Arduino and 1-wire

Wow, jims, very cool!

What would be even cooler is if you or someone else with a working one-wire device packaged the code up as a C++ library (like Wire or SoftwareSerial), with a keywords.txt file and examples. There's some (very sparse) documentation at http://www.arduino.cc/en/Main/Libraries) along with an example library that should be easy to adapt. Any takers?

I have a (simple) working example, that could be added. What is still missing from the library is readout in degrees celsius, I have that too. Also missing is more precise readout. The Application note in which it is explained seems to have disappeared. Except for the keywords.txt I think the library is pretty much done.

It is all jims work, so I guess he will want to pack it up too. Otherwise I will give it a shot. But I need someone to have look at it afterwards.

Oh OK. After I got done putting in all the rubbish to make the C++ and C symbols work together I did feel it would be better as a class. I'm away from that hardware until Tuesday, I'll redo it as C++ then.

Awesome.

Having things like:

OneWire(pin);
OneWire.read();
OneWire.write(value, power)

Would make the code that much easier to use and more consistent with the other libraries.

All packaged in C++ form. Well, not the keywords.txt file. I'm not sure what that is, though I guess it has something to do with the color coding of the build in editor.

http://www.federated.com/~jim/onewire/ contains the library and a sample program. Feel free to vacuum it up into anything you like.

This library is general 1-wire. It might be nice to derive a DS18S20 class from this that knows about temperature to handle the conversions, or that might start making too much object code. Maybe I'm being too sensitive to code bloat, but it seems that higher level libraries will end up containing a lot of unused functions for any given application. e.g. I won't use the alarm threshold registers in my application but I'd end up with functions for them linked into my code. I had enough worry about that in just the generic functions that I ended up with a couple nasty preprocessor symbols to omit some of the larger functions that people might not need.

Very nice. I may try to write up a bit of documentation for it in the playground, unless someone else decides to do it first.

I will make the keywords.txt then. That seems to be the easiest part. :slight_smile:

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 )