Blog2015 ≫ How's my brewing?

How to monitor temperature of your home brew (or anything) with raspberry pi...

Beer graph is still going strong! Febrewery continues apace, I spoke to Easy Home Brew1 and they said not to worry about a heat belt or any other heat source for my home brew unless the temperature is dropping below fifteen degrees. And it's not, even when the heating is off overnight.

At some point my home brew beer graph would have appeared here. I haven't done home brew for ages, it doesn't quite seem worthwhile, but maybe in times of austerity it will return.

I haven't seen the airlock bubbling away like it used to with the cider, but I can see that brew has bubbled up so fermentation is going on...

More details here of how I did this, with a raspberry pi and some 1-wire temperature sensors2 attached to the gpio pins.

Will be putting this code in its own repo3. Will write this all up in one place so it's easy to follow. And probably renaming that repo too, not sure about raspberry-pint...

Here are the steps I'm going to put into that repo. The first ones come from this page at Cambridge Computer Lab4, but with my own twist on them, what I had to do to make them work for me.

In brief the steps are:

Now for more details on each step:

Now update your pi, in the terminal again:

sudo apt-get update 
sudo apt-get upgrade

Now we have the modules we need to read from the GPIO pins on the raspberry pi, but we still need to load them. Terminal again:

sudo modprobe w1-[gpio](/wiki/#gpio)
sudo modprobe w1-therm

Not sure if you have to do this on restarting your pi, will come back to this. If so you could add it to the file /etc/rc.local just before the last line saying "exit 0".

Turn your pi off first, disconnect the power.

I'm assuming you're using the same waterproof sensors that I am for your beer2, that are encased in a shiny metal probe. If you're doing something with just the raw components follow the instructions here instead4.

There are three wires coming off the temperature sensor, one is for power, one is for earth, and one is for the data signal. Search online for GPIO pin details if you want more details, but here are the basics. Turn the pi round so the GPIO pins are to the top right, then connect:

So how to actually physically connect these? Be super super careful, if you connect to the wrong pin you can surely fry your pi. Best thing for this is some female to male jumper cables I think, that will just clip on to the ends of the GPIO pins, but I've done this with a GPIO cable5 because it's what I had to hand, and then I can poke the male jumpers into the other end of that. The Cambridge tutorial I first read suggests buying something so you can connect the GPIO to a breadboard and then plug your components in to that. I have connected my jumpers with the probes using a terminal block (aka chocolate block) so no soldering. Lots of options here, whatever works for you.

If you've done this right then the probe is now connected, and available as a device in /sys/bus/w1/devices/, look in that folder and you will see:

$ ls -tlar /sys/bus/w1/devices/
total 0
drwxr-xr-x 4 root root 0 Feb  8 16:27 ..
drwxr-xr-x 2 root root 0 Feb  8 16:30 .
lrwxrwxrwx 1 root root 0 Feb  8 16:30 28-0004784c24ff -> ../../../devices/w1_bus_master1/28-0004784c24ff
lrwxrwxrwx 1 root root 0 Feb  8 16:42 w1_bus_master1 -> ../../../devices/w1_bus_master1

If you only see w1_bus_master1 in this folder then your probe is not connected properly, so double check everything. If you don't see that folder then you've not updated your pi successfully. Both of these things happened to me on earlier attempts.

Best thing about the 1-wire technology is you can connect loads of 1-wire probes to the same pin and they'll just show in the folder above. And the graph generating code will pick them all up (to a maximum of ten probes). Each probe will get its own line on the graph.

My code uses ruby which is on the pi already, but if you want to view it in your browser you can use apache:

sudo apt-get install -y apache2

Next install the code to generate the graph:

sudo apt-get install -y git-core
cd && git clone https://github.com/pauly/raspbrewery.git

if this worked you can run the code to generate a graph:

~/raspbrewery/temperature.rb > /var/www/index.html

if that worked you'll see your graph if you go to the ip address of your pi in your browser. If you have a screen and things connected to your pi and you're using the gui just go to http://localhost/ - best set up your pi on the wifi though and run it headlessly, you don't need a monitor and keyboard and things where your brewing is.

Not much of a graph yet is it? We need to query the temperature periodically to get enough data to plot, so set up a cron job to run the command every minute. I've put a script in the repo to help so you can just run

~/raspbrewery/cron.rb

Any questions? Give me a shout here or on the twitter - @pauly.

raspberry pi: Credit card sized super cheap computer, awesome.

💬 There's been an update

⬅️ :: ➡️

Paul Clarke's weblog - I live in A small town. Wed to Clare and dad to two, I am a full-stack web engineer, and I do js / Node, some ruby, other languages ect ect. I like pubs, running, eating, home-automation and other diy stuff, history, tree stuff, Television, squirrels, pirates, lego, + TIME TRAVEL.