multiple DS18B20 unstable results

Hi,

Does anyone have some pointers for me? I'm trying to read temperature readings from 4x DS18B20 sensors, connected to a LinkIt One. There's a 4.7K resistor between the data line and 5V+ from the LinkIt One. With a seperate Volt meter, I can see the volts on the "bus" is between 4.7V and 5.5V, while connected to the USB port on my laptop. Using the 3.3V pin on the LinkIt One does the same, through voltages range from 3.8V to 4.1V on the Volt meter.

I have tried numerous sketches but they all have the same symptoms. Sometimes I get readings, sometimes not.

Here is one such sample:

//  This Arduino sketch reads DS18B20 "1-Wire" digital
//  temperature sensors.
//  Copyright (c) 2010 Mark McComb, hacktronics LLC
//  License: http://www.opensource.org/licenses/mit-license.php (Go crazy)
//  Tutorial:
//  http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html

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

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

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

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

// Assign the unique 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 GarageTemp = { 0x28, 0x50, 0x00, 0xA0, 0x07, 0x00, 0x00, 0xE3 };
DeviceAddress PVTemp = { 0x28, 0x78, 0xCA, 0xA1, 0x07, 0x00, 0x00, 0xE4 };
DeviceAddress UnderPVTemp = { 0x28, 0x52, 0xCA, 0xA0, 0x07, 0x00, 0x00, 0x12 };
DeviceAddress GarageRoofTemp = { 0x28, 0xEB, 0x92, 0x65, 0x05, 0x00, 0x00, 0xDF };

void setup(void)
{
  // start serial port
  Serial.begin(9600);
  // Start up the library
  sensors.begin();
  // set the resolution to 10 bit (good enough?)
  sensors.setResolution(GarageTemp, 6);
  sensors.setResolution(PVTemp, 6);
  sensors.setResolution(UnderPVTemp, 12);
  sensors.setResolution(GarageRoofTemp, 12);
}

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);
//  }
}

void loop(void)
{ 
  delay(1000);
  Serial.print("Getting temperatures...\n\r");
  sensors.requestTemperatures();
  
  Serial.print("Garage temperature is: ");
  printTemperature(GarageTemp);
  Serial.print("\n\r");
  Serial.print("Garage Roof temperature is: ");
  printTemperature(GarageRoofTemp);
  Serial.print("\n\r");
  Serial.print("PV temperature is: ");
  printTemperature(PVTemp );
  Serial.print("\n\r");
  Serial.print("Under PV Temp is: ");
  printTemperature(UnderPVTemp);
  Serial.print("\n\r\n\r");
}

Serial console output:

// This Arduino sketch reads DS18B20 "1-Wire" digital
// temperature sensors.
// Copyright (c) 2010 Mark McComb, hacktronics LLC
// License: The MIT License | Open Source Initiative (Go crazy)
// Tutorial:
// Arduino 1-Wire Tutorial

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

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

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

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

// Assign the unique addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// Arduino 1-Wire Address Finder

DeviceAddress GarageTemp = { 0x28, 0x50, 0x00, 0xA0, 0x07, 0x00, 0x00, 0xE3 };
DeviceAddress PVTemp = { 0x28, 0x78, 0xCA, 0xA1, 0x07, 0x00, 0x00, 0xE4 };
DeviceAddress UnderPVTemp = { 0x28, 0x52, 0xCA, 0xA0, 0x07, 0x00, 0x00, 0x12 };
DeviceAddress GarageRoofTemp = { 0x28, 0xEB, 0x92, 0x65, 0x05, 0x00, 0x00, 0xDF };

void setup(void)
{
// start serial port
Serial.begin(9600);
// Start up the library
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(GarageTemp, 6);
sensors.setResolution(PVTemp, 6);
sensors.setResolution(UnderPVTemp, 12);
sensors.setResolution(GarageRoofTemp, 12);
}

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);
// }
}

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

Serial.print("Garage temperature is: ");
printTemperature(GarageTemp);
Serial.print("\n\r");
Serial.print("Garage Roof temperature is: ");
printTemperature(GarageRoofTemp);
Serial.print("\n\r");
Serial.print("PV temperature is: ");
printTemperature(PVTemp );
Serial.print("\n\r");
Serial.print("Under PV Temp is: ");
printTemperature(UnderPVTemp);
Serial.print("\n\r\n\r");
}

Here's some photos of the setup.

How about actually posting the serial console output instead of a second copy of the code!

Also - put that output in a code box instead of a quote box, it will be easier to read.

Are you sure the device addresses are correct?

The valid choices for resolution are 9, 10, 11, and 12. I don't know what that library does with '6'. What happens if you leave all four resolutions at 10?

Try increasing the delay, especially if you want the higher resolution.

Why did you jam the resistor into the Dupont connector instead of using the breadboard? Maybe the connection is flaky. Are you sure it's 4.7K, the third band looks somewhat orange to me?

Don

I think resolution '6' is illegitimate. If you delete all that stuff they will run at 12 bit by default. I use the Hacktronics code for four sensors and it is fine. The delay you already have is more than sufficient.

Maybe the connection is flaky.

Yes, move that resistor onto the breadboard..

Here's code I use often that I know works:
https://arduino-info.wikispaces.com/Brick-Temperature-DS18B20#mult

floresta:
How about actually posting the serial console output instead of a second copy of the code!

Also - put that output in a code box instead of a quote box, it will be easier to read.

Uhm, oops :o

Getting temperatures...

GarageTemp temperature is: C: 26.06

GarageRoofTemp  temperature is: C: 26.37

PVTemp  temperature is: C: 26.75

UnderPVTemp temperature is: C: 26.94


Getting temperatures...

GarageTemp temperature is: C: 26.06

GarageRoofTemp  temperature is: Error getting temperature

PVTemp  temperature is: Error getting temperature

UnderPVTemp temperature is: C: 26.94


Getting temperatures...

GarageTemp temperature is: C: 26.12

GarageRoofTemp  temperature is: C: 26.37

PVTemp  temperature is: Error getting temperature

UnderPVTemp temperature is: C: 26.94


Getting temperatures...

GarageTemp temperature is: Error getting temperature

GarageRoofTemp  temperature is: C: 26.31

PVTemp  temperature is: Error getting temperature

UnderPVTemp temperature is: C: 26.94


Getting temperatures...

GarageTemp temperature is: C: 26.12

GarageRoofTemp  temperature is: C: 26.37

PVTemp  temperature is: C: 26.69

UnderPVTemp temperature is: C: 26.94

floresta:
Are you sure the device addresses are correct?

I checked each IC's address individually using the "1-wire address finder" sketch

floresta:
The valid choices for resolution are 9, 10, 11, and 12. I don't know what that library does with '6'. What happens if you leave all four resolutions at 10?

I kinda took a "stab in the dark" with that '6', didn't do anything. The default was 10, I tried 11 and 12 as well, and then just a random number way down. Same happens no matter which resolution I tried.

floresta:
Try increasing the delay, especially if you want the higher resolution.

This is with a delay of 5000 and a resolution of '9':

Getting temperatures...

GarageTemp temperature is: C: 25.69

GarageRoofTemp  temperature is: C: 25.87

PVTemp  temperature is: C: 26.62

UnderPVTemp temperature is: C: 26.69


Getting temperatures...

GarageTemp temperature is: Error getting temperature

GarageRoofTemp  temperature is: C: 25.94

PVTemp  temperature is: C: 26.62

UnderPVTemp temperature is: C: 26.69


Getting temperatures...

GarageTemp temperature is: Error getting temperature

GarageRoofTemp  temperature is: C: 25.94

PVTemp  temperature is: C: 26.50

UnderPVTemp temperature is: C: 26.62


Getting temperatures...

GarageTemp temperature is: C: 25.75

GarageRoofTemp  temperature is: Error getting temperature

PVTemp  temperature is: Error getting temperature

UnderPVTemp temperature is: C: 26.62


Getting temperatures...

GarageTemp temperature is: C: 25.69

GarageRoofTemp  temperature is: Error getting temperature

PVTemp  temperature is: C: 26.50

UnderPVTemp temperature is: C: 26.69


Getting temperatures...

GarageTemp temperature is: C: 25.75

GarageRoofTemp  temperature is: C: 25.94

PVTemp  temperature is: Error getting temperature

UnderPVTemp temperature is: C: 26.69

floresta:
Why did you jam the resistor into the Dupont connector instead of using the breadboard? Maybe the connection is flaky. Are you sure it's 4.7K, the third band looks somewhat orange to me?

It's a 4K7 resistor, light was probably a bit bad. I stuck it in there as it felt a bit loose in the breadboard, though it didn't help either.

terryking228:
Yes, move that resistor onto the breadboard..

Here's code I use often that I know works:
https://arduino-info.wikispaces.com/Brick-Temperature-DS18B20#mult

Thanx, here's the output from your code, but with my sensor's addresses:

Number of Devices found on bus = 4
Getting temperatures... 
Probe 01 temperature is:   Error getting temperature  
Probe 02 temperature is:   C: 29.50
Probe 03 temperature is:   C: 29.00
Probe 04 temperature is:   C: 28.00

Number of Devices found on bus = 4
Getting temperatures... 
Probe 01 temperature is:   C: 27.50
Probe 02 temperature is:   C: 29.00
Probe 03 temperature is:   C: 29.00
Probe 04 temperature is:   C: 28.00

Number of Devices found on bus = 4
Getting temperatures... 
Probe 01 temperature is:   C: 27.50
Probe 02 temperature is:   Error getting temperature  
Probe 03 temperature is:   C: 29.00
Probe 04 temperature is:   C: 28.00

Number of Devices found on bus = 4
Getting temperatures... 
Probe 01 temperature is:   C: 27.50
Probe 02 temperature is:   Error getting temperature  
Probe 03 temperature is:   Error getting temperature  
Probe 04 temperature is:   Error getting temperature  

Number of Devices found on bus = 4
Getting temperatures... 
Probe 01 temperature is:   Error getting temperature  
Probe 02 temperature is:   C: 29.50
Probe 03 temperature is:   C: 29.00
Probe 04 temperature is:   C: 28.00

It's a 4K7 resistor, light was probably a bit bad. I stuck it in there as it felt a bit loose in the breadboard, though it didn't help either.

Maybe the sensors are loose as well.

Don

floresta:
Maybe the sensors are loose as well.

Don

They do feel tight in the breadboard, but are these particular sensors very very sensitive?

RudiAhlers:
They do feel tight in the breadboard, but are these particular sensors very very sensitive?

Just an update on this, once I had all the sensors soldered onto wires and put some heatshrink on to protect the "legs", the readings were much more stable.

Maybe a "bad" sensor? Not likely, but when other explanations fail?... I'd start with one, add another, etc. If, say, adding 3rd "breaks" it, then go back to 1... but start this time with the one that was 3... was it the SENSOR, or the fact that there were now three in the system?

For development work, pay a little extra for "known good" devices from a reliable supplier. These can be replaced with eBay cheapies when you know everything else is "good".

tkbyd:
For development work, pay a little extra for "known good" devices from a reliable supplier. These can be replaced with eBay cheapies when you know everything else is "good".

Sounds like good advice, but I have a couple of dozen "ebay cheapies", and their performance tends to suggest they are "known good".