Skip to content

maglub/rpi-sous-vide

Repository files navigation

Disclaimer

I make mistakes, very often. Build this on your own risk.

Introduction

  • 2018-05-04, Migration from Slim 2 to Slim 3 framework done
  • 2017-10-25, Added installation scripts for influxdb and grafana

NOTE NOTE NOTE: If you do a "git pull" 2018-05-04 or later, on a system that has been installed before, you will have to run "./setup.sh" again, to resolve the new dependencies of the migration from the Slim2 to Slim3 php framework.

#--- upgrade from Slim2 to Slim3
cd ~/rpi-sous-vide
rm -rf vendor
./setup.sh

rpi-sous-vide is a Raspberry pi based PID controller for a home built sous vide machinery, a home built smoker (to smoke meat, fish, etc), a greenhouse, or anything else that you need to control depending on the current temperature, and a setpoint temperature that you wish to reach. The basic principle is the same. I even use it to control the solar heating for my pool. You measure the media (water or air), and decide to turn on or off a heating element or a pump. Currently it supports two output relays, to control a heating element and a motor to stir water.

The basic idea is to:

  • Control the temperature in a setting
  • Web based application
  • Metric/Temperature collection and graphing

The application, as seen on a mobile device:

Dasboard in grafana:

This was a "one day project" that turned into a weekend project, that turned into... It is not really in a state to be used by anyone else than me at the moment, but the basic idea is to have a web-gui based on:

lighttpd -> php -> php slim

The web gui is useful for monitoring and setting constants and setpoints.

One of my design criterias is to separate the problem domain on the low level to three "daemons":

  • input (temperature) => Gets input from your hardware (i.e ds18s20 or MAX6675), writes to tmp/temperature
  • control (temperature control, i.e PID or other algorithm) => reads from tmp/temperature and tmp/setpoint, writes to tmp/heaterDuty
  • output heater control (setting the heater to a range of 0% to 100%) reads from tmp/heaterDuty, controls the relay(s)

Conceptual view:

This is an overview of the API (input/output/interactions) between the systems components.

      +------------------------------+   +----------+   +----------------------+
      |          web gui             |   | rest api |   | LCD/Display, buttons |
      +------------------------------+   +----------+   +----------------------+
                                  |            |            |
                              +--------------------------------+
                              |              app api           | 
                              |          (bin/functions)       | 
                              +--------+-----------------------+
	                               |           ^
           +---------+                 |           |
           |  logger |-> i.e influx    |           | 
           +---------+                 |           |
                ^                      |           |
                |                      |           |
                +----+-----------------)----+------+--+
                     |                 |    |         |
                     |                 V    |         |
                     |              tmp/setpoint      |
  18B20              |                 |              |
    |                |                 V              |
+-------+            |          +---------+           |          +--------+
| input | -> tmp/temperature -> | control | -> tmp/heaterDuty -> | output |
+-------+                       +---------+                      +--------+
                                                                      |
                                                                      V
                                                                   Relay ---> Boiler/Heater/Pump

Separating the components in that way, I can play around with different ways of implementing the different components. I.e:

  • The input could potentially be changed to use PT1000 sensors or k-type sensors through an AD converter/SPI and a different piece of code. The only thing you need to do, is to write a looping script that reads the temperature(s) from your device, and writes it to the tmp/temperature file.
  • The control can be the default PID code, or be could be any algorithm of choice
  • The output could use the default "slow" PWM or other means of control that can accept a range from 0 - 100 as input.

Compatibility

This matrix show which versions of raspbian that works. Please try and use the "newest" possible, as I am not testing backwards compatibility properly.

Raspbian Distribution lite GUI PHP
Stretch 7.0
Jessie 5.6
Older
Reaally old

Installation

  • Install raspbian on an SD card
  • Log into your raspberry pi
  • Install git
  • Clone this repo to ~pi
  • Run the setup.sh script (will download and set up php dependencies)
  • Run the setup-influddb.sh script (will download and set up influxdb)
  • Run the setup-grafana.sh script (will download and set up php dependencies)
  • Reboot (since setup.sh will add items to /boot/config.txt and /etc/modules.conf)
  • Go to http://YOUR_PI_IP for the web gui
  • Go to http://YOUR_PI_IP:3000 for grafana (if installed)

On the raspberry pi:

sudo apt-get update
sudo apt-get -y install git

git clone https://github.com/maglub/rpi-sous-vide.git

cd rpi-sous-vide

#--- if you need en_US.UTF-8
# piLoggerLocale=true ./setup.sh

./setup.sh
./setup-influxdb.sh
./setup-grafana.sh

sudo shutdown -r now

After the reboot, the 1wire interface is enabled and you should be able to see your devices. You should give your sensors names in the conf/aliases.conf file now.

#--- if you set up a greenhouse, change the application_type to "greenhouse" in conf/app.conf
cd rpi-sous-vide
./bin/genAliases | tee conf/aliases.conf

Start the input, control, and output processes in the web GUI. You can also do it on the command line:

bin/wrapper startProcesses

Set a target temperature:

bin/wrapper setSetpoint 65

Install influxdb and grafana

Note, the installation of influxdb and grafana will take a while. I only show the installation for Raspberry Pi 3 (or newer), since it does not make sense to install it on the older ones.

  • Influxdb
./setup-influxdb.sh
  • Grafana
./setup-grafana.sh

Upgrade

  • On the command line
git pull
./setup.sh
  • You can also do a git pull from the GUI, which does not automatically run the ./setup.sh script

Different input/control/output/logging possibilities

The way the system figures out which input/control/output script to use, is set by symbolic links in ./bin, where the default symlinks are set as follows:

bin/control -> control-available/pid.enhanced
bin/input -> input-available/input-18b20
bin/output -> output-available/heaterOutput
bin/logging-enabled/none -> logging-available/none

For control, input, and output you can only link to one script. For logging, any symlink in bin/logging-enabled will be executed, hence you can log to multiple destinations if you like.

You can copy these scripts and adapt them in any way you like. In particular the input script might need different setup on your Raspberry Pi, and the setup script will try and satisfy this by calling the input script with the "--setup" parameter.

bin/input --setup

So if you have some esoteric hardware that need special configuration (like the 1wire sensors), you can put that in your input file in the doSetup() function.

Influxdb logging

If you have an influxdb server available, you can redirect the logging to it and create a new database for it. Update the influxdb variables in conf/app.conf, and symlink the logging script. In the influxdb script, there is an exampla curl call to create the database. There are three values logged at the moment:

  • control: smoker-output-pwm
  • input: smoker-setpoint
  • input: smoker-temp
cd bin
ln -sf logging-available/influxdb logging

ls -l logging
lrwxrwxrwx 1 pi pi 26 Jul  8 19:35 logging -> logging-available/influxdb

Influxdb examples:

  • Create database "smoker" on server 192.168.4.55
curl -G http://192.168.4.55:8086/query --data-urlencode "q=CREATE DATABASE smoker"
  • Query all values from table "sensor_data" in the database "smoker" server 192.168.4.55
curl -G 'http://192.168.4.55:8086/query?pretty=true' --data-urlencode "db=smoker" --data-urlencode "q=SELECT * FROM sensor_data"

Usage

Most things are hidden in the "functions" file. There is a wrapper that can be used to list the functions, and control them from outside the scripts.

bin/wrapper --list
  • Set the target (setpoint) temperature:
bin/wrapper setSetpoint 65
  • Turn all off (using an alias)
svBin=/home/pi/rpi-sous-vide/bin
alias off='$svBin/wrapper setHeaterDuty 0 ; $svBin/wrapper setSetpoint 0 ; $svBin/wrapper setHeater off; $svBin/wrapper setPump off'

off

BOM (bill of materials)

Type Item Pcs Cost Where Link
SOC Raspberry Pi 3 1 34.29 chf http://ch.farnell.com/raspberry-pi/raspberrypi3-modb-1gb/sbc-raspberry-pi-3-model-b-1gb/dp/2525225
SOC Raspberry Pi 3 case 1 7.00 chf https://ch.farnell.com/raspberry-pi/raspberry-pi3-case/geh-use-raspberry-pi-3-model-b/dp/2519567
SOC (alternative) Raspberry Pi Zero W (1) 32.94 EUR https://buyzero.de/collections/boards-kits/products/copy-of-raspberry-pi-zero-w?variant=31485043154
SD card SD Card, 16GB (more than enough) 1 16.00 chf Digitec.ch
PSU USB charger, 2.5A 1 7.99 Eur https://buyzero.de/collections/raspberry-pi-zubehor/products/netzteil-2-5-a
Relay SSR-25DA 1 $2.70 https://www.aliexpress.com/item/1-pcs-SSR-25DA-25A-3-32V-DC-TO-24-380V-AC-SSR-25DA-relay-solid/32712665772.html
Rail clip SSR-25DA 2 $2.32 https://www.aliexpress.com/item/single-phase-SSR-35MM-DIN-rail-fixed-solid-state-relay-clip-clamp-with-2-mounting-screws/32679765326.html
Thermometer 18B20, with 3m cable 1 $1.50 Ali Express
Resistor 4.7k 2 0.10 chf
Transistor MPSA05 or MPSA06 NPN 1 0.10 chf
Box IP55, F-Tronic, including DIN rail 1 35.00 chf Bauhaus
Connector Dupont crimp connectors, 1 pin, 4 pin 6 0.10 chf
Connector WAGO compact splicing connector 1 0.5 chf https://www.aliexpress.com/item/221-413-Original-WAGO-connector-led-splice-connector-COMPACT-Splicing-Connectors-3-conductor-connector-100-Original/32681506587.html
Cable 20AWG silicon wire 1m 0.50 chf https://www.aliexpress.com/item/UL-3135-20AWG-high-temperature-Silicone-wire-3135-20-silica-gel-wires-Conductor-construction-100-0/32260276471.html

Ca cost for a Raspberry Pi 3 based system:

  • Subtotal CHF: 95.00 chf
  • Subtotal EUR: 7.99 EUR => ca 9.00 chf
  • Subtotal USD: $6.52 => 6.50 chf

Total (ca) in CHF: ca 110.00 chf

Wiring it up

  • Note: I could not find an SSR-25 DA in the Fritzing library.

  • Wiring up the solid state control

  • Wiring up the ds18b20 (if you have only one thermometer)

  • The breakout board (if you have more than one thermometer)

  • The breakout board cable

  • The thermometers connected to the breakout board

Runtime

Start the three programs:

Program Description Input Output
bin/input Symlinked to the input of choice in input-available. Thermometer. 18B20 /var/lib/rpi-sous-vide/tmp/temperature
bin/control Symlinked to the control program of choice in control-available. /var/lib/rpi-sous-vide/tmp/{temperature, setpoint} /var/lib/rpi-sous-vide/tmp/heaterDuty
bin/output Symlinked to the output program of choice in output-available. /var/lib/rpi-sous-vide/tmp/heaterDuty Solid state relay over GPIO

Notes

DS18s20

  • One sample take ca 0.9 seconds on a Raspberry Pi Zero, and 0.8 seconds on a Raspberry Pi 3B, so don't expect this to work in very fast changing environments.

Releases

Every now and then I will create a new release tag. Mostly "master" is considered to be stable, so just "follow master" to be up to date.

If you rather follow tagged releases, please check the "Releases" page. https://github.com/maglub/rpi-sous-vide/releases

Feedback/bugs/feature requests/Contributions

Please provide any bug reports, feature requests, vulnerabilities, or other feedback in the Issue tracker here in this project. I happily receive contributions!

If you would like to contribute code, the process is simple.

  • Please create an issue with a feature request
  • If you have code you would like to contribute, please fork this project and devlop your enhancement.
  • When you are ready, please create a pull request

Coding standards

Currently I am very relaxed when it comes to coding standards, but there are a couple of things to keep in mind:

  • Please use spaces, not tabs, for indentation
  • The feature should not break the existing platform
  • The feature should not change the architecture too much

References

Misc

Now you will be able to browse your new dashboard on:

License

  • MIT - do whatever you want with this.