Displaying problems with DS18B20

Hi you all.

New to Arduino and in need of some help.
I'm trying to display the temperature from the DS18B20 in my lcd but I can't get it to do what I would like.

What I got to so far:

As you can see the temp. input repeats itself over and over.

What I want:

I'd like to have the temp. input update whithout printing another line in the lcd and also without blinking.

How do I go about doing this? Could you please help me understand what I need to do!
I have no real codingexperience but I'm willing to learn and understand the basics at least.

Here is the code I use:

#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>


// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

//Setup lcd
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

// Assign the addresses of your 1-Wire temp sensors.

DeviceAddress Probe012 = { 0x28, 0x6B, 0xE5, 0xE3, 0x03, 0x00, 0x00, 0x08 };
//DeviceAddress Probe013 = { 0×28, 0×43, 0×77, 0×22, 0×03, 0×00, 0×00, 0x9D };
//DeviceAddress Probe014 = { 0×28, 0×30, 0×65, 0×31, 0×03, 0×00, 0×00, 0×13 };
//DeviceAddress Probe015 = { 0×28, 0xDE, 0x9D, 0×31, 0×03, 0×00, 0×00, 0xB1 };
//DeviceAddress Probe016 = { 0×28, 0x7E, 0x8A, 0×31, 0×03, 0×00, 0×00, 0xC0 };

void setup(void)
{
  // start lcd
  lcd.begin(20, 4);
  // start serial port
  Serial.begin(9600);
  // Start up the library
  sensors.begin();
  // set the resolution to 10 bit (good enough?)
  sensors.setResolution(Probe012, 10);
  //sensors.setResolution(Probe013, 10);
  //sensors.setResolution(Probe014, 10);
  //sensors.setResolution(Probe015, 10);
  //sensors.setResolution(Probe016, 10);
}

void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  if (tempC == -127.00) {
  Serial.print("Error getting temperature");
} 
else 
{
  lcd.print("C: ");
  lcd.print(tempC);
  //Serial.print(” F: “);
  //Serial.print(DallasTemperature::toFahrenheit(tempC));
}
}

void loop(void)
{
  delay(2000);
  Serial.println();
  Serial.println();
  Serial.print("Getting temperatures\n\r");
  sensors.requestTemperatures();

  Serial.print("Probe 012 temperature is: ");
  printTemperature(Probe012);
  Serial.print("\n\r");
  //Serial.print(“Probe 013 temperature is: “);
  //printTemperature(Probe013);
  //Serial.print(“\n\r”);
  //Serial.print(“Probe 014 temperature is: “);
  //printTemperature(Probe014);
  //Serial.print(“\n\r”);
  //Serial.print(“Probe 015 temperature is: “);
  //printTemperature(Probe015);
  //Serial.print(“\n\r”);
  //Serial.print(“Probe 016 temperature is: “);
  //printTemperature(Probe016);
  //Serial.print(“\n\r”);

}

IIRC the LCD lib has a LCD.goto(x,y) function or something similar.

otherwise the LCD has a code to set the cursor on (0,0) or any other position.

check the datasheet.

quick check in the .h file ==> lcd.setCursor(x,y)

Ohh, that was simple.

Works great! Thank you, sir!

hello, I'm having a hard time with the Dallas ds18b20, I tried your code on my arduino mega and my display is showin bogus stuff wrong caracters, reseting etc.
this appends on any code that contains Dallas related queries, when it does this "sensors.begin();" al lines on my display lights up... and when it reads sensor data my display shows wierd caracters...
with other sensors works ok(DHT11, LM35, etc.)

#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>


// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 22

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

//Setup lcd
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

// Assign the addresses of your 1-Wire temp sensors.

DeviceAddress Probe012 = { 0x28, 0xCE, 0xE4, 0xA7, 0x03, 0x00, 0x00, 0x9C };
//DeviceAddress Probe013 = { 0×28, 0×43, 0×77, 0×22, 0×03, 0×00, 0×00, 0x9D };
//DeviceAddress Probe014 = { 0×28, 0×30, 0×65, 0×31, 0×03, 0×00, 0×00, 0×13 };
//DeviceAddress Probe015 = { 0×28, 0xDE, 0x9D, 0×31, 0×03, 0×00, 0×00, 0xB1 };
//DeviceAddress Probe016 = { 0×28, 0x7E, 0x8A, 0×31, 0×03, 0×00, 0×00, 0xC0 };

void setup(void)
{
  // start lcd
  lcd.begin(20, 4);
  // start serial port
  Serial.begin(9600);
  // Start up the library
  sensors.begin();
  // set the resolution to 10 bit (good enough?)
  sensors.setResolution(Probe012, 10);
  //sensors.setResolution(Probe013, 10);
  //sensors.setResolution(Probe014, 10);
  //sensors.setResolution(Probe015, 10);
  //sensors.setResolution(Probe016, 10);
}

void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  if (tempC == -127.00) {
  Serial.print("Error getting temperature");
} 
else 
{
  lcd.print("C: ");
  lcd.print(tempC);
  //Serial.print(” F: “);
  //Serial.print(DallasTemperature::toFahrenheit(tempC));
}
}

void loop(void)
{
  delay(2000);
  Serial.println();
  Serial.println();
  Serial.print("Getting temperatures\n\r");
  sensors.requestTemperatures();

  Serial.print("Probe 012 temperature is: ");
  printTemperature(Probe012);
  Serial.print("\n\r");
  //Serial.print(“Probe 013 temperature is: “);
  //printTemperature(Probe013);
  //Serial.print(“\n\r”);
  //Serial.print(“Probe 014 temperature is: “);
  //printTemperature(Probe014);
  //Serial.print(“\n\r”);
  //Serial.print(“Probe 015 temperature is: “);
  //printTemperature(Probe015);
  //Serial.print(“\n\r”);
  //Serial.print(“Probe 016 temperature is: “);
  //printTemperature(Probe016);
  //Serial.print(“\n\r”);

}

please use the # button around code (you can modify your previous post, select the code and press it. It will look much better :wink:

wrt your problem, you need to check the return values of some of the calls as they return different values for wrong readings.

And always check the wires, replace sensors to see if it is HW.

Finally, I always start with one of the demo programs of the library to see if all is connected well.

Succes

hello, sensors vorl ok on their own, LCD works OK stand alone and with DHT11 and LM35 and other things that I have coded as far, the only problem occurs when using the LCD along with DS18b20, problem is like this:

LCD display is 16x2 when the DS18b20 are initialized the LCD lights all character dots so I see 16x2 rectangles at void setup, after that the first round is OK, then randomly the screen lights up everything, then displays all sort of characters unrelated to the code, then sometimes recovers and displays normal etc. everything is random, as if the actual temperature reading is somehow pushing info to the display...

display is hooked up following this sketch : http://www.arduino.cc/en/Tutorial/LiquidCrystal
only pin layout is different, the power for the whole setup comes from this https://docs.google.com/folder/d/0B36bb78LeC1Ocl83anZmUnhwaEE/edit?pli=1&docId=0B36bb78LeC1ORFJidm9aMVVFRUk , the whole setup is powered from that, so I do not draw to much power from the arduino itself..
DS18b20 are hooked up following this example:One Wire Digital Temperature DS18B20 + Arduino – Dangerous Prototypes

using normal power all 3 wires run from chip to chip
there are two sensors on the bus, I plan on adding 4, but I am testing with 2 for the moment..
tested with each sensor, same thing :frowning:

any idea of what could be the problem?

looking at the code the first thing I spot is a mismatch between comments and code (code always wins)

// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 22

Are you using a MEGA?

If you are using pin 3 for the DS18b20, it is also used for the LCD : LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

Are the addresses of the DS18 correct? The Dallas lib has sample code to extract the addresses.

Hello,

Yes I'm using a mega V2, right now DS is on 22, diplay on 12, 11, 5, 4, 3, 2, DS on it's own is working fine...

Requesting temperatures...DONE
Device Address: 28CEE4A70300009C Temp C: 21.75 Temp F: 71.15
Device Address: 28AB8E5004000095 Temp C: 21.62 Temp F: 70.93
Requesting temperatures...DONE
Device Address: 28CEE4A70300009C Temp C: 21.75 Temp F: 71.15
Device Address: 28AB8E5004000095 Temp C: 21.62 Temp F: 70.93
Requesting temperatures...DONE

display work OK with all the rest, when having a code to use both of them together... it doesn't work..

Sorry about the comments, I haven't bothered to change them, I changed only the code to match my setup...

Ok, redone the sketch as simple as possible:

#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>


LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// Data wire is plugged into port 22 on the Arduino
#define ONE_WIRE_BUS 22
#define TEMPERATURE_PRECISION 12
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);
DeviceAddress  insideThermometer = { 0x28, 0xCE, 0xE4, 0xA7, 0x03, 0x00, 0x00, 0x9C };
DeviceAddress  outsideThermometer = { 0x28, 0xAB, 0x8E, 0x50, 0x04, 0x00, 0x00, 0x95 };

void setup(void)
{
  // start serial port
  Serial.begin(9600);
    lcd.begin(16, 2);
    lcd.clear();
  Serial.println("Dallas Temperature IC Control Library Demo");

  // Start up the library
  sensors.begin();
  sensors.setResolution(insideThermometer, TEMPERATURE_PRECISION);
  sensors.setResolution(outsideThermometer, TEMPERATURE_PRECISION);
}

void loop(void)
{ 
  // call sensors.requestTemperatures() to issue a global temperature 
  // request to all devices on the bus
  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.println("DONE");
 float temp1=sensors.getTempC(insideThermometer);
 float temp2=sensors.getTempC(outsideThermometer);
  Serial.print("Temperature for the device 1 (index 0) is: ");
  //Serial.println(sensors.getTempCByIndex(0)); 
 Serial.println(temp1);
 Serial.print("Temperature for the device 2 (index 1) is: ");
 Serial.println(temp2);
 lcd.clear();
 lcd.setCursor(0, 0);
 lcd.print(temp1);
 lcd.setCursor(0, 1);
 lcd.print(temp2);
 
}

And now the interesting part, behaviour, it has a cile like this:
Displays temp
1sec
then screen displays bogus characters
1sec
scren displays temp, but has one box on 2nd rov(one complete rectangle)
1sec
scren displays temp, but has one box on 2nd rov(one complete rectangle)

tried this:

#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>


LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// Data wire is plugged into port 22 on the Arduino
#define ONE_WIRE_BUS 22
#define TEMPERATURE_PRECISION 12
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);
DeviceAddress  insideThermometer = { 0x28, 0xCE, 0xE4, 0xA7, 0x03, 0x00, 0x00, 0x9C };
DeviceAddress  outsideThermometer = { 0x28, 0xAB, 0x8E, 0x50, 0x04, 0x00, 0x00, 0x95 };

void setup(void)
{
  // start serial port
  Serial.begin(9600);
   lcd.begin(16, 2);
//    lcd.clear();
  Serial.println("Dallas Temperature IC Control Library Demo");

  // Start up the library
  sensors.begin();
  sensors.setResolution(insideThermometer, TEMPERATURE_PRECISION);
  sensors.setResolution(outsideThermometer, TEMPERATURE_PRECISION);
}

void loop(void)
{ 
  // call sensors.requestTemperatures() to issue a global temperature 
  // request to all devices on the bus
  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  delay(3000);
  Serial.println("DONE");
 float temp1=sensors.getTempC(insideThermometer);
 float temp2=sensors.getTempC(outsideThermometer);
 delay(3000);
  Serial.print("Temperature for the device 1 (index 0) is: ");
  //Serial.println(sensors.getTempCByIndex(0)); 
 Serial.println(temp1);
 Serial.print("Temperature for the device 2 (index 1) is: ");
 Serial.println(temp2);
// lcd.clear();
// lcd.setCursor(0, 0);
// lcd.print(temp1);
// lcd.setCursor(0, 1);
// lcd.print(temp2);
 delay(2000);
}

display is shoving every line at initialization, and then starts displaying shifting random bogus characters...

try this, to check if your LCD and floats work well together

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup(void)
{
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(123);
  lcd.setCursor(0, 1);
  lcd.print(123.125);
}

void loop(void){}

Sorry about the comments, I haven't bothered to change them, I changed only the code to match my setup...

Uncle Bob Martin would say that if you use variables and functions with meaningful names, you would not need any comment at all.
Your code "reads as proze"

More about Uncle Bob - Clean Coder - his clean coding videos are good (and hilarious)

Hello,

Works like charm mate,

first row:123
second row:123.12

It even works well displaying date&time from RTC, temp values and humidity from DHT11, temp from LM35...
I even tried wiring the DS to 3.3v, same issue...

It seems I'm not the only one.. :frowning:

http://arduino.cc/forum/index.php/topic,44683.0.html

No clue yet....
Can you post a picture of the bogus chars?
Do you power the Arduino from USB or from a wall wart?
Do you have a voltmeter? if so can you confirm the LCD gets 5.0V

rereading the thread for clues....
Aha, new hypothesis:

On the picture (post 1) you have a 20x4 screen and you initialize it with
lcd.begin(16, 2);

Please try to change that to
lcd.begin(20,4);

Hello, the image is not from my project, I have 16x2 LCD

myu project without DS18B20

And with the last code, the simple one, only display and DS18B20

can you post an image of the backside of the panel?

Voltage is 4.95v(read with an inferior class voltmeter-cat2, if you need accurate readings let me know to looc for a cat3)

The back side of the LCD?

it was to see the soldering points, sometimes strange chars are caused by wires that short(?) every now and then. Although not sharp it looks like the soldering is not the issue here.

4.95 Volt seems high enough,

I still have the feeling it is some hardware failure as there is an image in which the 75 is in the right place but the rest is wrong. That implies that the bytes are send well to the LCD. Do you have another LCD to test if the cause is in the LCD (+wiring) or in the Arduino + temp sensors?