Go Down

Topic: Arduino and 1-wire (Read 19509 times) previous topic - next topic

cgriffin

Has anyone tried connecting to a dallas 1-wire temperature sensor yet?


looking for tips on it

DS18B20 is the sensor

cgriffin

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

mellis

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.

brainfart

#3
Oct 25, 2006, 08:39 pm Last Edit: Oct 25, 2006, 11:56 pm by brainfart Reason: 1
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&

cgriffin

#4
Oct 28, 2006, 04:56 am Last Edit: Oct 28, 2006, 04:57 am by cgriffin Reason: 1
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.

Ethan


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

yerg2k

(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?

bigengineer

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?

yerg2k

#8
Dec 23, 2006, 01:40 am Last Edit: Dec 23, 2006, 01:44 am by yerg2k Reason: 1
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.
}

bigengineer

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.

yerg2k

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!

bigengineer

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?

yerg2k

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 :-?

jims

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.

yerg2k

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!  :)

Go Up