An Expensive Thermometer
Sunday, January 16th, 2011Whilst digging around the components I had ordered I found the digital temperature sensor break out boardI had ordered late last year. I feel a minor enhancement to the LCD project coming on.
Objective
Add the temperature sensor to the project and display the temperature on the LCD.
Hardware
Wiring up the additional hardware is relatively straight forward as we only need four additional connections. I was also helped greatly by Rick Winscot’s post on the Netduino forums. Rick’s post not only contained a class for the temperature sensor but also some helpful comments which gave the wiring to be used.
Pin | Connection |
GND | Ground |
3.3V | 3.3V supply from the Netduino |
SDA | Analog pin 4 on the Netduino |
SCL | Analog pin 5 on the Netduino |
Software
The software was a also simple given that Rick had already done all of the hardwork. It was a simple case of adding the class from Rick’s post to the project and modifying the main program loop to the following:
GpioLcdTransferProvider lcdProvider;
Lcd lcd;
lcdProvider = new GpioLcdTransferProvider(rs: Pins.GPIO_PIN_D12, enable: Pins.GPIO_PIN_D11, d4: Pins.GPIO_PIN_D2, d5: Pins.GPIO_PIN_D3, d6: Pins.GPIO_PIN_D4, d7: Pins.GPIO_PIN_D5);
lcd = new Lcd(lcdProvider);
lcd.Begin(columns: 16, lines: 2);
lcd.Write("Hello, world!");
string temperature; TMP102 temperatureSensor;
TimeSpan time;
temperatureSensor = new TMP102();
temperature = temperatureSensor.GetTemperature();
while (true)
{
if (temperature != null)
{
time = Utility.GetMachineTime();
lcd.SetCursorPosition(column: 0, row: 1);
lcd.Write(temperature + "C " + time.Hours + " : " + time.Minutes + ":"; + time.Seconds + " ");
} Thread.Sleep(1000);
temperature = temperatureSensor.GetTemperature();
}
I did make one slight change to the TMP102 class. The GetTemperature method as originally posted returned “0” if there was a problem reading the temperature. 0oC is within the range of the sensor and so I decided to return null for an invalid reading.
Observations
When I first started the project I had some Debug.Print statements in the code and I was reading the temperature every 200 milliseconds. At this speed I seemed to be getting a few null values being returned. After taking these statements out and setting the timer to 1second I appear to be getting stable readings. The first version of the software yielded the following output:
Comparing the output with the digital output on the central heating thermostat gives a difference of about two degrees.
As for the title, well adding the component prices together gives a cost of approximately £80 for this project when there are perfectly good digital thermometers out there for about £10. But where’s the fun in that!
Credits
As already noted, this project was helped greatly by Rick Winscot’s posting on the Netduino forums – Thanks for donating the code to the community.