Pages: [1]   Go Down
Author Topic: dallas ds1820  (Read 772 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 49
love arduino
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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:
   if(insideThermometer == 25){                              // error here
    digitalWrite(13, HIGH);
  }
  else {
    digitalWrite(13,LOW);
  }



how can the value be be catch? :?

Tks in advance any help...
« Last Edit: November 25, 2012, 11:23:51 am by KJMM » Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 150
Posts: 6139
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
   if(insideThermometer >= 25){
    digitalWrite(13, HIGH);
  }
  else {
    digitalWrite(13,LOW);
  }
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 49
love arduino
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi SurferTim...

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

Code:
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
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26525
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Does this
Code:
float tempC = sensors.getTempC(deviceAddress);
help any?
Logged

"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.

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 150
Posts: 6139
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 49
love arduino
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

TY 

SurferTim and AWOL

smiley gr8
Logged

Pages: [1]   Go Up
Jump to: