Adding a DS18b20 1-wire digital thermometer to an LPC812 UKHASnet Node

DS18B20While my LPC812 UKHASnet nodes currently transmit the temperature from the RFM69HW radio module this isn’t particularly accurate as it is effected by how active the radio is.  As the LPC812 doesn’t have an ADC the easiest alternative is to use a DS18b20 1-Wire digital
thermometer from Maxim (Product Page).
These modules cost ~£2 and are quite easy to obtain as they are regularly used with arduino based products.

ds18b20pinFirst step is wiring the module to the LPC812, the version I use has 3 pins (TO-92), there are 2 ways that the module can be powered, either directly or parasitically where it uses current from the data line. I’ve found previously using the parasitic mode just added complications so have decided to go with the standard approach.
Using the EtnaNode 2nd Gen board I wired up pin 1 to ground, pin 3 to 3.3v (from the regulator) and then the DQ (data) pin to PIO0_12. As per the Figure 5 schematic it is necessary to have a 4.7K resistor as a pullup on the DQ line.ds18b20schem

Next step is sorting out the software side, the DS18b20 uses 1-Wire  protocol where it only requires a single data line (it can do both rx/tx). The LPC812 doesn’t have specific hardware for this but can just use a GPIO to bitbang the protocol. Luckily there is already software for both the 1-wire bus and ds18b20 by Joe Desbonnet (https://github.com/jdesbonnet) which he used for is LPC810 SousVide controller. I was able to integrate this code into my own LPC812 code with only a few changes. The DS18b20 relies on some quick timings, 1us ideally, and so my current mrtDelay was insufficient (this only allows 1ms). Looking at alternative code for LPC81* and DS18b20 by Gerrit Tamboer (http://home.kpn.nl/geetee1/lpc810_psychrometer.html) I saw that he used the function __delayticks() to give quicker timing and so I replicated this making a new UmrtDelay() function to give us microsecond level delays. Once all the delays were moved over to this new function I was then able to start reading the DS18b20.

The only issue currently is that the returned value is degC*100 to avoid using floats, it would be nice to fully integrate floats into the transmitted data but this is something that i’ll need to sort out with my stripped down version of sprintf. The code also only allows for a single DS18b20 on the 1-wire bus, in theory you could have more then 1 sensor on a single pin but this would requiring searching for each sensors ‘address’.

Find the latest code in the LPC812 github, in particular ds18b20.c and onewire.c you’ll need to ensure that you’ve selected the correct defines in settings.h including which pin the DQ line of the DS18b20 is connected to.