Wednesday, 30 January 2013

Upgraded Raspberry Pi Temperature Server

I've been having a lot of fun messing around with the Raspberry Pi as a server and decided to upgrade the temperature monitor with some more advanced I2C shenanigans.

I got 10 LM75 I2C temperature sensors on eBay for less than £3 including the delivery, which was a real bargain.  The only drawback was that they are SOIC-8 (i.e. tiny) 8-pin packages, but a small piece of tri-pad copper board and some fine soldering and I was able to come up with the adaptor in the photo below for prototyping purposes.


The red LED is just to confirm that 3.3v power is getting to the LM75 on the little breadboard and the white and grey wires are the SCL (clock) and SDA (data) lines for the I2C bus coming from the Raspberry Pi.

(if the server is running, you'll find it above!)

Reading temperature data from the LM75 is very simple, but I have hit a minor snag.  The LM75 uses a 2 byte data format although the device is essentially 8-bit.  Only 1 bit in the second byte is relevant, but it is the least-significant bit which represents 0.5 degrees C (or 0.5 Kelvin if you like).  The Python library I'm using insists on writing a byte to an I2C device if you want to read 2 bytes (or a 'word'), but this doesn't seem to work right so I am just reading 1 byte and losing the half-degree resolution until I can figure this out.  That said the data is accurate, if only to 1 degree resolution.


So on the programming and server end, I went for a graph this time as well as a table.  In behind this, the Python program is reading the LM75 and formatting the time and temperatures into a JSON file.  This is then decoded by a Java Script program at the client end and displayed as a little bar chart.

The next step I want to take is to log temperature data over a number of hours and display it as a graph on demand as well as having live data displayed in a table.  I want to use this to test the possibility of having 'almost live' telemetry data output over wi-fi from a car engine system.  As previously blogged, I want to try and get running data out to a low-cost Android tablet that only has wi-fi and a browser.  My thinking is that although there will be a limit on the number of browser requests possible (I'm aiming for 1 per second), the data logger/server would be collecting data much faster, collating it and then sending it as a JSON file.  In this case the Raspberry Pi would be running in access point mode as tested here over a short range (engine bay to the tablet computer on the dashboard).

It may be better to create the graphs at the server end in PHP and then  send them as a JPEG or GIF image, but part of the fun will be seeing which works best.  They key thing is in cracking the AJAX concepts to get regular timed updates on the browser without needing to refresh the whole page.  That has been a real revelation to me (yeah, I'm not an early adopter!) and

Monday, 21 January 2013

Retro Sci-Fi Fonts


I started looking at the classic fonts used in 1960s and 1970s science fiction and identified Eurostile and Futura as the fonts I remember best from films like '2001,' 'Silent Running' and TV series like 'U.F.O.'

I got to thinking how cool it would be to have indicators using these fonts and how to go about making them.  A bit of experimenting and I found that printing the image above onto a transparency made a good indicator which would allow light to shine through the lettering.  The only problem was that the printer couldn't get a deep enough black.  So I figured, print 5 copies of the image, line them up carefully and glue them together to make a transparency 5 times thicker and the black background is really well, black, but light can still shine through the lettering.  A piece of thin white paper behind it all acts as a diffuser and then all that's needed is a good bright LED to finish it off.

I've been playing with this and I'll get a photo of a working version up soon.

Monday, 14 January 2013

RaspberryPi Micro Server


RaspberryPi micro temperature server, sitting on the mantelpiece serving temperature data out via wireless onto the World Wide Web thingy.  Not always on, but if it is, it can be found at

Temperature Sensor

I'm working on making the readings more accurate using a better Python script.  The thermistor is (very) non-linear so I'm trying to generate a look-up table to do this quickly.

Saturday, 12 January 2013

Blocked

Well we are now trying recycled wooden blocks as a fuel source as we move ever-closer to smug carbon-neutrality.  They burn hot and each one will burn for about an hour, but best of all they are much cleaner to handle than the coal, light quicker and produce much less ash.  They are also easy to store because they are tightly compressed and water has difficulty getting into them so in theory they could be stored outside although I bagged mine in old coal sacks and put a tarpaulin over the whole lot to keep them dry.

Cost?  £40 for a big builders bag, must be at least 300kg in there, which is very reasonable.  This compares with about £80 for the same weight in coal.  The only drawback is you need to go and collect the blocks with a trailer.  Of course Ali sweet-talked the supplier into delivering the first order as a favour, but I had to bag it up myself to get it stored.

So there is of course a play-off with this arrangement.  That is to say, work and effort, but that keeps me fit and saves me a pointless gym membership.  Someone I know said they couldn't live without the convenience of throwing a switch and getting heat, but I figure they're in for a rude awakening sooner or later the way the world is turning.  That said, while we still have electricity on tap, I'm happy enough to use it so I bought myself one of these magic little electric saws from Black and Decker.  Only cost me £45 and makes light work of cutting up scrap timber, pallets and old flooring for fuel.  In the summer I still like to do a bit of cutting and chopping by hand for the satisfaction of it.



I think we will still use coal at night when it gets cold and the pump is running for the radiators.  We only have 10 radiators running, but 5 are big doubles and the boiler struggles sometimes to keep them warm.  In a slightly smaller house, say with 8 radiators, this system would be incredible.

The next stage in getting off-grid (-ish) is to look at an alternative system for running the pump, maybe using a solar panel, battery and inverter to drive it or something like that or maybe a parallel 12-volt pump.  A pump that could somehow be driven off the heat of the stove itself would be something special.  I remember years ago seeing a programme on TV where Russian farmers in Siberia were running their Rigonda TV on a 12 volt thermocouple array run off the back of a big range in the kitchen of the dacha.  Looked amazing.  I love Soviet-era technology, am a Socialist, but never really cared for Stalin.

All morning oil tankers have been going up and down our street making deliveries and I'm just looking at my nice warm cheap Chinese Communist stove and smiling away.  Told you I was a socialist.

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.