====== 2011.06.03 - temperature measurement ====== today i've built my first digital thermometer connected to linux. it is based on the [[http://pdfserv.maxim-ic.com/en/ds/DS18S20.pdf|ds18b20]] IC -- digital thermometer connected via [[wp>1-Wire]] communication bus. it appears that it can be easily connected to [[wp>RS232]] using [[http://kml.jogger.pl/2009/10/29/termometr-cyfrowy-ds18b20-na-rs232-com-i-usb|ds9097]] adapter. it is supported by [[http://www.digitemp.com|digitemp]] out of the box. ===== hardware ===== since RS232 to 1-Wire would require voltage converter (for example [[http://www.datasheetcatalog.org/datasheet/texasinstruments/max232.pdf|max232]]) and then some uC to translate between protocols it is best to use well checked ds9097 adapter with above mentioned digitemp package. note that is you're [[http://www.debian.org|debian]] or [[http://www.ubuntu.com|ubuntu]] user you have this package already available in your distro's repos (//apt-get install digitemp//). here is the electrical view. notice that rs232 is regular 9-pin connector, mail-sided on the computer (i.e. schematic shows how it should look, if you'd solder straight to the PC's mail connector). {{:blog:2011:06:03:ds1820_sch.jpg|ds1820 connection via ds9097 adapter (original image taken from http://mod-planet.com/modules/subjects/pages/termometr/zdjecie01.jpg)}} notice that you can also connect multiple devices to this bus without need of changing anything. cables are said to work for up to 100 meters((i haven't checked it yet.)). ===== software ===== using the digitemp software is a bit tricky at first so i'll spear you searching and give ready-to-go solution. first thing is to determine serial port to use. typically this is /dev/ttyS0 is you're using raw RS232. in my case i used USB to RS232 adapter, thus my device was /dev/ttyUSB0. first thing to do is check if the software sees the device(s) connected: digitemp_DS9097 -s /dev/ttyUSB0 -q -w at this moment you should see your device(s) list. now comes the tricky part -- save this list along with other configurations to file: digitemp_DS9097 -s /dev/ttyUSB0 -q -i now file ~/.digitemprc has been generated for you. from now on you can query all of the sensors by simply typing: digitemp_DS9097 -a notice that you not need device names any more! as you can see the tool is made the-unix-way, so it allows easy integration with other scripts and data collection mechanisms. example on-screen monitoring can just run forever displaying measurements every 2 seconds: digitemp_DS9097 -a -q -n 0 -d 2 see the command's manual for more details. ===== final notes ===== looks cool for me. now i think about spreading few such a sensors through my home to monitor temperature in key points (server's "closet", room, outdoors, and so on...). integration with data visualization would be nice too. i already use [[http://ganglia.info|ganglia]] for load and PC's temperatures monitoring. why not extend it to house temperatures as well. recently [[http://www.wcss.pl|at my work]] i've wrote pluin for [[http://www.nagios.org|nagios]] - API's nice. can be an option as well, though ganglia is probably more straight forward solution.