Google

HPR2353: RoboThermometer

Written on:August 13, 2017
Comments
Add One

I’m still recording stuff: here’s proof!
Yes, I know, it’s been far too long. Never mind my excuses, but I’m trying to ramp up and do this more often. It’ll probably help if I stop trying to make every episode a “full and complete” work on its particular topic, because that seems to always end up taking me far too long to research, write up, research some more, discover something has changed since I last researched, write up again, etc. That’s why this episode is only about 12 minutes long instead of being an hour-long documentary on the concept of “temperature” and the inner workings of the DS18B20 integrated circuit and probably at least one allegedly-humorous comment about “caloric fluid”. If you just want to know how to plug a temperature sensor into a RaspberryPi board and use it to log temperatures, this episode should give you what you need, though.

I’m amenable to being repeatedly harassed online until I get something recorded, so if you want to hear me talk about anything, please post in the comments, either here or at the official Hacker Public Radio page.

As usual, you can find the original posting of this episode in traditional deprecated ogg-vorbis format, obsolete .spx format, and really obsolete legacy .mp3 at the official Hacker Public Radio posting for it.

However, of course, if you’re really cool, you came here for the modern, awesome .opus version of the episode, complete with fully-populated metadata including embedded show notes.

This time around I encoded it at a mere 28kbps. The intro/outro music sounds a bit tinny but not too bad, but the voice still sounds great, and the file is actually even smaller than the official .spx encoding – you should even be able to actually listen to this file in “real time” over nearly any dial-up modem or GPRS link, if you are in a position where that’s your only connection to the internet.

As always, if you want to listen to this audio in a more full-featured media player, you can right-click-and-download the file directly right here. Of course, you can also just listen to it right here on this webpage:

The Show Notes:
Sorry this is such a short episode. I don’t know what came over me, I was just listening to Mr.X talking about doing something with Python in Hacker Public Radio episode 2340, and for some reason I just felt a compulsion to record _some_ kind of episode myself. It was so strange. I’m way behind on my Hacker Public Radio contribution duties anyway, so here’s a quick, geeky tutorial about a thing I did with a Raspberry Pi just to try it.

The temperature sensor I’m using is one of the many “1-wire” protocol devices supported by established kernel drivers, hence the reference to loading the modules for it:

sudo modprobe w1-gpio
sudo modprobe w1-therm

The part about adding “dtoverlay=w1-gpio” to /boot/config.txt and then rebooting is also necessary, otherwise the modules load but no devices show up in /sys/bus/w1/devices/ .

Part of the fun was coming up with a way of extracting the temperature reading in useful form without having to write a bunch of unnecessary python code. Not that there’s anything wrong with python, but I get the impression that some people think everything “RaspberryPi” has to be written in python. An example of this that amused me is the piFM project, which cleverl abuses the first-generation Raspberry Pi spread-spectrum circuitry to turn it into a surprisingly powerful FM radio transmitter. This project had two ways to run it – the actual compiled C program that takes input audio and makes FM radio come out…and a python “module” that was literally just a system call that…ran the C program that takes the audio and makes FM radio come out.

Examples of reading the temperature data that I ran into tended to also be short python scripts, so I took it as a challenge to do without, resulting in the fun-to-recite command in the episode, which on my system is:

echo "scale=3; (`grep -o "[[:digit:]]\{5\}" /sys/bus/w1/devices/28-05167380f6ff/w1_slave`/(5000/9))+32" | bc

As an example of what you get with a correctly connected and configured DS18B20 module on a Raspberry Pi, in my case the device shows up as:

/sys/bus/w1/devices/28-05167380f6ff/

Your device’s number after the “28-” will be different, so just replace my example with your own device’s number.

If you read the “w1_slave” virtual-file in that directory, you get something that looks similar to this:

67 01 4b 46 7f ff 0c 10 c4 : crc=c4 YES
67 01 4b 46 7f ff 0c 10 c4 t=22437

To be _completely_ proper, one probably _should_ validate that output to make sure the CRC matches so you know for sure that the read of the temperature data was correct, but I’ve had Zabbix checking my living-room temperature once every minute for a couple of days now and seen no odd readings or failures, so I’m not going to bother making anything more complicated than my hypnotic one-liner. I probably will, though, if I ever try to use the same kind of setup to monitor something more important, like a tank of expensive fish or a bioreactor full of beer.

If you want some more detailed connection instructions for the DS18B20 temperature sensor and the Raspberry Pi, here is one of the many online pages with the whole process:

https://learn.adafruit.com/adafruits-raspberry-pi-lesson-11-ds18b20-temperature-sensing/hardware

Leave a Comment

Bad Behavior has blocked 41 access attempts in the last 7 days.