Scripts to turn Tinkerforge bricklets into a general-purpose PID controlled heater.
Assumes we've got a running brickd instance and the following bricklets connected:
- Thermocouple 2.0 to connect to a thermocouple probe to read system temperature
- Solid State Relay 2.0 to control a heater or other or output in PWM
- LCD 128x64 to provide an interactive GUI
Also requires:
- Tinkerforge Python Bindings
- simple-pid (for
regulated.py
script)
Tested and working on a Raspberry Pi Zero with a HAT Zero Brick but theoretically would work fine with any other master brick.
There are currently two scripts available:
This provides a GUI which allows heater power to be set directly. The thermocouple temperature is visible and tracked over time via a graph.
If power is set to 0 or 100%, the relay is turned permanently off or on respectively. For any values in between, we use PWM with a fixed frequency (1Hz by default).
Provides a GUI which allows a desired target temperature to be set. A PID loop then dynamically updates heater power according to thermocouple temperature and tuning parameters.
The controls tab. Use the buttons to modify the set temperature (S)
Thermocouple temperature can again be visualised via a graph to verify stability.
The graph tab. Each horizontal pixel is one thermocouple reading. As such, the time scale is determined by the read period (default: 1 second per pixel)
PID parameters are set via the separate tuning.json
file which is read on initialisation.
If Heater.tuning_mode
is set to True
, this file is read on every PID iteration. This is
useful for live PID tuning.
After installing requirements and ensuring that brickd
is running, simply execute your desired
script:
./unregulated.py
or
./regulated.py
For long-term use, you can use your preferred method of autostarting this script on boot. On a Pi
Zero, I've had success using a systemd service
set to start as soon as brickd
is up.
The "Settings" tab in the GUI for both scripts provides a "Shut Down" button that executes a graceful shutdown of the host device. This may need to be updated as appropriate for your system.