Arduino and 1-wire

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.

For 18S20:

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.

For 18S20:

  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.

YES, I did forget to say that !

Anybody use DS1920 (thermocron)?

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.

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

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.

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.

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.

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.

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.

What happens if you run them with power? and do you have the pullup resistor in your circuit?

[...] and do you have the pullup resistor in your circuit?

Without the pull-up resistor, even one device wouldn't work.

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") 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.

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?

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, which is referenced on the OneWire page in the playground; I would recommend you use that.