Currently i'm doing a small project: obtaining temperature and date/time using sensors and DS1307, after that transfer the data to my pc thru ethernet shield every 15 minutes.
When i directly connect RTC and Arduino Duemilanove, date and time displayed correctly but if add ethernet shield, it juz display 165165165... I have searched thru the internet but can't find solution. I tried to bend the A4 and A5 pins of the ethernet shield, it doesn't work too...
Are there compatibility issues between RTC and ethernet shield? Can any experts here to give advice...
Below is my code
- CODE: SELECT_ALL_CODE
#include <Wire.h>
#include "RTClib.h"
#include <OneWire.h>
#include <SPI.h>
#include <Ethernet.h>
RTC_DS1307 RTC;
int DS18S20_Pin = 2; //DS18S20 Signal pin on digital 2
OneWire ds(DS18S20_Pin); // on digital pin 2
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDA, 0x02 };
IPAddress ip(192,168,8,253);
void setup () {
Serial.begin(19200);
Wire.begin();
RTC.begin();
Ethernet.begin(mac,ip);
// initialize the library with the numbers of the interface pins
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
}
void loop () {
float temperature = getTemp();
DateTime now = RTC.now();
Serial.print(now.day(),DEC);
Serial.print(now.month(),DEC);
Serial.print(now.hour(),DEC);
Serial.print(now.minute(),DEC);
Serial.println(temperature);
EthernetClient client = server.available();
client.print(now.day(),DEC);
client.print(now.month(),DEC);
client.print(now.hour(),DEC);
client.print(now.minute(),DEC);
client.println(temperature);
delay(900000);
}
float getTemp(){
//returns the temperature from one DS18S20 in DEG Celsius
byte data[12];
byte addr[8];
if ( !ds.search(addr)) {
//no more sensors on chain, reset search
ds.reset_search();
return -1000;
}
if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return -1000;
}
if ( addr[0] != 0x10 && addr[0] != 0x28) {
Serial.print("Device is not recognized");
return -1000;
}
ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end
byte present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
for (int i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
}
ds.reset_search();
byte MSB = data[1];
byte LSB = data[0];
float tempRead = ((MSB << 8) | LSB); //using two's compliment
float TemperatureSum = tempRead / 16;
return TemperatureSum;
}
Your advises are much appreciated~~!!