Technology Review
Hardware Devices
After getting an idea of what our solution could be centred around, we started designing our control system. To do so, we researched technologies we could include:
To monitor current farm conditions, we need on-field devices to collect data and make responses. Avanade has provided most of the hardware needed, including a Raspberry Pi 4B [4] with 4GB of RAM and a Grove Smart Agriculture Kit for Raspberry Pi 4 [5].
In addition to the provided hardware, we still need to acquire actuators for the luminosity, humidity, watering and temperature subsystems, as well as components needed to power those actuators. We firstly designed a circuit we could use and listed the hardware components needed. We then highlighted components we don't have yet and ordered them online. This circuit design includes adding extra power supplies to, for example, the LED light actuators of the luminosity subsystem. The LED bubbles are connected in serial and straightly powered by the Raspberry Pi's GPIO pin.
After some reading of the best growing light [6], we discovered the best colour would be RB with red and blue brightness set in the ratio of 8:1. We found a suitable LED strip on amazon and ordered it. Compared to the original planning, this led strip provided better light colour with greater maximum luminosity.To power this device, we decided to use a MOSFET and a 12v external power supply. We have another MOSFET for powering other components, but due to the high current needed for the led strip, we decided to have separated MOSFETs.
For the actuator of the humidity subsystem, we had 2 available options for choosing according to the available pins on board. Firstly, we can use PWM controlled 4 pin computer fans which are from our original design in circuit design. Secondly, we can use the MOSFET to control 2 pin DC fan. Ultimately, we decided that, since we are using the same 12v external power supply for everything, we could use the MOSFET and DC fan solution for cheaper cost and simpler wiring.
For actuator of watering, compared to types of small size pumps on market, we chose the 5v diving pump, which is powered by Grove relay, as we programmed it an on and off time pattern instead of changing its voltage for different water flow rate.
Programming Language
For code implementation, we considered both Python and Java, which are both capable of programming towards IoT programming and object-oriented programming. We compared them in several integrals. Firstly, Python has a much shorter development cycle than Java as a weak typo check language. Secondly, Java is more efficient in backend calculations, but this doesn't give a huge advantage for our project specifically. Finally, there are more libraries for hardware that we can find capable for Python than Java, so we ultimately chose Python for both the front end and back end of our project. Since our client wants a simple, easy-to-use GUI, we used the Tkinter library to implement it.
Data Analysis Algorithm
For backend analyzers, we first came up with a simple set value-reaction style algorithm which turns to set position when reaching some typical points. Soon we found this way can hardly keep the system situation steady. We then came up with another algorithm, PID. PID (Proportional–Integral–Derivative) is a control loop mechanism that requires continuous updates of data. A PID controller continuously calculates an error value e(t) as the difference between the desired setpoint (SP) and a measured process variable (PV) and applies a correction based on proportional, integral, and derivative terms (denoted P, I, and D respectively), hence the name. [7] By using PID, we can make a much smoother curve to reach the target value, and it can make the value stable at the target point.
GUI
Our requirement includes creating a simple, easy to use GUI for users to view farm information. Since we have decided to use Python for back end code, we thought it was appropriate to use the same language for the GUI. The most common python libraries are PyQT and Tkinter. Despite both providing very similar functionalities for displaying interface, we ultimately chose Tkinter because it is open source and easier to use [8]. One downside of using Tkinter is that the appearance of the GUI produced may look outdated and dull. To still allow a more aesthetic GUI appearance, we decided to design our buttons and decorative images with digital art on Procreate to replace the original default components. In addition, for displaying graphs, we decided to use the matplotlib library as it provides many features such as graph animation and graph styling to help us display graphs onto a Tkinter canvas.
Databases and The Cloud
We initially implemented our first data collection code with a local database using the Python sqlite3 library. This is a disk-based database [9] that is simple to implement, which allows us to explore creating a table and make queries without the need to consider the connection with a cloud database. Once we are confident that our sqlite3 table works, we started researching Azure services and how we can incorporate those to set up an online database and access data via internet connection. Our client provided us with an account that accesses many Azure Services:
The SQL databases service allows us to set up a FarmBeats server and database that can be accessed by both the Raspberry Pi and front end app. Here is a screenshot of the database profile we set up.
Using the Microsoft ODBC driver[10]:
This is the first driver we explored. The ODBC data access API can be used with Python using the pyodbc library [11], allowing our code to connect with the Azure Database. This can be used to connect the GUI with the database, however, since the Raspberry Pi cannot have the ODBC driver installed, we need an alternative way of connecting it: IoT Hub.
The IoT Hub [12] is an Azure service that allows our edge devices to communicate in a secure, reliable way. In other words, the IoT Hub simply allows us to register the IoT device, keep track of it and also send messages back and forth as JSON files. Our solution requires this as the Raspberry Pi does not have the ODBC drivers to connect with the Azure database.
To send the data from IoT Hub to the Azure database, we need another Azure service: the Azure Stream Analytics [13]. This unpacks the JSON data and converts the content into an SQL Insert query.
A Summary of Your Technical Decisions
Technical Problem | Our Decision |
---|---|
Programming Language (front and back end) | Python 3 |
Data Analysis Algorithm | PID Feedback Mechanism |
External Power Supply for Actuators | 12V External Power Supply with 2 MOSFETs and 1 Grove Relay |
Brightness Actuator | External Power Supply for Actuators |
Water Actuator | 5v Driving Pump |
GUI | Python Tkinter and Matplotlib |
Database | Azure SQL |
Cloud Based Solution | IoT Hub, Azure Databse, Azure Server, Azure Stream Analytics |
References
[1] Growing Underground, “Growing Underground,” [online]. Available: https://growing-underground.com/about/.
[2] lightsciencetech, “lightsciencetech,” lightsciencetech, [online]. Available: https://lightsciencetech.com/solutions/vertical-farming/.
[3] Growing Underground, “ZCF-impact-report-2021.pdf,” 2021.
[4] raspberry pi, “raspberry pi 4b specifications,” [online]. Available: https://www.raspberrypi.com/products/raspberry-pi-4-model-b/specifications/.
[5] seeed studio, “Grove Smart Agriculture Kit for Raspberry Pi 4,” [online]. Available: https://www.seeedstudio.com/Grove-Kit-with-Raspberry-Pi-4-designed-for-Microsoft-FarmBeats-for-Students-p-4872.html.
[6] [online]. Available: https://migrolight.com/blogs/grow-light-news/best-grow-light-spectrum.
[7] wikipedia, “wikipedia.PID_controller,” [online]. Available: https://en.wikipedia.org/wiki/PID_controller.
[8] "pyodbc 4.0.32," Python Documentation, [Online]. Available: https://pypi.org/project/pyodbc/. [Accessed April 2022].
[9] "Azure IoT Hub," Azure, [Online]. Available: https://azure.microsoft.com/en-gb/services/iot-hub/. [Accessed April 2022].
[10] "Azure Stream Analytics," Azure, [Online]. Available: https://azure.microsoft.com/en-gb/services/stream-analytics/. [Accessed April 2022].
[11] "Python GUI – PyQt VS TKinter," GeeksforGeeks, [Online]. Available: https://www.geeksforgeeks.org/python-gui-pyqt-vs-tkinter/. [Accessed April 2022].
[12] "sqlite3 — DB-API 2.0 interface for SQLite databases," Python Documentation, [Online]. Available: https://docs.python.org/3/library/sqlite3.html . [Accessed April 2022].
[13] "Microsoft ODBC Driver for SQL Server," Microsoft Documentation, [Online]. Available: https://docs.microsoft.com/en-us/sql/connect/odbc/microsoft-odbc-driver-for-sql-server?view=sql-server-ver15. [Accessed April 2022].