Skip to content

Software Design

Alasdair Robertson edited this page Apr 16, 2018 · 15 revisions

Software Plan


GroProControllerGui

Processing

The OPT3001 continuously polls data into the RPi3 dependent on detected lux levels of ambient sunlight. This data is used to adjust the intensity of the LED array through a PID loop implementation, where the output intensity of the array will account for the decrease in light intensity experienced during sunset, and in turn, decrease during sunrise. Multithreading is also incorporated in the form of two threads, giving the RPi3 the ability to "listen" for user interaction using the Android app. The app allows the user to adjust the intensity levels of the LED matrix to the user's preference, as well as switch between warm and cold light temperatures to benefit different stages of plant growth. The use of object orientated programming was incorporated in order to encapsulate the functionality of the light sensor, LED driver, threading and Android application in order for ease of implementation in the final main programme. External dependencies required for this project include the wiringPi library, in order to access the GPIO pins of the Pi using high level commands, as well as the QT library for the necessary networking protocols.

The SPI protocol will be used to interface with the MAX7219 LED Driver LED driver IC. There are four SPI channels implemented along with one I2C channel for communication with the OPT3001 ambient light sensor. The raspberry pi uses the Linux Kernel which is used to compile and run the source code. No post-processing is required for the OPT3001 as the lux levels detected were accurate enough to implement the PID loop.

All source code is committed to this GitHub repository. The master branch contains the final release code, the development branch contains the "work in progress" code. There is also an exclusive branch used for the Android application development code. This has been merged with the development branch and is now released to the master branch.

PID Control

A PID control loop was implemented in order to adjust the LED arrays intensity dependent on ambient light levels detected by the OPT3001 sensor. The loop was tuned and optimised in two distinct steps. Firstly, the ambient light levels of peak afternoon daylight were measured and declared as the set point for the PID loop, with the lux levels measured by the OPT sensor defined as the process variable. The proportional, integral and derivative coefficients were then tuned largely using trial and error.

The proportional gain was set so that the system approached the desired lux level measurement slowly and in discrete steps. This was due to the nature of the project, with instantaneous reaction times not being considered crucial as they are dependent on the rise and fall of the sun. The integral term was increased after the proportional gain coefficient was set in order to arrive at a steady state error which prevented oscillations between LED array intensity states. The derivative term would be near negligible during standard operation, as the ambient light levels provided by the sun would not be changing at a fast rate. However, one was implemented for demonstration purposes in order to showcase the arrays switching on and off in correlation with the application of external light source (e.g torch).

The output of the PID programme was scaled to have a maximum output of 100 and minimum of 0. This was scaled to values between 16 and 0 and passed to the Max7219 Driver class for driver intensity implementation.

Max7219 LED Driver

Whilst the Max7219 drivers prime purpose is to drive 8 bit seven segment displays, they can also be used to drive 64 individual LED's. Each LED implemented in this project contained a red, green and blue LED. Since each of these coloured led's can be accessed individually, different colour combinations can be achieved with different combinations of the Max chips segment and digit outputs. Each colour combination was implemented in the Max chips driver class as methods in order for ease of implementation.

The Max7219 LED Driver class implemented in our source code appropriately initialises the drivers and uses the output from the PID control system to control the intensity levels. These intensity levels were shifted by one so as they ranged from -1 to 15, where values 0 to 15 were written to the intensity register of the Max driver and a value of -1 turned all the LED panels off completely using the shutdown function of the driver.

OPT3001 Ambient Light Sensor

As mentioned above, the OPT3001 Ambient Light Sensors operation was condensed into classes. The data was accessed using the I2C protocol, with the received information undergoing the appropriate data manipulation within the OPT sensors class.

Class UML Diagram


GroProControllerGui

Running the Program

To run the overall program follow the steps below:

  1. Connect Appropriate Hardware to RaspberryPi 3 model B
  2. Clone the GroPro Repo onto RaspberryPi
  3. Install wiringPi library
  4. Go to the GroProMain directory
  5. run make
  6. run ./GroProMain