system
March 6, 2010, 1:15pm
1
Hello!
I have some trouble with DS 18S20 sensors and the Arduino -
The Problem:
I have 9 DS18S20 sensors connected to a converter and I use digitemp to read them (No parasite mode because of higher temperatures) - Works absolutly fine. No problems.
I have an arduino with 2 DS1820 on a board (Also No parasite mode, and a 4K7 resistor (+5 - DATA)) - works fine too
When I try to add the 9 sensors to the arduino - it will see none of them not even the 2.
Maybe the resistor is the problem ?
Hope that somebody can help me.
DJ
Seems to me that more people have had this problem in the past
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1266716721/4
It is unresolved there or solution not posted
Found on
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?action=print;num=1161557194
the code used:
/* 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.
}
Please read the whole post,as there are code improvements suggestions
David
system
March 6, 2010, 5:37pm
3
Hi David,
thanks for your help. Indded that semms to be a bigger problem with this 18S20. Nevertheless I´m happy that they wotk fine with the Selfmade-Converter and the digitemp Prg. So I knew tht the things are working well and not dead.
Maybe it could be a solution to have a closer look to this converter and to the digitemp program to find a solution for the arduino too
http://www.digitemp.com/
http://public.rz.fh-wolfenbuettel.de/~hamannm/general/digitempd.html
So it works as long as I use 2 of this with the arduino
Ground ---- Ground
Data ----- Pin 2
VDD ------- +5 V
and also a 4K7 Resistor between Data and +5V
Meanwhile I found this info:
Note on resistors: For larger networks, try something smaller. The ATmega328/168 datasheet indicates starting at 1k6 and a number of users have found smaller to work better on larger networks.
here:
http://www.arduino.cc/playground/Learning/OneWire
which means would be the resistor.
Dirk
Edit: Sun 07.02.2010
I changed the resistor from 4K7 to 1K0 and only one still makes problems (-127 Degrees C) (The sensor is ok - no prob with digitemp). Maybe 1 K are still to much.
system
March 7, 2010, 8:05am
4
Has someone used this with the Arduino and DS18S20 as explained in appendix A ?
http://pdfserv.maxim-ic.com/en/an/AN148.pdf
system
March 8, 2010, 6:21pm
5
And another interesting Advanced 1-Wire Network Driver schematic by Maxim
http://pdfserv.maxim-ic.com/en/an/AN244.pdf
Would be great if someone could add an Arduino and a DS18S20 to this, so that it would be easier to understand this.
http://pdfserv.maxim-ic.com/en/an/AN4206.pdf