Skip to content

Displaying temperature from DS18B20 on S65 Shield

2014 Januar 23
by Jan

Hey Folks,

in somewhat of a building spree i took the code for reading the DS18B20 digital temperatur sensor and built a thermometer to display the temperature outside. It´s cold in Berlin.

Here´s the code:

#include
#include
#include
int ledPin1 = 3;

#define ONE_WIRE_BUS 7

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

S65Display lcd;

DeviceAddress VL;

void setup(void)
{
Serial.begin(9600);
Serial.println(“Dallas Temperature IC Control Library Demo”);

Serial.print(“Locating devices…”);
sensors.begin();
Serial.print(“Found “);
Serial.print(sensors.getDeviceCount(), DEC);
Serial.println(” devices.”);

Serial.print(“Parasite power is: “);
if (sensors.isParasitePowerMode()) Serial.println(“ON”);
else Serial.println(“OFF”);

if (!sensors.getAddress(VL, 0)) Serial.println(“No address for D 0″);

Serial.print(“Device 0 Address: “);
printAddress(VL);
Serial.println();

sensors.setResolution(VL, 9);

Serial.print(“Device 0 Resolution: “);
Serial.print(sensors.getResolution(VL), DEC);
Serial.println();

lcd.init(4);

sei();

lcd.clear(RGB(0,0,0));

}

void printTemperature(DeviceAddress deviceAddress)
{

float tempC = sensors.getTempC(deviceAddress);
//Serial.print(“Temp C: “);
//Serial.print(tempC);

char Vorlauf[30];

itoa(tempC,Vorlauf,10);
Serial.println(Vorlauf);
lcd.drawText(15, 10, “Temperatur aussen”, 1, RGB( 0,255, 0), RGB(0, 0, 0));
lcd.drawText(15, 20, Vorlauf, 9, RGB( 255, 255, 255), RGB(0, 0, 0));

//lcd.drawTextPGM(5,10,PSTR(“VL Temp:=”),RGB(0,0,255),RGB(255,0,0));

}

void loop(void)
{

Serial.print(“Requesting temperatures…”);
sensors.requestTemperatures();
Serial.println(“DONE”);

digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin1, LOW);

printTemperature(VL);
delay(2000);
}

void printAddress(DeviceAddress deviceAddress)
{
for (uint8_t i = 0; i < 8; i++)
{
if (deviceAddress[i] < 16) Serial.print(“0″);
Serial.print(deviceAddress[i], HEX);
}
}

 

and here´s a picture of the system running:

Foto am 23.01.14 um 21.29

No comments yet

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS