Arduino Forum

Forum 2005-2010 (read only) => Software => Interfacing => Topic started by: cgriffin on Oct 23, 2006, 12:46 am

Title: Arduino and 1-wire
Post by: cgriffin on Oct 23, 2006, 12:46 am
Has anyone tried connecting to a dallas 1-wire temperature sensor yet?


looking for tips on it

DS18B20 is the sensor
Title: Re: Arduino and 1-wire
Post by: cgriffin on Oct 24, 2006, 11:13 pm
I have found a site with 1-wire support for the atmega16,   with source

http://gandalf.arubi.uni-kl.de/avr_projects/tempsensor/index.html


Does anyone know how I might integrate this with the arduino IDE

or am I barking up the wrong tree,  

I am pretty good with the hardware but I am fairly poor with the software stuff
Title: Re: Arduino and 1-wire
Post by: mellis on Oct 25, 2006, 04:25 pm
It certainly look like a possibility.  You could try putting onewire.c and onewire.h into the ARDUINO/lib/targets/arduino directory and adding:

#include "onewire.h"

to the top of your sketch.  It's probably not that easy, but that's how I'd start.
Title: Re: Arduino and 1-wire
Post by: brainfart on Oct 25, 2006, 08:39 pm
On this site you can find a nice and fully documented project using 16 1 wire temp sensors with a bunch of Atmegas:

Introduction:
http://66.249.93.104/translate_c?&langpair=de%7Cen&u=http://s-huehn.de/elektronik/tempmess/tempmess.htm

How to connect several 1 wire buses to an Atmega8:
http://66.249.93.104/translate_c?&langpair=de%7Cen&u=http://s-huehn.de/elektronik/tempmess/tempmess-sm.htm

Edit: Google translator is acting up, maybe these links will work?
http://translate.google.com/translate?u=http%3A%2F%2Fs-huehn.de%2Fe+lektronik%2Ftempmess%2Ftempmess.htm+&langpair=de%7Cen&
http://translate.google.com/translate?u=http%3A%2F%2Fs-huehn.de%2Fe+lektronik%2Ftempmess%2Ftempmess.htm+&langpair=de%7Cen&
Title: Re: Arduino and 1-wire
Post by: cgriffin on Oct 28, 2006, 04:56 am
Not alot of help on that one,   the hardware connects are correct but there is not much in software.  I have found WinAVR had built in 1-wire support,   but I dont yet know if its possible to load a WinAVR hex file using the arduino bootloader.   Im gonna have to do a little more research.
Title: Re: Arduino and 1-wire
Post by: Ethan on Oct 28, 2006, 01:12 pm

I've been playing around with those 1-wire sensors as well a few months ago. They're very cool!

Interesting idea to try and hook them up to an Arduino. :)
Title: Re: Arduino and 1-wire
Post by: yerg2k on Dec 20, 2006, 08:10 pm
(BUMP)

I'm new to this whole Arduino thing but it is a great design and tool, and I'm very enthusiastic about what I may be able to do with it.

Recently I received my own Arduino USB development board to play around with, and I also happened to order one of Dallas semiconductor's 1-wire temperature sensors. Painfully going through the datasheet for the DS12S20, I hacked together code to try to interface with this unit. I am not working in parasite power mode.

After getting the timing is right and the subroutines in place in order to read and write to the one wire interface, I was able to come up with a working software. The current version simply sends a request to do a conversion, waits until it is done, and then requests the scratchpad from the unit.

I thought that this would take much longer than a few hours, however at this point I can communicate with the temperature sensor and read back data. At this point, I simply have the nine bytes set back over in their numeric value, via the serial port (USB interface in my case).

Interestingly enough, so far I am able to receive proper data. What is sent back is on par with what the data sheet says should be sent back, including reserved registers and CRC codes, and the data that I received corresponds to what this should be by default. Also, I was able to make the Arduino write to the temperature sensor's storage registers and read the data back properly, so everything is working in that department.

The problem is, when I send a request to do a conversion, that is fine and well, except that the data that is returned for bytes one and two (which should be the temperature reading), always are returned as the default power on value for the DS12S20. For some reason, I cannot get it to convert and return temperature readings.

So, at this point it is only a marginal success in that I can get these sensors to hold two bytes for me, however I cannot get it to do what it was designed to do, and convert temperatures.

If anyone at this point is still trying to interface these or other chips that use the one wire interface, to Arduinos, it is possible with not too much code, however I am stumped at this point as to why the sensor will not initiate a conversion and return sensible data. I've tried hooking up an oscilloscope to the one wire data pin, and the transaction seems to be taking place properly, yet the DS12S20 will not write the finished conversion value to the scratchpad. Perhaps I have a bad sensor, however at this point I only have one so I cannot confirm this to be the problem.

The other thing is that in the data sheet for this temperature sensor, all of their examples heavily rely on the "parasite power mode" and I do not see specific examples of using it with external power. Any suggestions?
Title: Re: Arduino and 1-wire
Post by: bigengineer on Dec 20, 2006, 08:25 pm
I tried to get a DS18S20 working but didn't get any further than the reset. That seemed to work but I never got any data from the sensor. I played around with the timing values but that didn't help me. The delayMicrosecond function seemed to work ok as far as I could measure it with my scope. So I guess filling in the delay's as mentioned in the datasheets should work.

Do you want to share your code? Or at least a read function?
Title: Re: Arduino and 1-wire
Post by: yerg2k on Dec 23, 2006, 01:40 am
http://dmgaming.com/arduino/ds18x20-on-arduino-wiring/

Please let us know if you get it working! Here, or in my comments section.

Edit: My scope doesn't seem to trigger well & sharp unless I do one request at a time in the loop. It appears that the data line goes to around 3v when the conversion starts. I did use the required 4.7k pull-up resistor on the data line. And, I accidentally hooked it up backwards polarity once, oops!

/* DS18S20 Temperature chip i/o
* ---------------
*
* See http://pdfserv.maxim-ic.com/en/ds/DS1820-DS1820S.pdf for the datasheet.
*
* (copyleft) 2006 by Derek Yerger - Free to distribute freely.
*
*
*/
// variable declaration
int onepinio = 7; // i/o
int pres; // just a temporary variable to store return data  

void ds_reset(void) {
 pinMode(onepinio, OUTPUT);  // Pull low for 500mcs
 digitalWrite(onepinio,0);
 delayMicroseconds(500);
 pinMode(onepinio, INPUT);   // Release for at least 500mcs
 pres=0;
 delayMicroseconds(500);
 while (pres = 0) {
   pres=digitalRead(onepinio);
 }
}
void ds_write1(void) {
 pinMode(onepinio, OUTPUT);
 digitalWrite(onepinio,0);
 delayMicroseconds(5);        // A "1" is when the line is pulled
 pinMode(onepinio, INPUT);    //     1mcs < t < 15mcs  
 delayMicroseconds(45);       // so the write slots are even
}

void ds_write0(void) {
 pinMode(onepinio, OUTPUT);
 digitalWrite(onepinio,0);
 delayMicroseconds(20);        // A "0" is when t > 15mcs (30 typical)
 pinMode(onepinio, INPUT);
 delayMicroseconds(30);        // evening up again...
}

int ds_readbit(void) {
 pinMode(onepinio, OUTPUT);
 digitalWrite(onepinio,0);
 delayMicroseconds(1);          // A "read slot" is when 1mcs > t > 2mcs
 pinMode(onepinio, INPUT);
 delayMicroseconds(2);          // Wait just a bit
 return(digitalRead(onepinio)); // return what we see on the line
}

void ds_writebyte(byte dsbyte) {
 byte mask;                            // How heavy is this bit?
 int cwt;
 cwt=0;
 for (mask = 0x01; mask; mask <<= 1) {  // Thanks to mellis - http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1147888882
   if (mask & dsbyte) {                 // Or whoever they got it from...
     ds_write1();
   }
   else {
     ds_write0();
   }
 }
}

int ds_readbyte(void) {
 byte mask;
 int cwt;
 cwt=0;
 for (mask = 0x01; mask; mask <<= 1) {  // Thanks again.
   cwt = cwt + mask * ds_readbit();
 }
 return(cwt);
}

void setup(void) {
 // initialize inputs/outputs
 // start serial port
 pinMode(onepinio,INPUT);
 digitalWrite(onepinio,1);
 Serial.begin(9600);
}

void loop(void) {
 ds_writebyte(0xCC);         // Skip ROM
 ds_writebyte(0x44);         // Supposed to work, but doesn't for me.
 pres=0;
 //pinMode(onepinio, OUTPUT);  // Maybe I was going to try parasite power?
 //digitalWrite(onepinio, 1);
 //delay(100);
 //digitalWrite(onepinio, 0);  // In thst case, be sure to turn it back to 0
 //pinMode(onepinio, INPUT);   // to turn off the internal pull-up resistor.
 while (pres = 0) {          //   The chip's supposed to return a 0 until the
   pres=ds_readbit();        // conversion's done (can't do in parasite mode)
 }
 ds_reset();
 ds_writebyte(0xCC);         // Skip ROM
 ds_writebyte(0xBE);         // Read Scratchpad
 int cby;                    // Call me lazy, or creative: "current byte"
 cby=0;
 while (cby <=8) {           // we need 9 bytes
   Serial.print(ds_readbyte(), HEX);
   Serial.print(" ");
   cby=cby+1;
 }
 Serial.println();
 delay(100);                 // Lets not flood.
}
Title: Re: Arduino and 1-wire
Post by: bigengineer on Dec 23, 2006, 04:27 pm
Well, unfortunately it doesn't work for me either. But, at least I understand why my code didn't work.

I Keep getting the same line:
"AA 0 4B 46 FF FF C 10 87"
The only thing I changed in the code was adding a ds_reset() at the start of the loop(void). But it didn't make any difference. I tried a "read rom", (33h) command. Then the 64bit ROM code is read from the scratchpad. So, that works.
As you stated in the comment after the CONVERT (44h) command this probably doesn't work.
Title: Re: Arduino and 1-wire
Post by: yerg2k on Dec 23, 2006, 06:08 pm
Quote
Well, unfortunately it doesn't work for me either. But, at least I understand why my code didn't work.

I Keep getting the same line:
"AA 0 4B 46 FF FF C 10 87"
The only thing I changed in the code was adding a ds_reset() at the start of the loop(void). But it didn't make any difference. I tried a "read rom", (33h) command. Then the 64bit ROM code is read from the scratchpad. So, that works.
As you stated in the comment after the CONVERT (44h) command this probably doesn't work.


Yes, that's all I get too  :-/
All the digital operations work, but convert doesn't. I haven't had time to, but I'd like to read my ROM code and address the chip specifically when issuing the convert command. The datasheet isn't very clear and straightforward in describing when "Skip ROM" can be used.

Happy Holidays!
Title: Re: Arduino and 1-wire
Post by: bigengineer on Dec 23, 2006, 07:16 pm
Quote
The datasheet isn't very clear and straightforward in describing when "Skip ROM" can be used.


No,  they mention it is possible with only one slave on the bus. See page 9 "SKIP ROM", in the DS1820 datasheet.  (you can follow your own link tot the datasheet)

I searched around on avrfreaks.net to see if there are similar problems. I couldn't find anything useful. I thought I read something about a similar problem.

Would the problem be on timing? How long will the temperature be in the scratchpad? Or would it take more time to finish writing it to the scratchpad than you wait with the while(pres=0) loop?
Title: Re: Arduino and 1-wire
Post by: yerg2k on Dec 24, 2006, 01:04 am
The datasheet says the chip will return "0" if it is requested, until the conversion is done. I think the temperature is stored in the scratchpad and shouldn't have to be read x amount of time after converting. Your guess is as good as mine :-?
Title: Re: Arduino and 1-wire
Post by: jims on Dec 30, 2006, 12:20 am
You almost certainly have a DS18S20P on your hands. This is a variant that only uses parasitic power, the power lead is not connected in the package. You can verify this by using another pin to trigger a scope just before you write the 0x44, you will then see the 8 bits followed by a tragically sagging voltage on the data pin.

I ran out to the FET shop and got a VN2406L (the guy said "everyone buys these", good enough for this) and wired it to another pin like the data sheet shows and everything works now.

The only sad part about this is that now you have to blindly wait 750ms for the temperature to read instead of waiting just long enough.
Title: Re: Arduino and 1-wire
Post by: yerg2k on Dec 30, 2006, 06:51 am
The atmega8 io pins have a maximum rating of 40mA per pin... But I'm not seeing maximum power consumption for the converter while converting in parasite mode. I did see the voltage drop about half after the start conversion command, so it must be trying to do parasite power.

Enabling pull-up on the data line by the microcontroller didn't seem to fix the problem. Also, I didn't spend too much time on the oscilliscope trying to perfect timings in accordance with the microcontroller.

So the fet is required to supply the device, and in that case, I assume a second digital out could be used to control that pull-up. If it could be done with the USB's 500mA, what would be suitable for this application? I need to order a few, there are no FET shops around these parts.

With a 750ms delay on conversions, if you had numerous devices on a line, it wouldn't be a very quick operation, to say the least. When I saw one when ordering my arduino, I thought it might be an interesting thing to use, but thermistors are just so much cheaper!  :)
Title: Re: Arduino and 1-wire
Post by: jims on Dec 31, 2006, 04:27 am
I'm missing something here, looking at the atmel source current spec (~20mA) and the ds18s20p current (~1.5mA) draw during a conversion it should be able to power a dozen temperature sensors on a single pin without a problem. Very odd. It is almost as if the Atmel is using its internal pull up resistor to go high instead of the buffer, but I don't see a combination of settings that would cause that. I'll try a bunch of resistors and make a current/voltage plot when I get back to m analog bench and see what those ports are really doing.
Title: Re: Arduino and 1-wire
Post by: jims on Jan 03, 2007, 12:27 am
Ok, the world has not gone crazy.  The Atmels really do provide >20ma on the pins and the DS18S20P does take about 1ma.  The problem was in the timing. As soon as the DS18S20 receives the 0x44 it will start taking current for the conversion. Unfortunately, the write_byte function is sitting around for many microseconds with the pin in a high impedance state in order to provide timing margins. The DS18S20P crashes before the power gets turned on.

The solution is to not let the external pull-up bring the pin high after the low period of the final bit of the 0x44 is written, force it high with the output driver. Then after the 750ms conversion period passes flip the pin back to an input and let the external pull-up take over.

My little sensor is now happily converting away on my desk.

I'll clean up my changes to the one-wire code and put them up here soon.
Title: Re: Arduino and 1-wire
Post by: bigengineer on Jan 03, 2007, 09:21 am
That's good news jims! How do you connect the DS18S20? I have a resistor between +5V and the data pin. I found this somewhere in the avrfreaks forum.
Title: Re: Arduino and 1-wire
Post by: jims on Jan 03, 2007, 10:52 pm
I have the grounds connected, the DQ pin on the DS18S20P connected to the pin of the Arduino, and a 4.7kohm resistor from DQ to +5v as the pullup. It is good to connect the Vdd pin of the DS18S20P to ground also so if you get a non-parasite version (DS18S20) it will also work in parasite mode.

If you are going to use more than a few of these on the same pin you will need to use a pullup transistor and another pin, as shown in the DS18S20 datasheet, but for a few, say less than 10? of them the Arduino has enough current capacity.
Title: Re: Arduino and 1-wire
Post by: bigengineer on Jan 04, 2007, 05:22 pm
Quote
The solution is to not let the external pull-up bring the pin high after the low period of the final bit of the 0x44 is written, force it high with the output driver. Then after the 750ms conversion period passes flip the pin back to an input and let the external pull-up take over.



Do you use the same pin for this? In yerg2k's code I bring the pin high immediately after the ds_writebyte(0x44) function. But it still  doesn't work. I was wondering if it maybe takes too much time to finish the ds_writebyte() function and that you are doing someting different with an additional pin.


Quote
You almost certainly have a DS18S20P on your hands.

Hmm, overlooked this one but indeed I have the DS18S20P. So far I still couldn't find what I am doing wrong. I am using the 750 uS delay after the 44h write, then pulling the pin high. Why don't I see what's going wrong?
Title: Re: Arduino and 1-wire
Post by: bigengineer on Jan 04, 2007, 07:55 pm
This http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=41771&highlight=ds18s20 thread explains something about connecting the DS18S20. To it seems it is about the powered sensor. Unfortunately, because I have the DS18S20P I can't connect to it like "kartman" explains.

Title: Re: Arduino and 1-wire
Post by: bigengineer on Jan 05, 2007, 05:00 pm
:) YES YES
Finally, it works. I'll do a quick clean up of the code and post it. Though I rewrote almost everything it was a hardware  >:( problem after all. I don't really understand it, maybe someone can explain it to me. There are some other issues that I found out by trial and error. So, I am not there yet, but there is a start to get 1-wire working.
Title: Re: Arduino and 1-wire
Post by: bigengineer on Jan 05, 2007, 05:35 pm
This program is specifically for the DS18S20P. But it is probably easier to get a non P(arasite) version working. To avoid misunderstandings let's start with the DS18S20P  connections.

GND and Vdd to GND, Dq to pin 6 AND  to pin 7 AND via a 4k7 resistor to +5V on arduino board.


Thanks to yerg2k to get me started and jims to get me thinking.
Comments are welcome.

Code: [Select]
/* DS18S20P Temperature chip i/o
* ---------------
*
* See http://pdfserv.maxim-ic.com/en/ds/DS1820-DS1820S.pdf for the datasheet.
*
* (copyleft) 2006 by Derek Yerger - Free to distribute freely.
* (sorry Derek, great inspiration but I rewrote it completely)
*  heavily modified by bigengineer
* inspired by: http://microsyl.com/
* and Dallas 1-wire datasheets
*
*/
#define DQ 7  //data pin
#define PU 6  //separate pin for pull up
#define pin13 13
#define VERSION 01

void setup(void)
{
 // initialize inputs/outputs
 // start serial port
 pinMode(DQ,INPUT);
 pinMode(PU,INPUT);
 pinHigh();
 Serial.begin(9600);
}
byte reset()
{
 pinLow();
 delayMicroseconds(500);
 pinIn();
 delayMicroseconds(70);
 if (digitalRead(DQ) == LOW)
 {
   delayMicroseconds(500);
   return(1);
 }
 return(0);
}
void WriteByte(byte data)
{
 byte i;
 for(i=0;i<=7;i++)
 {
   pinLow();
   if (data & 0x01) //write 1
   {
     delayMicroseconds(7);
     pinIn();
     delayMicroseconds(70);      
   }
   else //write 0
   {
     delayMicroseconds(70);
     pinIn();
     delayMicroseconds(7);
   }
   data>>=1;
 }
}
void convertTemp()
{
 byte i;
 byte data = 0x44;

 for(i=0;i<=7;i++)
 {
   pinLow();
   if (data & 0x01) //write 1
   {
     delayMicroseconds(7);
     pinIn();
     delayMicroseconds(70);      
   }
   else //write 0
   {
     delayMicroseconds(70);
     pinIn();
     delayMicroseconds(7);
   }
   data>>=1;
 }
 pullupHigh(); //pull pin 6 high for the conversion
 delay(750); //conversion time is 750 milliseconds
 pullupIn(); //switch off pin 6
 pinIn();
}
byte readByte()
{
 /* timing is critical here. But timing values are different
  * from the datasheets. These values are found by trial & error.
  * The delay's should be somewhere around 15 uS.
  */
 byte data=0;
 byte i;
 byte bit;
 for(i=0;i<8;i++)
 {
   pinLow();
   delayMicroseconds(1); // > 2 doesn't work
   pinIn();
   delayMicroseconds(1); // >5 doesn't work
   bit = digitalRead(DQ) & 0x01;
   data >>= 1;
   if (bit) data |= 0x80;
   delayMicroseconds(50); //doesn't seem to be necessary
 }
 return(data);
}

void pinHigh()
{
 pinMode(DQ,OUTPUT);
 digitalWrite(DQ,HIGH);
}
void pinLow()
{
 pinMode(DQ,OUTPUT);
 digitalWrite(DQ,LOW);
}
void pinIn()
{
 pinMode(DQ,INPUT);
 //pullupIn(); //om de resistor pull-up te laten werken
}

void pullupHigh()
{
 pinMode(PU,OUTPUT);
 digitalWrite(PU,HIGH);
 digitalWrite(pin13, HIGH);
}
void pullupLow()
{
 pinMode(PU,OUTPUT);
 digitalWrite(PU,LOW);
 digitalWrite(pin13, LOW);
}
void pullupIn()
{
 pinMode(PU,INPUT); //necessary for resistor pull-up
 digitalWrite(pin13, LOW);
}

void readRom()
{
 byte j;
 byte pad[9];

 reset();
 WriteByte(0x33);
 for(j=0;j<8;j++)
 {
   pad[j] = readByte();
 }
 for(j=0;j<8;j++)
 {
   Serial.print(pad[j], HEX);
   Serial.print(" ");
 }
 Serial.println("read rom");
}
void readScratchpad()
{
 byte j;
 byte pad[9];
 int msb,lsb;

 WriteByte(0xBE);
 for(j=0;j<9;j++)
 {
   pad[j] = readByte();
 }
 for(j=0;j<9;j++)
 {
   Serial.print(pad[j], HEX);
   Serial.print(" ");
 }
 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(" ");
   
}
void loop(void)
{
 readRom();
 reset();
 WriteByte(0xCC);
 convertTemp();
 reset();
 WriteByte(0xCC);
 readScratchpad();
 Serial.print("version: ");
 Serial.println(VERSION);
  delay(1000);                 // Lets not flood.
}


[edit]changed typo that cosinekitty discovered[/edit]
Title: Re: Arduino and 1-wire
Post by: CosineKitty on Jan 05, 2007, 09:04 pm
This line of code scares my kitty cat    ;)

Code: [Select]

 if (digitalRead(DQ == LOW))


This compares DQ to LOW (7 == 0), which evaluates to false, or 0, then does a digitalRead of pin 0 and asks whether it returned HIGH or not.

I think you meant:

Code: [Select]

 if (digitalRead(DQ) == LOW)


But hey, maybe it works anyway... ????
Title: Re: Arduino and 1-wire
Post by: jims on Jan 06, 2007, 04:52 am
I've finished. I  packaged the 1-wire functions into a library for Arduino. It includes the read and write byte functions, reset, device enumeration, and CRC computation. The comments about how one might use it are in the library source.  Sadly, it won't fit in a post anymore.

You can pick up the files at http://core.federated.com/~jim/onewire/

Create an arduino-0007/lib/targets/libraries/OneWire/ directory and put them in there. You will probably need to quit the arduino program and restart to get it to notice.  The test.c program doesn't go in the library, it was a little test program you might find useful.

The test is working fine on my unit with 4 DS18S20s connected.

Physically, I have all the DQ lines connected to my IO pin, all the grounds connected to a ground, and 4.7k ohm resistor from a Vcc to the DQ lines. It would be best to connect all the remaining pins of the DS18S20s to either Vcc or GND, then a regular DS18S20 (not a -P) would still work in either normal or parasite mode depending how you connected it.

If you are going to have any kind of wire run I would suggest looking at some of the ESD protection variations (resistor in series with IO pin and 5.5v Zener diode to ground) to keep the stress down when bad things happen.  Likewise, I think it would be possible to make this work using the internal pull-up of the Arduino, but decided that would be a needless stress with there is a short, and the resistor is a bit too big so it would be bad on longer cable runs and possibly not able to supply parasite power.
Title: Re: Arduino and 1-wire
Post by: bigengineer on Jan 06, 2007, 08:46 am
Quote
Physically, I have all the DQ lines connected to my IO pin, all the grounds connected to a ground, and 4.7k ohm resistor from a Vcc to the DQ lines. It would be best to connect all the remaining pins of the DS18S20s to either Vcc or GND, then a regular DS18S20 (not a -P) would still work in either normal or parasite mode depending how you connected it.



Strange, my code started working when I used another pin to supply current to Dq during the temperature conversion.

I am very glad that you have the device enumeration already working, that saves me a lot of time!

I will try it and report back.
Title: Re: Arduino and 1-wire
Post by: bigengineer on Jan 06, 2007, 05:06 pm
Well jims, your code is working! I don't understand why I needed an extra pin to get my code working but your code works with just pin 7 and GND connected.


At the moment I have 3 sensors connected and all 3 give a temperature reading. Your library should become a standard library.
Title: Re: Arduino and 1-wire
Post by: yerg2k on Jan 13, 2007, 10:40 pm
Big thanks to bigengineer and JimS! I'd never have expected it to be that delay right before conversion. Things have been busy here, so I won't get to try this out, but way to go on cracking this one guys!
Title: Re: Arduino and 1-wire
Post by: mellis on Jan 14, 2007, 11:48 am
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?
Title: Re: Arduino and 1-wire
Post by: bigengineer on Jan 14, 2007, 05:23 pm
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.
Title: Re: Arduino and 1-wire
Post by: jims on Jan 14, 2007, 11:01 pm
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.
Title: Re: Arduino and 1-wire
Post by: mellis on Jan 15, 2007, 08:49 am
Awesome.  

Having things like:

Code: [Select]
OneWire(pin);
OneWire.read();
OneWire.write(value, power)


Would make the code that much easier to use and more consistent with the other libraries.
Title: Re: Arduino and 1-wire
Post by: jims on Jan 17, 2007, 03:47 am
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.
Title: Re: Arduino and 1-wire
Post by: mellis on Jan 17, 2007, 09:24 am
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.
Title: Re: Arduino and 1-wire
Post by: bigengineer on Jan 17, 2007, 12:45 pm
I will make the keywords.txt then. That seems to be the easiest part.  :)
Title: Re: Arduino and 1-wire
Post by: yerg2k on Jan 17, 2007, 10:05 pm
I made a rough outline at http://www.arduino.cc/playground/Learning/OneWire

When I get some time later today, I'll go through and edit it up.
Title: Re: Arduino and 1-wire
Post by: bigengineer on Jan 18, 2007, 05:43 pm
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.
Code: [Select]
#######################################
# 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]
Title: Re: Arduino and 1-wire
Post by: mellis on Jan 19, 2007, 09:43 am
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?).
Title: Re: Arduino and 1-wire
Post by: bigengineer on Jan 19, 2007, 03:27 pm
Quote
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.
Title: Re: Arduino and 1-wire
Post by: mellis on Jan 19, 2007, 03:58 pm
Cool, thanks.
Title: Re: Arduino and 1-wire
Post by: RJL20 on Jul 06, 2007, 10:08 pm
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.
Title: Re: Arduino and 1-wire
Post by: RJL20 on Jul 07, 2007, 02:42 am
Quote
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 http://www.elsewhere.org/onewire/

Thanks, Jim!
Title: Re: Arduino and 1-wire
Post by: Ludo on Jul 12, 2007, 02:19 pm
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
Title: Re: Arduino and 1-wire
Post by: Stoner on Sep 05, 2007, 10:20 pm
The OneWire library working fine with Arduino-0009. I'm reading from two DS18S20 using parasite power.
Title: Re: Arduino and 1-wire
Post by: daidalos on Sep 10, 2007, 01:54 am
EDIT:  nevermind .... figured it out  :o


Title: Re: Arduino and 1-wire
Post by: wrastus on Sep 26, 2007, 12:44 am
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() {

}
Title: Re: Arduino and 1-wire
Post by: bigengineer on Sep 26, 2007, 09:36 am
But does you program work without "OneWire ds(10)"? I don't think so.
Title: Re: Arduino and 1-wire
Post by: JohnZero on Oct 24, 2007, 07:14 pm
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/
http://www.arduino.cc/en/Reference/PROGMEM )
Title: Re: Arduino and 1-wire
Post by: vastator on Nov 09, 2007, 04:55 pm
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.  
Title: Re: Arduino and 1-wire
Post by: DanMo on Jan 18, 2008, 02:44 am
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?
Title: Re: Arduino and 1-wire
Post by: TomP on Jan 24, 2008, 12:24 pm
Quote
[...] 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,
Code: [Select]

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;
}
Title: Re: Arduino and 1-wire
Post by: futureshape on Feb 18, 2008, 12:54 pm
Quote
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.
Title: Re: Arduino and 1-wire
Post by: venalicio on Mar 25, 2008, 04:22 am
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
Code: [Select]
R=28 92 F1 7D 1 0 0 34 Device is not a DS18S20 family device

any ideas?
Title: Re: Arduino and 1-wire
Post by: TomP on Mar 25, 2008, 04:51 am
Yes I ran into that too, as I reported elsewhere (http://"http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1199313338") - the family code for the 18B20 is different from that for the 18S20.   (There's a note one the Arduino OneWire (http://"http://www.arduino.cc/playground/Learning/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).
Title: Re: Arduino and 1-wire
Post by: venalicio on Mar 25, 2008, 12:59 pm
Quote
Yes I ran into that too, as I reported elsewhere (http://"http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1199313338") - the family code for the 18B20 is different from that for the 18S20.   (There's a note one the Arduino OneWire (http://"http://www.arduino.cc/playground/Learning/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
Code: [Select]
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(" ");
Title: Re: Arduino and 1-wire
Post by: Inventor on Apr 17, 2008, 11:18 pm
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,
Title: Re: Arduino and 1-wire
Post by: TomP on Apr 18, 2008, 03:55 pm
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.  
Title: Re: Arduino and 1-wire
Post by: JAy1st on Apr 18, 2008, 07:05 pm
For 18S20:


Code: [Select]

void loop()
{
 int LowByte, Whole, Fract, Tc;
 OneWireReset(TEMP_PIN);
 OneWireOutByte(TEMP_PIN, 0xcc);
 OneWireOutByte(TEMP_PIN, 0x44); // perform temperature conversion, strong pullup for one sec
 OneWireReset(TEMP_PIN);
 OneWireOutByte(TEMP_PIN, 0xcc);
 OneWireOutByte(TEMP_PIN, 0xbe);
 LowByte = OneWireInByte(TEMP_PIN);
 Tc=(LowByte*10)/2;               // 18S20 Temp= LSB/2
 Whole=Tc / 10;                  //calcul de l'entier
 Fract=Tc % 10;                  //calcul fraction ".5"
  Serial.print("Temperature :");
 Serial.print(Whole);
 Serial.print(".");
 Serial.println(Fract);
 delay(2000);
}


I only have 18S20 so I know it works and I did spend a couple of hours reading through the datasheet.
Title: Re: Arduino and 1-wire
Post by: TomP on Apr 18, 2008, 10:50 pm
Quote
For 18S20:
Code: [Select]

 Tc=(LowByte*10)/2;               // 18S20 Temp= LSB/2
 Whole=Tc / 10;                  //calcul de l'entier
 Fract=Tc % 10;                  //calcul fraction ".5"
}

I only have 18S20 so I know it works and I did spend a couple of hours reading through the datasheet.


Of course, that code only works for temperatures above freezing.   I'm sure that's fine for your purposes, but anyone who might want to use reuse your code should be aware of this.
Title: Re: Arduino and 1-wire
Post by: JAy1st on Apr 19, 2008, 09:05 am
YES, I did forget to say that !
Title: Re: Arduino and 1-wire
Post by: TavIR-AVR on Apr 21, 2008, 09:51 pm
Anybody use DS1920 (thermocron)?
Title: Re: Arduino and 1-wire
Post by: TomP on Apr 21, 2008, 10:50 pm
Quote
Anybody use DS1920 (thermocron)?

Not me, but the datasheet makes it look like code for the DS1820 or DS18S20 would also work to read temperatures froma DS1920.  It has the same family code (0x10) and returns a 9 bit temperature, like the DS1820.
Title: Re: Arduino and 1-wire
Post by: Franklin on May 12, 2008, 06:12 am
Well, I'm just joining this discussion because I have a new Arduino and have been building a weather station so when I saw Arduino and OneWire in the same post I jumped at the chance. I'm using the 0011 version and put the files in arduino-0011\hardware\libraries\OneWire but I get an error about
OneWire::OneWire(unsigned char)'o: In function `loop':
I'm still going through the messages but if anyone has the fix I would appreciate it.

Thanks, Stephen
Title: Re: Arduino and 1-wire
Post by: TomP on May 20, 2008, 07:02 pm
Quote
I'm using the 0011 version and put the files in arduino-0011\hardware\libraries\OneWire but I get an error about
OneWire::OneWire(unsigned char)'o: In function `loop':
I'm still going through the messages but if anyone has the fix I would appreciate it.


The OneWire library, itself, doesn't have any problems with arduino-0011 that I'm aware of.  If you're still having this problem, I'd be happy to look at it if you post your code here.
Title: Re: Arduino and 1-wire
Post by: Franklin on May 21, 2008, 04:58 am
TomP, I'm trying to compile the sample.c program that comes with the OneWire library. Like I say I'm new to the Arduino and have not programmed in c for several (many?) years. Perhaps I'm just doing it wrong. Thanks for trying to help.
Title: Re: Arduino and 1-wire
Post by: Franklin on May 23, 2008, 05:22 am
OK, told you I was new to all of this.  :o I just noticed that in the files downloaded there is a onewire.h and a onewire.cpp but unlike the other libraries there is no onewire.o file. Do I need to compile the code and what would be the best way to do that?  :-/ Thanks.
Title: Re: Arduino and 1-wire
Post by: Franklin on May 24, 2008, 06:21 am
More info: I've gotten the library to work, I had two problems. First I copied the sample.c file into the directory and I think that was confusing Arduino somehow and there was an extra semicolon in the code ( :-[ ..who put that there?..) I got rid of the fluff and it compiled OK and works. Thanks all for the help and support, I can use all I can get at this stage.
Title: Arduino and 1-wire not working with +16 DS18B20's
Post by: audas on Jun 19, 2008, 09:05 am
Hello everyone,

I am from Irvine,CA. I am working with a network of 1 wire temp sensors. (DS18B20).

have you ever tried using your 1-wire arduino and Jim's updated library for arduino-10 with more than 9 DS18B20's in parasite power mode?

I am using your  example code and the 1-wire library by calling it from the Arduino IDE as someone has posted in the arduino playground.( I have even commented the code)

I am attempting to connect 29 DS18B20's in parasite power mode. So far I have tested those 29 individually with your library and they worked pretty well. I can discover their addresses and ask them for a temperature value.

As long as I connect  8 DS18B20 to the same wire of course, the readings become rubbish. Only two sensors keep giving me their ID and loop forever(CRC's ok). The others sensors seem to be lost or not being able to be discovered ever.

It is not a power issue since I have looked at the signal over the oscilloscope. It is neither a problem of the pull up resistor.

I got 100 DS18B20's from maxim. ALL OF THEM WORK PERFECT INDIVIDUALLY.

The weird behaviors comes into play when I CONNECT MORE THAN 8 sensors. I tried replacing sensors with those hundred I got until I find one that is is able to be read adding an extra sensor to the 8 sensor network. The farthest  I could go was 16 sensors. Leaving 16 sensors cataloged as not being able to participate in a network of more than 8 sensors.

this means that If I have a network of 16 DS18B20's working well (after trying with ~32 different sensors until 16 worked ok together) and I replace one of them with one of the cataloged as "bad"(~15) all the information becomes rubish again.

I am pretty much sure is a software problem( the 1-wire library).

Can you provide any help?

Many thanks,.

Ulises
:-[Irvine, CA.
Title: Re: Arduino and 1-wire
Post by: Franklin on Jun 20, 2008, 03:10 am
What happens if you run them with power? and do you have the pullup resistor in your circuit?
Title: Re: Arduino and 1-wire
Post by: TomP on Jun 20, 2008, 03:34 am
Quote
[...] and do you have the pullup resistor in your circuit?

Without the pull-up resistor, even one device wouldn't work.  
Title: Re: Arduino and 1-wire not working with +16 DS18B2
Post by: TomP on Jun 20, 2008, 05:05 pm
Quote
It is not a power issue since I have looked at the signal over the oscilloscope. It is neither a problem of the pull up resistor. [...] I am pretty much sure is a software problem( the 1-wire library).


I'm not sure how you can conclude that it's not a hardware issue.  You can't just continue to add devices to a 1-wire network and expect them all to perform as if they were the only devices on the bus.  Maxim publishes an application note (AN148 - ""Guidelines for Reliable 1-Wire Networks" (http://www.maxim-ic.com/appnotes.cfm/an_pk/148)) that discusses the issues people encounter when trying to build medium-sized and large 1-wire networks.  It's readable and seems to contain a lot of good advice.  Two things, in particular, that would probably be helpful would be to power the devices directly and to split your network up into two or more separate, smaller 1-Wire busses.

Personally, I don't think there's bug in the OneWire library that could be responsible for your problems.  On the other hand, it may be possible to improve the reliability of your existing circuit by using the library differently.  For example, you can either tell all the devices to start a temperature conversion at once, or you can address them individually and ask them to do their conversions one at a time.  Having them do all their conversions at once is going to draw much more power from the bus, and so I'd avoid doing that.  I guess a similar issue arises with the command to have devices report their addresses, but I'm not sure whether there's an alternative there.  All that said, my feeling is that you will probably need to (at a minimum) split up your network into smaller, separately powered networks if you want to support that many devices.  
Title: Re: Arduino and 1-wire
Post by: kBit on Jul 21, 2008, 02:41 am
I just thought I'd try Jim's OneWire library and got the following errors when the Arduino environment (11) starts up:

OneWire.cpp: In constructor 'OneWire::OneWire(uint8_t)':
OneWire.cpp:74: error: 'digital_pin_to_port' was not declared in this scope
OneWire.cpp:76: error: 'port_to_output' was not declared in this scope
OneWire.cpp:77: error: 'port_to_input' was not declared in this scope
OneWire.cpp:78: error: 'port_to_mode' was not declared in this scope


OneWire.cpp and OneWire.h are in hardware/libraries/OneWire

Any ideas what went wrong?

Title: Re: Arduino and 1-wire
Post by: TomP on Jul 21, 2008, 04:29 am
Quote
I just thought I'd try Jim's OneWire library and got the following errors when the Arduino environment (11) starts up:

I don't think Jim's original library is usable in anything but Arduino-007.  It had to be updated to work with changes in the header files in later Arduino releases, as you can see from your compile errors.  I didn't start working with it until Arduino-010, myself, and have only tried using the most recently updated versions. At this point, the most recent update that I'm aware of is mine (http://homepage.mac.com/wtpollard/Software/FileSharing7.html), which is referenced on the OneWire (http://www.arduino.cc/playground/Learning/OneWire) page in the playground (http://www.arduino.cc/playground/Main/HomePage); I would recommend you use that.
Title: Re: Arduino and 1-wire
Post by: The_Deviant on Nov 12, 2008, 02:38 am
Sorry for the thread ressurection, but I appear to be having a problem similar to the one experienced by audas, except this problem occurs in my setup after a FIFTH DS1820 is added.  I'm using the code on the Learning/OneWire page.

Here is an example of what happens:

Four sensors connected:
R=10 F2 36 55 0 8 0 D0 P=1 31 0 4B 46 FF FF 2 10 72  CRC=72
R=10 8A 14 55 0 8 0 92 P=1 33 0 4B 46 FF FF 3 10 30  CRC=30
R=10 E3 73 55 0 8 0 87 P=1 32 0 4B 46 FF FF E 10 FA  CRC=FA
R=10 EF 4A 55 0 8 0 8D P=1 31 0 4B 46 FF FF 3 10 B6  CRC=B6
No more addresses.

Looks good...  Now, I add a fifth:
R=10 F4 31 55 0 8 0 33 P=1 41 0 4B 46 FF FF 4 10 6D  CRC=6D
R=10 F2 36 55 0 8 0 D0 P=1 31 0 4B 46 FF FF 4 10 D8  CRC=D8
R=10 8A 14 55 0 8 0 92 P=1 34 0 4B 46 FF FF E 10 69  CRC=69
R=10 F2 36 55 0 8 0 D0 P=1 31 0 4B 46 FF FF 4 10 D8  CRC=D8
R=10 8A 14 55 0 8 0 92 P=1 35 0 4B 46 FF FF 3 10 A3  CRC=A3
R=10 F2 36 55 0 8 0 D0 P=1 31 0 4B 46 FF FF 4 10 D8  CRC=D8
R=10 8A 14 55 0 8 0 92 P=1 35 0 4B 46 FF FF 3 10 A3  CRC=A3
R=10 F2 36 55 0 8 0 D0 P=1 31 0 4B 46 FF FF 4 10 D8  CRC=D8
...and on and on and on...

Now, of course, I thought I might have a bad sensor, so I swapped out one sensor each time, while running only four, and it worked every time.  Every time I added a fifth sensor, it would loop.

I'm not running parasite power, and have the 4.7k pull-up (to +5V) resistor on the DQ line, which also goes to the Arduino.  Pin 1 is going to ground, and pin 3 is connected to the same +5v source.

Anyone have any ideas?
Title: Re: Arduino and 1-wire
Post by: don on Nov 12, 2008, 05:25 pm
Hi,

I am inclined to suspect a software bug perhaps in the search function. I have a bunch of sensors on a board for testing and am able to get 5 sensors reading reliably, but when I add 2-3 more sometimes it works and sometimes I get into loop mode where it never gets to the last address.

It doesn't make sense to me that a network would need to be split with just 5 sensors on a board.

- using latest code, parasite power....

any thoughts would be greatly appreciated
Title: Re: Arduino and 1-wire
Post by: GordonEndersby on Nov 12, 2008, 07:40 pm

Can you address more than 5 individually?
In other words not using the search function but send the command to an individual device by its id?

It could be inconvenient to get the id for each device first, depending on how many you are using.
When I got the id's for mine I used the search function in the 1-wire library and touched each in turn to raise the temperature then made a note of the ID. Keep swapping them out till youve done them all. Then I addressed each device directly to get it to send back the temperature.

I was only working with 2 devices but it was more convenient for me to know exactly which device  gave which reading. Im not using the one wire library but a cut down version Ive cobbled together from numerous sources. No search functions. Just the ability to send and receive data on the bus.

If there are limitations in the 1-wire library maybe this would help?

Gordon

Title: Re: Arduino and 1-wire
Post by: don on Nov 14, 2008, 01:59 am
Excellent suggestion! I now have 20 working. So the strategy is:

- test 3-4 at a time
- get their ids
- add ids to an array of known devices

thanks!
Title: Re: Arduino and 1-wire
Post by: ata on Dec 30, 2008, 01:10 pm
hi all,

any ideas about how to connect multiple 1-wire temp sensor DALLAS 18B20 to arduino? (not in parasite mode)......i mean the full code to view the temp of each sensor ..

thanks
Title: Re: Arduino and 1-wire
Post by: cxl2253 on Jan 07, 2009, 09:12 am
hello,all, thanks jim for his onewire library.But i used the arduino 12, i  got the following errors when the Arduino environment (11) starts up:

OneWire.cpp: In constructor 'OneWire:neWire(uint8_t)':
OneWire.cpp:74: error: 'digital_pin_to_port' was not declared in this scope
OneWire.cpp:76: error: 'port_to_output' was not declared in this scope
OneWire.cpp:77: error: 'port_to_input' was not declared in this scope
OneWire.cpp:78: error: 'port_to_mode' was not declared in this scope

so i have to fix it myself for i cannot open the link on background to get the recent files.

in onewire.h i add   #include <pins_arduino.h>
in onewire.cpp
Code: [Select]
OneWire::OneWire( uint8_t pinArg)
{
   pin = pinArg;
   /*
   port = digital_pin_to_port[pin].port;
   bit =  digital_pin_to_port[pin].bit;
   outputReg = port_to_output[port];
   inputReg = port_to_input[port];
   modeReg = port_to_mode[port];
   */
   port = digitalPinToPort(pin);
   bit =  digitalPinToBitMask(pin);
   outputReg = port_to_output_PGM[port];
   inputReg = port_to_input_PGM[port];
   modeReg = port_to_mode_PGM[port];
#if ONEWIRE_SEARCH
   reset_search();
#endif
}


now the error is gone, but i want to know that it is right ? maybe anybody can help me or give me the right link to get recent file.thanks.
Title: Re: Arduino and 1-wire
Post by: agentsmith on Mar 05, 2009, 09:42 pm
Anyone have used DS2406 switch or similar with OneWire library?

Please help, have a look on my post here
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1236262942

Thanks!!
Title: Re: Arduino and 1-wire
Post by: SC on Mar 06, 2010, 08:35 pm
To bring this up again.

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1267881314

Maybe we find a solution some day  :-/