Pages: 1 2 3 [4] 5 6   Go Down
Author Topic: Arduino and 1-wire  (Read 14099 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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() {

}
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 183
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 )
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.  
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
« Last Edit: January 17, 2008, 08:44:57 pm by DanMo » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 39
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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;
}
« Last Edit: January 24, 2008, 06:26:11 am by TomP » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
R=28 92 F1 7D 1 0 0 34 Device is not a DS18S20 family device

any ideas?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 39
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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
Code:
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(" ");
« Last Edit: March 25, 2008, 07:50:00 am by venalicio » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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,
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 39
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 << smiley-cool + lsb;
double tempc = (double)hext * 0.5;

DS18B20

int hext = (msb << smiley-cool + 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.  
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 39
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For 18S20:


Code:
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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 39
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
For 18S20:
Code:
 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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 39
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

YES, I did forget to say that !
Logged

Pages: 1 2 3 [4] 5 6   Go Up
Jump to: