-
Notifications
You must be signed in to change notification settings - Fork 0
Software
The idea of the software was to keep it as modular as possible for future extensions and keep it as basic as possible, since it is an ongoing Python learning project.
For this reason I decided to spawn distinct processes:
- The Controller (controller.py); only dedicated to measure Temperature & Humidity, adjusting the heater with a software PID controller to the set points and adjusting the status LEDs and buzzer.
- The Brood Lord (brood_lord.py); reads the incubation program and schedules the set point changes; it also schedules the egg turning
- The Output (output.py); collects all the data from the controller via a process queue and writes it into a csv file.
I also wanted to be able to resume the incubation program, in case the incubator has to be switched off in between or some problems arise. Therefore the `--init` flag writes the start time into time_init.json. When the flag is not used, the program resumes from that time point.
All the variables needed for hatchling are stored in json files. So there is no need to tweak the python code right away. `settings.json` contains all the hardware related info. The GPIO pins (BCM format), the names of the the data folder and output csv file, the LED/buzzer status modes, PID parameters and number of steps the motor should turn. The LED status section defines when the LEDs should switch from green to blue to red to red + buzzer. They work on either too high or too low values. E.g.: green=0.25; LED=green, if temperature between +- 0.25°C around set point.
This was probably the most tricky part. It took me quite long the implement the PID controller, because I didn't just want to buy a hardware solution. I tried a few different packages, but then found simple-pid. It works nicely and comes with great options. Check out their page!
This is the actual difficult and bit annoying part. I had no idea how a PID actually works and what values I need for my box, but then stumbled over Emile's Home Brewing Project. He has great documentation and the idea is not too far away from what I was building. So have a look at that page!
To start off, you should start warming up the incubator without any PID control and just let it settle (no more heating up due to cooling from outside). This can take a while depending on your system. Since my heater is actually too powerful, I let it run at 25% power. It then settles at around 40°C. You find a little python script under docs/ to help you with calculating the PID values from your data. These values worked pretty well for me, but these are for sure very system related. Still, there is room of improvement. E.g: the temperature fluctuates around the set point by +-0.2°C. I think that's pretty good, but bothers me that it is not perfect...However this might also be coupled to the relatively slow sensor reading (1Hz). The PID controller would work much better with a higher sampling rate. Using faster temperature sensors could do the trick in the future.
The LEDs and buzzer are controlled via a 74HC595 shift register. The update of the shift register uses a decimal system, which encodes the different modes. Find the encoding table under the docs/ and here.