Pages: [1]   Go Down
Author Topic: DS18B20 temperature sensor problem  (Read 2913 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i have 2 18B20 temp sensors ...

Found '1-Wire' device with address:
0x28, 0xC2, 0x39, 0x77, 0x03, 0x00, 0x00, 0x52
Found '1-Wire' device with address:
0x28, 0x3F, 0x2B, 0x77, 0x03, 0x00, 0x00, 0x95

1 HD74480 LCD  and an arduino uno

i can make each of them work seperatly (lcd hello world and 18B20 read temp through serial monitor)

i cant get it to work together.
here is the code im using...

Quote
// 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>
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

int backLight = 13; // pin 13 will control the backlight

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

// 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 insideThermometer = { 0x28, 0xC2, 0x39, 0x77, 0x03, 0x00, 0x00, 0x52 };
DeviceAddress outsideThermometer = { 0x28, 0x3F, 0x2B, 0x77, 0x03, 0x00, 0x00, 0x95 };

void setup(void)
{
// Start up the library
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(insideThermometer, 10);
sensors.setResolution(outsideThermometer, 10);

pinMode(backLight, OUTPUT);
digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
lcd.begin(16,2); // columns, rows. use 16,2 for a 16x2 LCD, etc.
lcd.clear(); // start with a blank screen
}

void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC();
if (tempC == -127.00) {
lcd.print("Error");
} else {
lcd.print(tempC);
lcd.print("/");
lcd.print(DallasTemperature::toFahrenheit(tempC));
}
}

void loop(void)
{
delay(2000);
sensors.requestTemperatures();
lcd.setCursor(0,0);
lcd.print("In: ");
printTemperature(insideThermometer);
lcd.setCursor(0,1);
lcd.print("Out: ");
printTemperature(outsideThermometer);
}



this is the error im getting

Quote
sketch_oct13a:7: error: variable or field 'printTemperature' declared void
sketch_oct13a:7: error: 'DeviceAddress' was not declared in this scope
sketch_oct13a:20: error: no matching function for call to 'DallasTemperature::DallasTemperature(OneWire*)'
C:\Users\Chad\Downloads\arduino-0023\arduino-0023\libraries\DallasTemperature/DallasTemperature.h:48: note: candidates are: DallasTemperature::DallasTemperature(NewOneWire&, uint8_t, StratBase*)
C:\Users\Chad\Downloads\arduino-0023\arduino-0023\libraries\DallasTemperature/DallasTemperature.h:20: note:                 DallasTemperature::DallasTemperature(const DallasTemperature&)
sketch_oct13a:26: error: 'DeviceAddress' does not name a type
sketch_oct13a:27: error: 'DeviceAddress' does not name a type
sketch_oct13a.cpp: In function 'void setup()':
sketch_oct13a:34: error: 'class DallasTemperature' has no member named 'setResolution'
sketch_oct13a:34: error: 'insideThermometer' was not declared in this scope
sketch_oct13a:35: error: 'class DallasTemperature' has no member named 'setResolution'
sketch_oct13a:35: error: 'outsideThermometer' was not declared in this scope
sketch_oct13a.cpp: At global scope:
sketch_oct13a:43: error: variable or field 'printTemperature' declared void
sketch_oct13a:43: error: 'DeviceAddress' was not declared in this scope

any guidance is appreciated.

please dont do the " just use the search function of the forum" i already have as well as crawled all over the net searching before i posted.
« Last Edit: October 14, 2012, 01:52:32 am by WonHungLow » Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 549
Posts: 46129
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What version of the IDE are you using? If it is 1.0.1, try compiling that code on 1.0, and show the messages from that.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok started over with the programming. now im using ...

Quote
// LCD Thermostat
// www.hacktronics.com

#include <OneWire.h>
#include <LiquidCrystal.h>

// Connections:
// rs (LCD pin 4) to Arduino pin 12
// rw (LCD pin 5) to Arduino pin 11
// enable (LCD pin 6) to Arduino pin 10
// LCD pin 15 to Arduino pin 13
// LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 2
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
int backLight = 13;    // pin 13 will control the backlight

OneWire  ds(smiley-cool;        // ds18b20 pin #2 (middle pin) to Arduino pin 8

byte i;
byte present = 0;
byte data[12];
byte addr[8];
 
int HighByte, LowByte, SignBit, Whole, Fract, TReading, Tc_100, FWhole;

void setup(void) {
  pinMode(backLight, OUTPUT);
  digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
  lcd.begin(2,16);              // rows, columns.  use 2,16 for a 2x16 LCD, etc.
  lcd.clear();                  // start with a blank screen
  lcd.setCursor(0,0);           // set cursor to column 0, row 0
 
    if ( !ds.search(addr)) {
      lcd.clear(); lcd.print("No more addrs");
      delay(1000);
      ds.reset_search();
      return;
  }

  if ( OneWire::crc8( addr, 7) != addr[7]) {
      lcd.clear(); lcd.print("CRC not valid!");
      delay(1000);
      return;
  }
}

void getTemp() {
  int foo, bar;
 
  ds.reset();
  ds.select(addr);
  ds.write(0x44,1);
 
  present = ds.reset();
  ds.select(addr);   
  ds.write(0xBE);

  for ( i = 0; i < 9; i++) {
    data = ds.read();
  }
 
  LowByte = data[0];
  HighByte = data[1];
  TReading = (HighByte << smiley-cool + LowByte;
  SignBit = TReading & 0x8000;  // test most sig bit
 
  if (SignBit) {
    TReading = -TReading;
  }
  Tc_100 = (6 * TReading) + TReading / 4;    // multiply by (100 * 0.0625) or 6.25
  Whole = Tc_100 / 100;          // separate off the whole and fractional portions
  Fract = Tc_100 % 100;
  if (Fract > 49) {
    if (SignBit) {
      --Whole;
    } else {
      ++Whole;
    }
  }

  if (SignBit) {
    bar = -1;
  } else {
    bar = 1;
  }
  foo = ((Whole * bar) * 18);      // celsius to fahrenheit conversion section
  FWhole = (((Whole * bar) * 18) / 10) + 32;
  if ((foo % 10) > 4) {            // round up if needed
       ++FWhole;
  }
}

void printTemp(void) {
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Temp is: ");
  lcd.setCursor(0,1);   
 
  if (SignBit) { 
     lcd.print("-");
  }
  lcd.print(Whole);
  lcd.print(" C / ");
  lcd.print(FWhole);
  lcd.print(" F");
}

void loop(void) {
  getTemp();
  printTemp();
  delay(1000);
}


and everything is working fine except the lcd always says "Temp is: 85C / 185F "
no matter what i do am i overlooking something in the coding
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 549
Posts: 46129
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't suppose those smiley faces are doing what you think they are. There is an icon with a # sign on it that is to be used when posting code, so that doesn't happen.

Code:
  int foo, bar;
  if (SignBit) {
    bar = -1;
  } else {
    bar = 1;
  }
  foo = ((Whole * bar) * 18);      // celsius to fahrenheit conversion section
Might I politely suggest that you need to get real. Meaningful names help more than you believe.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12465
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Have you tried the - http://milesburton.com/Dallas_Temperature_Control_Library - ?
It contains some example code to run with multiple sensors.

in your code there is no check for a 'failed' read ...
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: