Arduino and 1-wire

You can check out the keywords.txt of the existing libraries (in lib/targets/libraries). It looks good, except that OneWire should be in the datatypes section and a KEYWORD1. Now we just need to zip it all and upload it somewhere (the playground?).

You can check out the keywords.txt of the existing libraries (in lib/targets/libraries). It looks good, except that OneWire should be in the datatypes section and a KEYWORD1. Now we just need to zip it all and upload it somewhere (the playground?).

I made this after looking at an example. Only the OneWire wasn't clear to me. I have changed the file, so you can just copy/paste it.

Cool, thanks.

Has anybody gotten this working with the 008 environment? I can make it compile by changing digital_pin_to_port to digital_pin_to_port_PGM and such, but I'm not getting valid readings from the DS18S20P I'm testing it with.

Has anybody gotten this working with the 008 environment?

Jim Studt was kind enough to email me with details of how to get the OneWire library working with arduino-0008. I've posted an updated version of the library to Index of /onewire

Thanks, Jim!

Don't know if you need more code sample for One Wire, but the project OWW is open source and addresses a lot of One Wire devices :
http://oww.sourceforge.net

The OneWire library working fine with Arduino-0009. I'm reading from two DS18S20 using parasite power.

EDIT: nevermind .... figured it out :o

When attempting to compile my program with the onewire library I am getting this error. I have created the library directories and added the keyword file.

o: In function __static_initialization_and_destruction_0(int, int)': undefined reference to OneWire::OneWire(unsigned char)

Anyone know how to fix it?

#include <OneWire.h>

OneWire ds(10); <------------ Commenting out this line makes the program compile

void setup() {

}

But does you program work without "OneWire ds(10)"? I don't think so.

Thank you for the lovely OneWire library, it works well!

The only problem I had with it is that it really eats up SRAM. The CRC tables use about 256 bytes of RAM (from the 1 kbytes the atmega168 has).
On my system I have temporarily commented out that section, but I think a good solution would be to use PROGMEM for the CRC tables. (Some links about PROGMEM:
http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=38003
http://tinker.it/now/2007/03/04/avr-and-of-course-arduino-ram-limits-overcome/
PROGMEM - Arduino Reference )

Has anyone tried the library with the arduino-0010 version yet? When I try to use the 008 version of the OneWire library with it, I get a bunch of errors.

I put the files in hardware/libraries/OneWire and everything worked fine. I am on OS X using arduino-0010 and the 0008 version of the OneWire library.

Dan

PS - Can the OP post the circuit they are testing with?

[...] it really eats up SRAM. The CRC tables use about 256 bytes of RAM (from the 1 kbytes the atmega168 has).
On my system I have temporarily commented out that section, but I think a good solution would be to use PROGMEM for the CRC tables.

A better solution, I think, would be to do the CRC calculation in code, without using the lookup table at all. I spent a couple of hours on that yesterday and worked it out. Just replace the current code for the OneWire::crc8() function with the following,

uint8_t OneWire::crc8 ( uint8_t *addr, uint8_t len )
{
   uint8_t i, j;
   uint8_t crc = 0;

   for (i = 0; i < len; i++) {
       uint8_t inbyte = addr[i];
       for (j = 0; j < 8; j++) {
           uint8_t mix = (crc ^ inbyte) & 0x01;
           crc >>= 1;
           if (mix) crc ^= 0x8C;
           inbyte >>= 1;
       }
   }
   return crc;
}

The OneWire library working fine with Arduino-0009. I'm reading from two DS18S20 using parasite power.

Just to mention that it's working fine with Arduino-0010 as well, using it to read a DS18S20 with parasite power.

does any one know if this works with the DS18B20...

I have it hooked up per everything I have found here, in parasite mode, and all get is this

R=28 92 F1 7D 1 0 0 34 Device is not a DS18S20 family device

any ideas?

Yes I ran into that too, as I reported elsewhere - the family code for the 18B20 is different from that for the 18S20. (There's a note one the Arduino OneWire page that mentions this.) Just replace the family code in the test (0x28) with the one for the 18B20 (0x10). For the record, the DS1822 thermometer has yet another family code (0x22).

Yes I ran into that too, as I reported elsewhere - the family code for the 18B20 is different from that for the 18S20. (There's a note one the Arduino OneWire page that mentions this.) Just replace the family code in the test (0x28) with the one for the 18B20 (0x10). For the record, the DS1822 thermometer has yet another family code (0x22).

Awesome, Thanks, I must have missed the family code changed, I thought I read all the paged, my bad.

edit: Its working now, I am getting hex data out, which is great. I saw this piece of code in the original code snip, I just want to make sure its an accurate conversion of the hex

Serial.print("read scratchpad  ");
  msb = pad[1];
  lsb = pad[0];
  if (msb <= 0x80)lsb = lsb/2;
  msb = msb & 0x80;
  if (msb >=0x80) lsb = (~lsb)+1;
  if (msb >=0x80) lsb = lsb/2;
  if (msb >=0x80) lsb = ((-1)*lsb);
  Serial.print("T =  ");
  Serial.print(lsb);
  Serial.print(" ");

Has anyone had any problems with this library in Arduino-0011?

I am trying to interface to the 1-wire weather station and am just initially trying to access the ds1820 temperature sensor. But when I try the sample code provided with the library it can't seem to find any addresses. If I comment out the search part and enter the address manually it does return a presence pulse but all zeros for the temperature and 0 for the crc

This is exactly what it returns : R=10 A 36 9 0 8 0 C9 P=1 0 0 0 0 0 0 0 0 0 CRC=0

I'm not very good at understanding the code and maybe I've jumped into deep water but the wiring I2C library was so easy, I kind of expected the same here...

Thanks,

venalicio: (Sorry for not responding sooner, but your edit didn't trigger a notification.) The code to read the temperature needs to be slightly different for the DS18B20 (and DS1822), because it returns a 12-bit temperature value (0.0625 deg precision), while the DS18S20 and DS1820 return 9-bit values (0.5 deg precision). Assuming you've gotten the msb and lsb for the temperature, here's how converting to a floating-point temperature value is pretty easy. You should just need the following code:

DS18S20:

int hext = (msb << 8) + lsb;
double tempc = (double)hext * 0.5;

DS18B20

int hext = (msb << 8) + lsb;
double tempc = (double)hext * 0.0625;

These snippets ought to work, but I don't have my Arduino wired up to the temperature sensors at the moment, and so I can't verify it right now.