Go Down

Topic: DS1820+Ethernet problem (Read 1 time) previous topic - next topic

omnimint

Dec 25, 2010, 03:21 pm Last Edit: Dec 25, 2010, 03:22 pm by omnimint Reason: 1
Hello everybody

I'm starting using Arduino and the first thing that I wanted to test was Dalllas the Ethernet shield:

Code: [Select]
#include <OneWire.h>

// DS18S20 Temperature chip i/o
OneWire ds(10);  // on pin 10

void setup(void) {
 // initialize inputs/outputs
 // start serial port
 Serial.begin(9600);
}

int HighByte, LowByte, TReading, SignBit, Tc_100, Whole, Fract;
char buf[20];

void loop(void) {
 byte i;
 byte present = 0;
 byte data[12];
 byte addr[8];

 if ( !ds.search(addr)) {
   Serial.print("No more addresses.\n");
   ds.reset_search();
   return;
 }

 if ( OneWire::crc8( addr, 7) != addr[7]) {
   Serial.print("CRC is not valid!\n");
   return;
 }

 if ( addr[0] != 0x10) {
   Serial.print("Device is not a DS18S20 family device.\n");
   return;
 }

 ds.reset();
 ds.select(addr);
 ds.write(0x44,1);         // start conversion, with parasite power on at the end

 delay(1000);     // maybe 750ms is enough, maybe not

 present = ds.reset();
 ds.select(addr);    
 ds.write(0xBE);         // Read Scratchpad

 for ( i = 0; i < 9; i++) {           // we need 9 bytes
   data[i] = ds.read();
 }
 
 LowByte = data[0];
 HighByte = data[1];
 TReading = (HighByte << 8) + LowByte;
 SignBit = TReading & 0x8000;  // test most sig bit
 if (SignBit) // negative
 {
   TReading = (TReading ^ 0xffff) + 1; // 2's comp
 }
 Tc_100 = (TReading*100/2);    
 
 Whole = Tc_100 / 100;  // separate off the whole and fractional portions
 Fract = Tc_100 % 100;
 
 sprintf(buf, "%c%d.%d     ",SignBit ? '-' : ' ', Whole, Fract < 10 ? 0 : Fract);
 
 Serial.print( buf );
 Serial.println();
}


The sketch above is working fine. But after adding Ethernet support no temperature shows:
Code: [Select]
#include <OneWire.h>
#include <SPI.h>
#include <Ethernet.h>

OneWire ds(10);  // on pin 10

byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x1A, 0x67 };
byte ip[] = { 192,168,0,10 };

Server server(80);

void setup(void) {
 Ethernet.begin(mac, ip);
 server.begin();
 Serial.begin(9600);
}

int HighByte, LowByte, TReading, SignBit, Tc_100, Whole, Fract;
char buf[20];

void loop(void) {
 byte i;
 byte present = 0;
 byte data[12];
 byte addr[8];
   
 if ( !ds.search(addr)) {
   Serial.print("No more addresses.\n");
   ds.reset_search();
   return;
 }

 if ( OneWire::crc8( addr, 7) != addr[7]) {
   Serial.print("CRC is not valid!\n");
   return;
 }

 if ( addr[0] != 0x10) {
   Serial.print("Device is not a DS18S20 family device.\n");
   return;
 }

 ds.reset();
 ds.select(addr);
 ds.write(0x44,1);         // start conversion, with parasite power on at the end

 delay(1000);     // maybe 750ms is enough, maybe not

 present = ds.reset();
 ds.select(addr);    
 ds.write(0xBE);         // Read Scratchpad

 for ( i = 0; i < 9; i++) {           // we need 9 bytes
   data[i] = ds.read();
 }
 
 LowByte = data[0];
 HighByte = data[1];
 TReading = (HighByte << 8) + LowByte;
 SignBit = TReading & 0x8000;  // test most sig bit
 if (SignBit) // negative
 {
   TReading = (TReading ^ 0xffff) + 1; // 2's comp
 }
 Tc_100 = (TReading*100/2);    
 
 Whole = Tc_100 / 100;  // separate off the whole and fractional portions
 Fract = Tc_100 % 100;
 
 sprintf(buf, "%c%d.%d     ",SignBit ? '-' : ' ', Whole, Fract < 10 ? 0 : Fract);
 
 Serial.print( buf );
 Serial.println();
}


It seems like
Code: [Select]
ds.search(addr)
is unable to find the device because the loop always exites in this condition.


Any help is appreciated, thanks.

PS: using arduino-002 on Windows Vista

PaulS

#1
Dec 25, 2010, 03:26 pm Last Edit: Dec 25, 2010, 03:27 pm by PaulS Reason: 1
Quote
But after adding Ethernet support no temperature shows:

From http://arduino.cc/en/Main/ArduinoEthernetShield
Quote
Arduino communicates with both the W5100 and SD card using the SPI bus (through the ICSP header). This is on digital pins 11, 12, and 13 on the Duemilanove and pins 50, 51, and 52 on the Mega. [glow]On both boards, pin 10 is used to select the W5100[/glow] and pin 4 for the SD card. These pins cannot be used for general i/o.


You have:
Code: [Select]
OneWire ds([glow]10[/glow]);  // on pin 10
Try a different pin.

Quote
PS: using arduino-[glow]002[/glow] on Windows Vista

Two? Man, are you behind the times. ;D

omnimint

[smiley=lolk.gif] can't hide I'm a newbie here. It's working like a charm now, the next thing I'll try to do is some basic ajax stuff, we'll see how it goes...

And the arduino I'm using is 0022 [smiley=embarassed.gif]


Thanks Paul

arduniomstr

Try connecting it up to Pachube http://www.pachube.com/ - it's got a nice api to make life easy

Here's my feed - http://www.pachube.com/feeds/14134

Go Up