Arduino and 1-wire

I made a rough outline at Arduino Playground - OneWire

When I get some time later today, I'll go through and edit it up.

So, the easiest jobis done too, although I am not sure if I got it right. I thought I read something about the keywords.txt file, but I can't find it anymore.

#######################################
# Syntax Coloring Map For OneWire
#######################################

#######################################
# Datatypes (KEYWORD1)
#######################################

OneWire    KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
#######################################

reset      KEYWORD2
write_bit      KEYWORD2
read_bit      KEYWORD2
write      KEYWORD2
read      KEYWORD2
select      KEYWORD2
depower      KEYWORD2
reset_search      KEYWORD2
search      KEYWORD2
crc8      KEYWORD2
crc16      KEYWORD2

#######################################
# Instances (KEYWORD2)
#######################################


#######################################
# Constants (LITERAL1)
#######################################

[edit]changed the keywords.txt[/edit]

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(" ");