I'm using the following to build a temperature logger and, ultimately, controller.
- Adruino UNO and software 1.0.4
- Ethernet Shield with integrated SD card
- Tiny RTC breakout board
- OneWire DS18B20 temperature ICs
- SanDisk 2GB micro SD card
To get everything running, I'm importing the following libraries.
#include <Wire.h>
#include "RTClib.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <Ethernet.h>
#include <Fat16.h>
#include <Fat16util.h>
The Arduino reads the sensors and if the temperature has changed, it logs the time and temperature reading to the 2GB micro SD card.
The good news is that when I monitor everything via the USB serial port "Serial Monitor" everything works as expected. I can see the updates via the serial monitor, the code is successfully logging the information to the SD card, and I can poll the device over the Ethernet and retrieve the current temperatures as JSON.
Sample from data stored on the SD card when everything is working and the Arduino is tethered to my computer via a USB cable
1376477404,2013-8-14 10:50:4,77.90,76.10,75.20
1376484172,2013-8-14 12:42:52,78.80,77.00,77.00
1376484711,2013-8-14 12:51:51,78.80,77.90,77.00
1376485722,2013-8-14 13:8:42,79.70,77.90,77.00
1376489582,2013-8-14 14:13:2,80.60,78.80,78.80
Now, the problem I'm having is that when I disconnect the USB cable from the Arduino, all hell breaks loose. To start with the RTC seems to start returning a spurious result, basically, I get a unix timestamp value of '2212184785' constantly, which isn't even a legal value.
It seems like the Ethernet library, the OneWire/Dallas Tempurature libraries are working, and the SD card library is working, but for some reason the values reported by the RTC are junk.
Here's what on the SD card if I boot the code without being tethered. The Unix Timestamp (first value) and the Date/Time (second value) are completely wrong and do not change from moment to moment.
2212184785,2165-165-165 165:165:85,82.40,80.60,59.90
2212184785,2165-165-165 165:165:85,82.40,80.60,62.60
2212184785,2165-165-165 165:165:85,82.40,80.60,64.40
The JSON from the Ethernet connection also reports this incorrect time, but does export the correct temperature values. And more importantly, shows that the Ethernet Lib continues to work:
{"UTC":"2212184785","tf0":"82.40","tf1":"80.60","tf2":"62.60","avg":"75.20"}
I've tried compiling a version of the code with ALL calls to any Serial or Serial related functions commented out. This yields the same result, basically, the RTC doesn't seem to work. (It works if the USB cable is plugged in even though there's no serial connection. It doesn't work once the USB cable is untethered.)
I've got the RTC break out board plugged into the Analog Pins. A5 = SCL, A4 = SDA, A3 = HIGH = 5v power, A2 = LOW = Ground, A1 = BAT = Unused. See attached image.
Any ideas on why untethering from the USB would cause the TinyRTC breakout board and library to start returning crap values?
My suspicion is that it has something to do with the Wire Library and perhaps some interaction with the Ethernet Shield w/integrated SD card. ???
Attached is my code with all the calls to Serial stripped out.
When running the version ~with~ the Serial calls left in, I have free RAM of 563 bytes. (This is when Arduino is attached via USB to computer and all code is working correctly.)
temp_code_stripped.cpp (7.73 KB)