Wednesday, 2 January 2013

RaspberryPi Remote Temperature Sensing

Well I finally got around to setting up an I2C device properly on the RaspberryPi, in this case a PCF8591 4-input analogue-to-digital converter (A/D for short).  The PCF8591 is easy to communicate with and has 8-bit resolution so it is okay for basic applications.

Above you can see it on a breadboard hooked up to the RaspberryPi.  The device is reading an LM35DZ temperature sensor, which outputs a very accurate voltage at 10mV per degree Celsius (or Kelvin for the purists!), so at a room temperature of 20 degrees C, you get 200mV or 0.2 volts.  The only issue at the minute is that the PCF8591 is using the RPi's 3.3v as its reference so a full '255' reading equates to 3.3v and my minuscule 0.2v gets about 16.  The solution will be to hook up an accurate 1 volt reference to the PCF8591 and I will sort that out next.

Now the fun part!  The Python script reads the PCF8591 and if the voltage on input '0' has changed it prints it out, but also writes this out to a file called 'liveData' which just happens to be in the Apache 'www' server directory.  There is also a neat AJAX JavaScript file called 'reloader.js' lurking in there and an HTML page to wrap it.  The re-loader goes back to the server every 5 seconds and updates the value in 'liveData' which is a representation of the temperature.

Voila, a remote temperature sensing device that only needs to be in range of the wi-fi access point to serve live temperature data out over the Internet.

The only problem I'm having is setting up the D-Link router to give external access to the RaspberryPi server.  I can test everything okay using the internal IP address of the RPi, which I have made static, but until I figure this one out, I can't read the data from Ulan Batur, Tomsk or Easter Island.

I have also managed to get the No-Ip client working in Linux and have a domain name set up so it would be nice to be able to go to my domain, click on a 'Home Temperature' link and see live data.  I'll get there eventually.

1 comment:

  1. UPDATE - This works fine online. I needed to test it using a 3G 'phone because my router doesn't allow Internet loopback so you can't test the server as if you were out in the big bad world if you are on my local network. Anyway the NO-IP client works fine and sets up my URL to follow the dynamic IP address automatically and the temperature is displayed and updated online. Sweet!