RPi Brewing – Web Control
Hello reader (yes, you, at the back) – apologies for no recent updates,but I’m back with the third in the series of adventures in getting some brewday control developed using the Raspberry Pi platform. Interestingly, this comes only days after the 2 millionth Raspberry Pi was shipped!
In the last article I described the simple circuits we’re going to use to control the relays and also to connect the temperature sensors to the Pi. The code remains to be detailed (as does building the permanent circuits). The code to read the temperature is easy and essentially just pulls the data from the /sys/bus/w1 device as previously. I’ve written this into a python class which allows something along the following:
s.getTemp() returns the temperature of the HLT thermometer – this can be used for working out the heater control.
I should note here that I’ve decided to use Django as a framework to build the code within, which should enable me to quickly wrap this all up into a web control front end (see below). Django comes shipped with support for a variety of databases – I’m using sqlite to store the various config parameters, as well to store output states and as having the option to perform logging if so required (though I’d expect this to perform poorly over large datasets). As a result, the “HLT” parameter passed to the class allows it to do it’s own lookup of the device id it needs to query, and similarly, calls to heater control classes and the like will allow the lookup of ports, PID parameters, etc. without hardcoding.
The PID code reuses the PID code from the RasPiBrew project – specifically using the type C PID controller code – I’ve no real idea how this is going to work until I try and tune it – I suspect it’ll need a bit of work.
However, I can at present set the various parameters, set points, and set the “enable” flag on the PID controller through a web interface (pictured). This interface allows also the user to visualize the recent temperature of the HLT (at present – will work to expand this to all temperature sensors).
The graphing here uses rrdtool to record and display the graph back to the user – I tried using matplotlib, but the performance just wasn’t good enough here – rrdtool performs much better and has a python module for import. In the back end, to do the rrd logging, as well as controlling the output of 7-segment displays (as a visual output of the temperatures), I run a simple python script to call the temperature read script, and this is managed by supervisord.
Note there’s placeholders for status indicators for the heaters, pumps, etc. I’ll probably use this for override switches, and display the duty cycle as well. There’s more I need to do here – linking up a script to interface temperature readout, PID in/out and port control is next.
And of course, I need to start to build the hardware side of the system into a more permanent setup – currently, I have a prototype of the 7-segment display circuit being driven by the RPi – this uses an SAA1064 driver chip over i2c, but there is a web of wiring that I need to translate over to a veroboard. A fun few evenings with a soldering iron await, as well as needing to mount up the temperature sensor in the HLT and kettle for starters.