Pages: [1]   Go Down
Author Topic: Help with DS18S20  (Read 772 times)
0 Members and 1 Guest are viewing this topic.
Easton Pa
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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, smiley-cool, 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
Logged

Offline Offline
Full Member
***
Karma: 3
Posts: 246
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: December 27, 2012, 10:08:02 pm by be80be » Logged

Easton Pa
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Vermont USA
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Dee Why NSW
Offline Offline
Full Member
***
Karma: 5
Posts: 206
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I found Hacktronics the best tutorial by far.
Logged

Pages: [1]   Go Up
Jump to: