{"id":185,"date":"2017-08-13T13:37:00","date_gmt":"2017-08-13T17:37:00","guid":{"rendered":"http:\/\/hpr.dogphilosophy.net\/?p=185"},"modified":"2017-08-13T13:37:00","modified_gmt":"2017-08-13T17:37:00","slug":"hpr2353-robothermometer","status":"publish","type":"post","link":"https:\/\/hpr.dogphilosophy.net\/?p=185","title":{"rendered":"HPR2353: RoboThermometer"},"content":{"rendered":"<p><b>I&#8217;m still recording stuff: here&#8217;s proof!<\/b><br \/>\nYes, I know, it&#8217;s been far too long. Never mind my excuses, but I&#8217;m trying to ramp up and do this more often. It&#8217;ll probably help if I stop trying to make every episode a &#8220;full and complete&#8221; 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&#8217;s why this episode is only about 12 minutes long instead of being an hour-long documentary on the concept of &#8220;temperature&#8221; and the inner workings of the DS18B20 integrated circuit and probably at least one allegedly-humorous comment about &#8220;caloric fluid&#8221;. 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.<\/p>\n<p>I&#8217;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.<\/p>\n<p>As usual, you can find the original posting of this episode in traditional deprecated ogg-vorbis format, obsolete .spx format, and <em>really<\/em> obsolete legacy .mp3 <a href=\"http:\/\/hackerpublicradio.org\/eps.php?id=2353\" title=\"Hacker Public Radio Episode 2353\" target=\"_New\">at the official Hacker Public Radio posting<\/a> for it.<\/p>\n<p>However, of course, if you&#8217;re <em>really<\/em> cool, you came here for the modern, awesome <a href=\"http:\/\/opus-codec.org\" target=\"_New\">.opus<\/a> version of the episode, complete with fully-populated metadata including embedded show notes.<\/p>\n<p>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 &#8211; you should even be able to actually listen to this file in &#8220;real time&#8221; over nearly any dial-up modem or GPRS link, if you are in a position where that&#8217;s your only connection to the internet.<\/p>\n<p>As always, if you want to listen to this audio in a more full-featured media player, you can <a href=\"https:\/\/hpr.dogphilosophy.net\/audio\/hpr2353RoboThermometer.opus\" title=\"Hacker Public Radio episode 2353: RoboThermometer\" target=\"_New\">right-click-and-download the file directly right here<\/a>.  Of course, you can also just listen to it right here on this webpage:<\/p>\n<p><audio controls><source src=\"http:\/\/hpr.dogphilosophy.net\/audio\/hpr2353RoboThermometer.opus\">(If your browser was modern and supported .opus audio, you&#8217;d see audio player controls here to listen right in the webpage. Try Firefox or Chrome.)<\/audio><\/p>\n<p><b>The Show Notes:<\/b><br \/>\nSorry this is such a short episode. I don&#8217;t know what came over me, I was just listening to Mr.X talking about doing something with Python in <a href=\"http:\/\/hackerpublicradio.org\/eps.php?id=2340\">Hacker Public Radio episode 2340<\/a>, and for some reason I just felt a compulsion to record _some_ kind of episode myself. It was so strange. I&#8217;m way behind on my Hacker Public Radio contribution duties anyway, so here&#8217;s a quick, geeky tutorial about a thing I did with a Raspberry Pi just to try it.<\/p>\n<p>The temperature sensor I&#8217;m using is one of the many &#8220;1-wire&#8221; protocol devices supported by established kernel drivers, hence the reference to loading the modules for it:<\/p>\n<p><code>  sudo modprobe w1-gpio<br \/>\n  sudo modprobe w1-therm<\/code><\/p>\n<p>The part about adding &#8220;<code>dtoverlay=w1-gpio<\/code>&#8221; to <code>\/boot\/config.txt<\/code> and then rebooting is also necessary, otherwise the modules load but no devices show up in <code>\/sys\/bus\/w1\/devices\/<\/code> .<\/p>\n<p>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&#8217;s anything wrong with python, but I get the impression that some people think everything &#8220;RaspberryPi&#8221; 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 &#8211; the actual compiled C program that takes input audio and makes FM radio come out&#8230;and a python &#8220;module&#8221; that was literally just a system call that&#8230;ran the C program that takes the audio and makes FM radio come out. <\/p>\n<p>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:<\/p>\n<p>  <code>echo \"scale=3; (`grep -o \"[[:digit:]]\\{5\\}\" \/sys\/bus\/w1\/devices\/28-05167380f6ff\/w1_slave`\/(5000\/9))+32\" | bc<\/code><\/p>\n<p>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:<\/p>\n<p>  <code>\/sys\/bus\/w1\/devices\/28-05167380f6ff\/<\/code><\/p>\n<p>Your device&#8217;s number after the &#8220;28-&#8221; will be different, so just replace my example with your own device&#8217;s number.<\/p>\n<p>If you read the &#8220;w1_slave&#8221; virtual-file in that directory, you get something that looks similar to this:<\/p>\n<p><code>  67 01 4b 46 7f ff 0c 10 c4 : crc=c4 YES<br \/>\n  67 01 4b 46 7f ff 0c 10 c4 t=22437<\/code><\/p>\n<p>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&#8217;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&#8217;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.<\/p>\n<p>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:<\/p>\n<p><a href=\"https:\/\/learn.adafruit.com\/adafruits-raspberry-pi-lesson-11-ds18b20-temperature-sensing\/hardware\">https:\/\/learn.adafruit.com\/adafruits-raspberry-pi-lesson-11-ds18b20-temperature-sensing\/hardware<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m still recording stuff: here&#8217;s proof! Yes, I know, it&#8217;s been far too long. Never mind my excuses, but I&#8217;m trying to ramp up and do this more often. It&#8217;ll probably help if I stop trying to make every episode a &#8220;full and complete&#8221; 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&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-185","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/hpr.dogphilosophy.net\/index.php?rest_route=\/wp\/v2\/posts\/185","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hpr.dogphilosophy.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hpr.dogphilosophy.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hpr.dogphilosophy.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hpr.dogphilosophy.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=185"}],"version-history":[{"count":5,"href":"https:\/\/hpr.dogphilosophy.net\/index.php?rest_route=\/wp\/v2\/posts\/185\/revisions"}],"predecessor-version":[{"id":190,"href":"https:\/\/hpr.dogphilosophy.net\/index.php?rest_route=\/wp\/v2\/posts\/185\/revisions\/190"}],"wp:attachment":[{"href":"https:\/\/hpr.dogphilosophy.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=185"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hpr.dogphilosophy.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=185"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hpr.dogphilosophy.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=185"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}