Go Down

Topic: dallas ds1820 (Read 843 times) previous topic - next topic

KJMM

Nov 25, 2012, 05:21 pm Last Edit: Nov 25, 2012, 05:23 pm by KJMM Reason: 1
Hi ppl!

I´m not getting how to get the tmp value of some (in 1 of 4) dallas temperature to put in on IF STATE,

in Multiple. exemple we got the following, (changed to add more 2...)



scketch:

Code: [Select]

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

#define ONE_WIRE_BUS 2
#define TEMPERATURE_PRECISION 9

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

DeviceAddress insideThermometer, insideThermometer2, outsideThermometer, outsideThermometer2;

void setup(void)
{
 Serial.begin(9600);
 Serial.println("Dallas Temperature IC Control Library Demo");
 pinMode(13, OUTPUT);

 sensors.begin();

 Serial.print("Locating devices...");
 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(insideThermometer, 0)) Serial.println("Unable to find address for Device 0");
 if (!sensors.getAddress(insideThermometer2, 1)) Serial.println("Unable to find address for Device 0");
 if (!sensors.getAddress(outsideThermometer, 2)) Serial.println("Unable to find address for Device 1");
 if (!sensors.getAddress(outsideThermometer2, 3)) Serial.println("Unable to find address for Device 2");


 Serial.print("Device 0 Address: ");
 printAddress(insideThermometer);
 Serial.println();

 Serial.print("Device 1 Address: ");
 printAddress(insideThermometer2);
 Serial.println();

 Serial.print("Device 2 Address: ");
 printAddress(outsideThermometer);
 Serial.println();

 Serial.print("Device 3 Address: ");
 printAddress(outsideThermometer2);
 Serial.println();
 
 sensors.setResolution(insideThermometer, TEMPERATURE_PRECISION);
 sensors.setResolution(insideThermometer2, TEMPERATURE_PRECISION);
 sensors.setResolution(outsideThermometer, TEMPERATURE_PRECISION);
 sensors.setResolution(outsideThermometer2, TEMPERATURE_PRECISION);

 Serial.print("Device 0 Resolution: ");
 Serial.print(sensors.getResolution(insideThermometer), DEC);
 Serial.println();

 Serial.print("Device 0 Resolution: ");
 Serial.print(sensors.getResolution(insideThermometer2), DEC);
 Serial.println();

 Serial.print("Device 1 Resolution: ");
 Serial.print(sensors.getResolution(outsideThermometer), DEC);
 Serial.println();
 
 Serial.print("Device 2 Resolution: ");
 Serial.print(sensors.getResolution(outsideThermometer), DEC);
 Serial.println();
}

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

void printTemperature(DeviceAddress deviceAddress)
{
 float tempC = sensors.getTempC(deviceAddress);
 Serial.print("Temp C: ");
 Serial.print(tempC);
 Serial.print(" Temp F: ");
 Serial.print(DallasTemperature::toFahrenheit(tempC));
}

void printResolution(DeviceAddress deviceAddress)
{
 Serial.print("Resolution: ");
 Serial.print(sensors.getResolution(deviceAddress));
 Serial.println();    
}

void printData(DeviceAddress deviceAddress)
{
 Serial.print("Device Address: ");
 printAddress(deviceAddress);
 Serial.print(" ");
 printTemperature(deviceAddress);
 Serial.println();
}

void loop(void)
{
 Serial.print("Requesting temperatures...");
 sensors.requestTemperatures();
 Serial.println("DONE");

 printData(insideThermometer);
 printData(insideThermometer2);
 printData(outsideThermometer);
 printData(outsideThermometer2);

 
   if(insideThermometer == 25){                              // error here
   digitalWrite(13, HIGH);
 }
 else {
   digitalWrite(13,LOW);
 }
 
 
 delay(1000);
}




(just in button)

Code: [Select]

   if(insideThermometer == 25){                              // error here
   digitalWrite(13, HIGH);
 }
 else {
   digitalWrite(13,LOW);
 }




how can the value be be catch? :?

Tks in advance any help...

SurferTim

The LED will be lit only if the temperature is exactly 25. Try this. The LED will be lit if the temp is at or above 25.
Code: [Select]
   if(insideThermometer >= 25){
    digitalWrite(13, HIGH);
  }
  else {
    digitalWrite(13,LOW);
  }


KJMM

Hi SurferTim...

Tks for reply.. but when compiled give this error..

Code: [Select]

Multiple.cpp: In function 'void setup()':
Multiple.pde:-1: error: expected primary-expression before '{' token
Multiple.pde:-1: error: expected `;' before '{' token
Multiple.cpp: In function 'void loop()':
Multiple.pde:-1: error: ISO C++ forbids comparison between pointer and integer


this is the address of DS right? Why don´t catch value?

BR

AWOL

Does this
Code: [Select]
float tempC = sensors.getTempC(deviceAddress);
help any?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

SurferTim

My bad. That (insideThermometer) is the device number, not the temp, correct?

KJMM

TY 

SurferTim and AWOL

:) gr8

Go Up