Dallas Temperature Sensor

I am wanting to use this sketch Original Dallas Temp Sensor - Pastebin.com to use multiple sensors to monitor temperature via a Arduino, but when I amend the code to reflect the address of the sensors;

  // assign address manually.  the addresses below will beed to be changed
  // to valid device addresses on your bus.  device address can be retrieved
  // by using either sensors.search(deviceAddress) or individually via
  // sensors.getAddress(deviceAddress, index)
  insideThermometer = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 };
  outsideThermometer   = { 0x28, 0x3F, 0x1C, 0x31, 0x2, 0x0, 0x0, 0x2 };
 
  // search for devices on the bus and assign based on an index.  ideally,
  // you would do this to initially discover addresses on the bus and then
  // use those addresses and manually assign them (see above) once you know
  // the devices on your bus (and assuming they don't change).
  // if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0");
  // if (!sensors.getAddress(outsideThermometer, 1)) Serial.println("Unable to find address for Device 1");
 
  // show the addresses we found on the bus
  //Serial.print("Device 0 Address: ");
  //printAddress(insideThermometer);
  //Serial.println();
 
  // Serial.print("Device 1 Address: ");
  //printAddress(outsideThermometer);
  //Serial.println();

It will not compile, and highlights errors here;

insideThermometer = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 };
outsideThermometer   = { 0x28, 0x3F, 0x1C, 0x31, 0x2, 0x0, 0x0, 0x2 };

The amended code is here Amended Dallas Temp Sensor - Pastebin.com but I can't understand what I am doing wrong??

Those declarations need to be global or static, with a datatype

AWOL:
Those declarations need to be global or static, with a datatype

Really sorry to show my ignorance, but aren't they declared as variables?

// arrays to hold device addresses
uint8_t insideThermometer[8], outsideThermometer[8];

(please make the answer easy for a beginner!! )

In C/C++, you can initialize arrays with a list only when you define the array. So

int insideThermometer[] = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 };

is valid, but:

int insideThermometer[8];
insideThermometer = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 };

is not.

Initialization from a list is something the compiler does. The compiler actually does the initialization in the first case by reserving the memory and filling in the values at the same time. The compiler can't do anything in the second case - the memory for the array has already been allocated, so a change would have to happen at runtime.

OK, I have tried replacing

// arrays to hold device addresses
DeviceAddress insideThermometer, outsideThermometer;

with

// arrays to hold device addresses
int insideThermometer[] = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 };
int outsideThermometer[] = { 0x28, 0x1D, 0x39, 0x34, 0x5, 0x1, 0x0, 0xF0 };

but it still errors..
This sketch by Miles Burton is really popular and well respected, so I can't understand why I'm having all these problems getting it to work, I'm sure it's something that I have overlooked.

The errors probably relate to you having changed the type of those variables.
Probably.

I see the code I use has :
DeviceAddress outsideThermometer = { 0x28 .......

here's the code I use if it is of help to you.

// This Arduino sketch reads DS18B20 "1-Wire" digital
// temperature sensors.
// 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 11

// 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 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 outsideThermometer = { 0x28, 0x3C, 0xC0, 0x08, 0x03, 0x00, 0x00, 0x54 };
//DeviceAddress outsideThermometer = { 0x28, 0x6B, 0xDF, 0xDF, 0x02, 0x00, 0x00, 0xC0 };
//DeviceAddress dogHouseThermometer = { 0x28, 0x59, 0xBE, 0xDF, 0x02, 0x00, 0x00, 0x9F };

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(outsideThermometer, 11);
//  sensors.setResolution(outsideThermometer, 10);
//  sensors.setResolution(dogHouseThermometer, 10);
}

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

void loop(void)
{ 
  delay(2000);
  Serial.print("Getting temperatures...\n\r");
  sensors.requestTemperatures();
  
  Serial.print("Outside temperature is: ");
  printTemperature(outsideThermometer);
  Serial.print("\n\r");
//  Serial.print("Outside temperature is: ");
//  printTemperature(outsideThermometer);
//  Serial.print("\n\r");
//  Serial.print("Dog House temperature is: ");
//  printTemperature(dogHouseThermometer);
//  Serial.print("\n\r\n\r");
}

The code is useful, but because I don't have the libraries, the error messages would be even more helpful

Many thanks to Miles Burton (http://milesburton.com), who suggested including this;

uint8_t insideThermometer[8] = { 0x28, 0xC0, 0x5E, 0x9C, 0x03, 0x00, 0x00, 0xA1 };
uint8_t outsideThermometer[8]   = { 0x28, 0x3F, 0x1C, 0x31, 0x2, 0x0, 0x0, 0x2 };

in the global scope (outside of any functions like Loop()) and now it works great.

Hello !

i am a beginner in world of programing and need a help , i have a arduino duemilanove and ARDUINO 0022 software.
when i paste this code,i got serval error http://img265.imageshack.us/img265/4549/onewireproblem.jpg

sorry for bad english. :grin:

mladislavonac:
Hello !

i am a beginner in world of programing and need a help , i have a arduino duemilanove and ARDUINO 0022 software.
when i paste this code,i got serval error ImageShack - Best place for all of your image hosting and image sharing needs

sorry for bad english. :grin:

Have you added the onewire library to your Arduino library folder?