Go Down

Topic: Help with DS18S20 (Read 817 times) previous topic - next topic

n3ow

I am trying to just get the thing talking but can't seem to get any sample code to work.
here is the code I am trying to use"#include <OneWire.h>

// DS18S20 Temperature chip i/o
OneWire ds(10);  // on pin 10

void setup(void) {
  // initialize inputs/outputs
  // start serial port
  Serial.begin(9600);
}

void loop(void) {
  byte i;
  byte present = 0;
  byte data[12];
  byte addr[8];

  if ( !ds.search(addr)) {
      Serial.print("No more addresses.\n");
      ds.reset_search();
      return;
  }

  Serial.print("R=");
  for( i = 0; i < 8; i++) {
    Serial.print(addr, HEX);
    Serial.print(" ");
  }

  if ( OneWire::crc8( addr, 7) != addr[7]) {
      Serial.print("CRC is not valid!\n");
      return;
  }

  if ( addr[0] == 0x10) {
      Serial.print("Device is a DS18S20 family device.\n");
  }
  else if ( addr[0] == 0x28) {
      Serial.print("Device is a DS18B20 family device.\n");
  }
  else {
      Serial.print("Device family is not recognized: 0x");
      Serial.println(addr[0],HEX);
      return;
  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44,1);         // start conversion, with parasite power on at the end

  delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.

  present = ds.reset();
  ds.select(addr);   
  ds.write(0xBE);         // Read Scratchpad

  Serial.print("P=");
  Serial.print(present,HEX);
  Serial.print(" ");
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data = ds.read();
    Serial.print(data, HEX);
    Serial.print(" ");
  }
  Serial.print(" CRC=");
  Serial.print( OneWire::crc8( data, 8), HEX);
  Serial.println();
}
Then I get these error msg,

sketch_dec27e:4: error: 'OneWire' does not name a type
sketch_dec27e.ino: In function 'void loop()':
sketch_dec27e:18: error: 'ds' was not declared in this scope
sketch_dec27e:30: error: 'OneWire' has not been declared
sketch_dec27e:47: error: 'ds' was not declared in this scope
sketch_dec27e:67: error: 'OneWire' has not been declared
The device is commected to pin 10 and 5volts from the ardunio. The Ardunio seems to be still running the first program I loaded to it.
Thank you  for the help
Jay

be80be

#1
Dec 28, 2012, 03:53 am Last Edit: Dec 28, 2012, 04:08 am by be80be Reason: 1
Your missing some things make sure set the include files right
You look like you installed them wrong make sure you have the right names

I had to change the name on the files after I unziped them and place them in my library  folder.

n3ow

Oops has the wrong pin called out.
next is to access the data before you.g to serial port.

tonybullard

I  think you also need some #include

// 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 3

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

This tutorial looks prity good. I'm going to try it.

Tony

NickPyner

I found Hacktronics the best tutorial by far.

Go Up