Pages: 1 [2] 3   Go Down
Author Topic: Please update OneWire page for DS18B20  (Read 5435 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello, im new here! thanks for all the inforrmation. can anyone please help me make the VB6 code for the pc thermometer ds1820. Thank you very much for your reply..
Logged

Montreal
Offline Offline
Full Member
***
Karma: 0
Posts: 185
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi i did a web server showing all the DS18B20 attach and printint the temperature on a web page.
If anyone wants it!
Actually i just grab some code here and there (on this site) and match every thing so it work for my application
Code:
/*
 * Multiport Web Server
 *
 * A simple web server that shows
 * the value of the analog and digital input pins.
 *
 * port 80: human readable page
 * port 8080: machine readable page (csv format)
 */
#include <OneWire.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 123 };
//byte gateway[] = { 192, 168, 0, 254 };
//byte subnet[] = { 255, 255, 255, 0 };

Server server1(80); // server for human beings
Server server2(8080); // server for machines
// DS18S20 Temperature chip i/o

OneWire ds(9);  // on pin 10

void setup()
{
  for (int i = 2 ; i < 8; i++){
    pinMode(i, INPUT);
    //digitalWrite(i, HIGH);
  }
  //Ethernet.begin(mac, ip, gateway, subnet);
  Ethernet.begin(mac, ip);
  server1.begin();
  server2.begin();
}

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


  Client client1 = server1.available();
  Client client2 = server2.available();
  if (client1) {
    boolean current_line_is_blank = true;
    while (client1.connected()) {
      if (client1.available()) {
        char c = client1.read();
        if (c == '\n' && current_line_is_blank) {
          client1.println("HTTP/1.1 200 OK");
          client1.println("Content-Type: text/html");
          client1.println();

          
//            if ( !ds.search(addr)) {
//              // No more adresses
//              ds.reset_search();
//            }
            
            //else {
            while (ds.search(addr)) {
              client1.print("A=");
              for( i = 0; i < 8; i++) {
                client1.print(addr[i], HEX);
                client1.print(" ");
              }

              if ( OneWire::crc8( addr, 7) != addr[7]) {
                client1.print("CRC is not valid!\n");
                client1.println("<br />");

                //      return;
              }

              if ( addr[0] != 0x28) {
                client1.print("Device is not a DS18S20 family device.\n");
                client1.println("<br />");

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

              for ( i = 0; i < 9; i++) {           // we need 9 bytes
                data[i] = ds.read();
              }
              int rawtemp = (data[1] << 8) + data[0];
              int tempca = rawtemp / 16.0;
              int tempcb = rawtemp % 16;

              client1.print(" Celcius = ");
              client1.print(tempca);
              client1.print(".");
              client1.print(tempcb);
              client1.println("<br />");
            }
            // No more device then reset the search
            ds.reset_search();




/*
          for (int i = 0; i < 6; i++) {
            client1.print("analog input ");
            client1.print(i);
            client1.print(" is ");
            client1.print(analogRead(i));
            client1.println("<br />");
          }
          for (int i = 2; i < 8; i++) {
            client1.print("digital input ");
            client1.print(i);
            client1.print(" is ");
            if (digitalRead(i)) {
              client1.print("HIGH");
            } else {
              client1.print("LOW");
            }
            client1.println("<br />");
          }
*/
          break;
        }
        if (c == '\n') {
          current_line_is_blank = true;
        } else if (c != '\r') {
          current_line_is_blank = false;
        }

      }
    }
  
    delay(10);
    client1.stop();
  }
  
  if (client2) {
    boolean current_line_is_blank = true;
    while (client2.connected()) {
      if (client2.available()) {
        char c = client2.read();
        if (c == '\n' && current_line_is_blank) {
          client2.println("HTTP/1.1 200 OK");
          client2.println("Content-Type: text/html");
          client2.println();
          for (int i = 0; i < 6; i++) {
            if (i != 0)
              client2.print(",");
            client2.print(analogRead(i));
          }
          for (int i = 2; i < 8; i++) {
            client2.print(",");
            client2.print(digitalRead(i));
          }
          break;
        }
        if (c == '\n') {
          current_line_is_blank = true;
        } else if (c != '\r') {
          current_line_is_blank = false;
        }
      }
    }
    delay(10);
    client2.stop();
  }

}
Logged

Patgadget
Montreal

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you get this to work in Flash??
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

where do i get the onewire.h?
Logged

London
Offline Offline
Sr. Member
****
Karma: 1
Posts: 330
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Onewire.h is included with the ide.

Just use:
#include <OneWire.h>

As per Patgadget's example.

Gordon
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 39
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You need to download and install the OneWire library - it's not included as part of the Arduino distribution.   You should download the most recent version of the library from
this page

http://homepage.mac.com/wtpollard/Software/FileSharing7.html

unzip it, and copy the OneWire directory into your Arduino hardware/libraries folder.  There's a page on the Arduino playground with some examples of how to use the library.

http://www.arduino.cc/playground/Learning/OneWire
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

I have a project that is way beyond my capabilites (because they are non-exisitant at this point) using the Adruino with a C#
I'm trying to do something similar to this

http://pscmpf.blogspot.com/2008/12/arduino-lm35-sensor.html

but, using 2 to 4 DS18B20s and C# instead of processing.

I got the Arduino talking to C# via serial but I have no idea how to format the data into something usable.

Thanks for any help.

-Wes
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

has anyone run into a problem using both the DS1307 (sparkfun rtc module) with the DS18B20 temp sensor?  Im prototyping a data logger that writes temp, light, wind speed and voltage values to an sd card running on an atmega 168.  Seems to be some interference between the wire.h and the OneWire.h libraries since I can get either to work without the other.  Is it an I2C communication problem and/or ram?  
I am using the ds18b30 code from the playground with modifications and the ds1307 from: www.glacialwanderer.com/hobbyrobotics.

at the moment the temp is reading and only part of the time/date working, but after much trial and error.

any suggestions would be super helpful.
thanks in advance!
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

first thank you guys for the above info. what really helped me was tkbyd's first link: http://www.phanderson.com/arduino/ds18b20_1.html. its much simpler IMO than the OneWire library, however its made to talk to only one sensor per input pin... but thats cool with me.

the only thing i'm wondering about (in hope to speed up the sensor read time) is why the DS18B20 has to wait a full second when pulling the bus high after the 0x44 command and then why you need to do a reset followed by a 0xCC BEFORE you send the read command 0xBE. can anyone explain this?
Logged

Van Alstyne, TX
Offline Offline
Full Member
***
Karma: 1
Posts: 154
Haven't smoked an Arduino... yet.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
the only thing i'm wondering about (in hope to speed up the sensor read time) is why the DS18B20 has to wait a full second when pulling the bus high after the 0x44 command and then why you need to do a reset followed by a 0xCC BEFORE you send the read command 0xBE. can anyone explain this?
Actually, you only need to wait a maximum of 750-milliseconds for
the 18B20 to perform the digitization of the current temperature.
This is the maximum time needed for all 12-bits of precision *BUT*
if you can get by with 9-bit precision (+/- 0.5 degree C and I don't
see why you couldn't) then the wait is at most 93.75-milliseconds.
These numbers come from the 18B20 spec sheet.  Keep in mind
that you need to tell the 18B20 that you want only 9-bits of precision
by appropriately setting its configuration register in the scratchpad.

Why do you need to issue a 0xCC after the reset but before the 0xBE?
After a 1-wire bus reset all attached devices are listening to hear which
one gets selected with a SELECT command (0x55).  This presumes
multilple devices on the bus and will determine which of the devices on
the bus the ReadScratchPad command (0xBE) will apply to so you can
read the temperature.  Since you've only got one sensor on each pin you
don't need to select which sensor to read so the SkipROM command
(0xCC) is issued to tell the lone sensor that the next set of commands
are for you.  If you don't do this your 18B20 will merrily sit there waiting
to be selected.

How's that?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've tested the sample code of converting HEX to Temperature
http://www.arduino.cc/playground/Learning/OneWire

and found a slip of the pen
Code:
LowByte = data[0];
  HighByte = data[1];
should be
Code:
LowByte = data[0];
  HighByte = present;

otherwise got a wrong temperature like the following
Quote
R=28 90 9 60 0 0 0 CC P=1 CD 1 4B 46 7F FF 3 10 4A  CRC=4A
28.81
R=28 CC FA 5F 0 0 0 A5 P=1 D3 1 4B 46 7F FF D 10 7B  CRC=7B
29.18
R=28 2 ED 5F 0 0 0 4 P=1 E5 5 FF FF 7F FF B 10 2D  CRC=2D
94.31
No more addresses.
0x01E5=30.31/6.25    0x05E5=94.31/6.25
« Last Edit: July 14, 2010, 08:43:45 am by quinezhu » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

After reading through the whole datasheet, I found the 3rd DS18B20 of mine is wrong and the sample code is right actually. :'(
« Last Edit: October 06, 2010, 10:45:19 am by quinezhu » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, I'm new to arduino,  in fact I only got mine today! smiley-grin

I finally got the temperature probe running nicely using snipets of code smiley

I'd thought I would share it:

Code:
#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("\n");
      ds.reset_search();
      return;
  }

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

  if ( addr[0] != 0x28) {
      Serial.print("Device is not a DS18S20 family device.\n");
      return;
  }

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

  delay(2000);     // 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


  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();

  }
  
  int rawtemp = (data[1] << 8) + data[0];
  
double tempc, tempk;
tempc = (double)rawtemp / 16;
tempc = tempc;
tempk = (double)rawtemp / 16 + 273.15;
tempk = tempk;
   Serial.print("Temperature = ");
   Serial.print(tempc,4);
   Serial.println(" 'C");
   Serial.print("Temperature = ");
   Serial.print(tempk,4);
   Serial.println(" K");

}

How would it be possible to turn on a set of led's (red, yellow and green) based on the temperature?
For instance about 20'c green, between 19 and 5 yellow and below 5 red?

Thanks in advance,
Ollie
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Forgot to paste the other code, use this for fahrenheit:
Code:
double tempc, tempk, tempf;
tempc = (double)rawtemp / 16;
tempc = tempc;
tempf = (1.8*(tempc)+32);
tempf = tempf;
tempk = (double)rawtemp / 16 + 273.15;
tempk = tempk;
   Serial.print("Temperature = ");
   Serial.print(tempc,4);
   Serial.println(" 'C");
   Serial.print("Temperature = ");
   Serial.print(tempf,4);
   Serial.println(" 'F");
   Serial.print("Temperature = ");
   Serial.print(tempk,4);
   Serial.println(" K");

Ollie
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
How would it be possible to turn on a set of led's (red, yellow and green) based on the temperature?
For instance about 20'c green, between 19 and 5 yellow and below 5 red?
Code:
if(tempX > 20)
{
   digitalWrite(greenPin, HIGH);
   digitalWrite(yellowPin, LOW);
   digitalWrite(redPin, LOW);
}
else if(tempX > 5)
{
   // Turn the yellow light on
}
else
{
  // Man, it's cold out here
}
You need to assign appropriate values to greepPin, yellowPin, and redPin, of course. You need to decide whether tempX is tempk, tempf, or tempc, too.

And, of course, you need to choose and connect the LEDs and resistors correctly.
Logged

Pages: 1 [2] 3   Go Up
Jump to: