DallasTemp temperature accuracy [need to tweak the code a bit]

Hi guys,

I've managed to connect 5 temp. sensors to one bus using this code:

/* YourDuino Multiple DS18B20 Temperature Sensors on 1 wire
  Connections:
  DS18B20 Pinout (Left to Right, pins down, flat side toward you)
  - Left   = Ground
  - Center = Signal (Pin 10):  (with 3.3K to 4.7K resistor to +5 or 3.3 )
  - Right  = +5 or +3.3 V

   Questions: terry@yourduino.com 
   V1.01  01/17/2013 ...based on examples from Rik Kretzinger
   
/*-----( Import needed libraries )-----*/
// Get 1-wire Library here: http://www.pjrc.com/teensy/td_libs_OneWire.html
#include <OneWire.h>

//Get DallasTemperature Library here:  http://milesburton.com/Main_Page?title=Dallas_Temperature_Control_Library
#include <DallasTemperature.h>

/*-----( Declare Constants and Pin Numbers )-----*/
#define ONE_WIRE_BUS_PIN 10

//lcd
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

/*-----( Declare objects )-----*/
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS_PIN);

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

/*-----( Declare Variables )-----*/
// Assign the addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

DeviceAddress Probe01 = { 0x28, 0x78, 0xE0, 0x10, 0x05, 0x00, 0x00, 0xF0 }; 
DeviceAddress Probe02 = { 0x28, 0xA2, 0xA3, 0x10, 0x05, 0x00, 0x00, 0x5C };
DeviceAddress Probe03 = { 0x28, 0xB8, 0x45, 0x11, 0x05, 0x00, 0x00, 0x01 };
DeviceAddress Probe04 = { 0x28, 0xA2, 0x18, 0x11, 0x05, 0x00, 0x00, 0xEC };
DeviceAddress Probe05 = { 0x28, 0x73, 0x5A, 0x11, 0x05, 0x00, 0x00, 0x75 };


void setup()   /****** SETUP: RUNS ONCE ******/
{
  // start serial port to show results
  Serial.begin(9600);
  Serial.print("Initializing Temperature Control Library Version ");
  Serial.println(DALLASTEMPLIBVERSION);
  lcd.begin(20, 4);
  
  // Initialize the Temperature measurement library
  sensors.begin();
  
  // set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
  sensors.setResolution(Probe01, 10);
  sensors.setResolution(Probe02, 10);
  sensors.setResolution(Probe03, 10);
  sensors.setResolution(Probe04, 10);
  sensors.setResolution(Probe05, 10);

}//--(end setup )---

void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  delay(1000);
  Serial.println();
  Serial.print("Number of Devices found on bus = ");  
  Serial.println(sensors.getDeviceCount());   
  Serial.print("Getting temperatures... ");  
  Serial.println();   
  
  // Command all devices on bus to read temperature  
  sensors.requestTemperatures();  
  
  Serial.print("Probe 01 temperature is:   ");
  printTemperature(Probe01);
  Serial.println();

  Serial.print("Probe 02 temperature is:   ");
  printTemperature(Probe02);
  Serial.println();

 
  Serial.print("Probe 03 temperature is:   ");
  printTemperature(Probe03);
  Serial.println();

   
  Serial.print("Probe 04 temperature is:   ");
  printTemperature(Probe04);
  Serial.println();

  
  Serial.print("Probe 05 temperature is:   ");
  printTemperature(Probe05);
  Serial.println();

    
  
}//--(end main loop )---

/*-----( Declare User-written Functions )-----*/
void printTemperature(DeviceAddress deviceAddress)
{

float tempC = sensors.getTempC(deviceAddress);

   if (tempC == -127.00) 
   {
   Serial.print("Error getting temperature  ");
   } 
   else
   {
   Serial.print("C: ");
   Serial.print(tempC);   
   Serial.print(" F: ");
   Serial.print(DallasTemperature::toFahrenheit(tempC));
   }
}// End printTemperature
//*********( THE END )***********

and what I'd like to do is to change the code so that it displays the temperature more accurately instead of every .25.

Which bit if the code do I need to tweak in order to get what I want? (funny enough, I just noticed that the sensor #5 shows all data, not only .25.

PS. I would also like to display this data on the LCD display. Which bit of the code do I need to modify to get it working properly?

Thanks in advance

It would be a good idea to read up on the libraries you are using. Hint: what do you suppose the following does?

  // set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
  sensors.setResolution(Probe01, 10);

jremington:
It would be a good idea to read up on the libraries you are using. Hint: what do you suppose the following does?

  // set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)

sensors.setResolution(Probe01, 10);

yes and all are set to 10.

What do you suppose the "10" means?

You can get a more precise measurement from the sensor, but it won't be more accurate. The sensors are accurate to +/- 0.5 degrees C.

What I mean is this:

Number of Devices found on bus = 5
Getting temperatures...
Probe 01 temperature is: C: 32.75 F: 90.95
Probe 02 temperature is: C: 31.50 F: 88.70
Probe 03 temperature is: C: 30.75 F: 87.35
Probe 04 temperature is: C: 30.00 F: 86.00
Probe 05 temperature is: C: 26.06 F: 78.91
...
Probe 05 temperature is: C: 26.12 F: 79.02

the first four sensors' accuracy is per 0.25 units and the fifth sensor's accuracy is, by the look of it, per 0.06 units.

Very strange.

I think what happens is that if you specify 10-bit precision it doesn't mean that the two low-order bits will be zero. If you have 10-bit precision you should clear the bottom two bits. The result of 26.06 from probe 5 just means that the bottom two bits happened to be 01 (corresponding to .0625 degrees C) which you should have cleared so that the result was 26.0C.

Pete

el_supremo:
I think what happens is that if you specify 10-bit precision it doesn't mean that the two low-order bits will be zero. If you have 10-bit precision you should clear the bottom two bits. The result of 26.06 from probe 5 just means that the bottom two bits happened to be 01 (corresponding to .0625 degrees C) which you should have cleared so that the result was 26.0C.

Pete

Thanks for an explanation. It makes sense.