SD Card Logging with Nuelectronics Real-time Datalog & IO Shield
Created 26th October - by Glyn Hudson
This documentation was compiled as part of a bee hive temperature monitoring project. Multiple DS18B20 temperature sensors were used to sense the temperature at various locations in the hive. An Arduino with a Nuelectronics sensor shield is used to log the readings to an SD card. The shield's RTC (Real time clock) provides time stamps for the readings.
In the future, memory card logging could be integrated into the Open Energy Monitor project to provide local storage or backup for energy monitoring data.
Reading the DS18B20 temperature sensors is documented here.
Hardware
- Nuelectronics Real-time Datalog & IO shield
- Compatible SD card
- Arduino 328
Figure 1: Nuelectronics Real-time Datalog & IO Shield
The Nuelectronics real-time datalogging shield is an ‘all-in-one’ data-logging solution. However I did not find the software to be ‘all-in-one’. I ended up using a FAT file system library which was not designed for this shield. See the software section for details. Since the Nuelectronics shield uses a different chip select line a wire jumper is required between digital pins 10 and 5.
For logged data readings to be useful, they require a time stamp. The Nuelectronics shield has a built in DS1302 timekeeping chip and coin cell battery backup. Once the clock on the chip has been set the chip will keep the correct time, even if the Arduino is reset or loses power.
The DS1302 communicates with the Arduino through digital pins 3, 4 and 6.
Figure 2: RTC Schematic from Nuelectronics Data-log Shield Datasheet
Software
Memory Card
Download the Arduino FAT file system library sdFAT by William Greiman from here. I used version 20100818.
There is an excellent tutorial on SD card logging available on Ladyada’s website here. Although her tutorials are based on her SD logging shield which is slightly different to the Nuelectronics datalog shield. As mentioned earlier, a wire jumper is required between digital pins 10 and 5 to make the Nuelectronics shield work with the sdFAT library.
Once the library has been installed, it’s a good idea to run the ‘SdFATinfo’ example which performs an SD card self test. This should detect any potential SD card incompatibility errors.
I wanted the sensor data saved to the SD card as a .csv file, with a new file created each time the Arduino is powered up. Ladyada has a good example which does just that for a light and temperature logger. Ignore the RTC part of the code, as the RTC on Ladyada's logging shield is a DS1307 but the RTC on the Nuelectronics shield is a DS1302.
RTC (Real-time clock)
The Nuelectronics data-logging shield uses the DS1302 RTC. Download the library from here.
Once the library has been installed, open the ‘DS1302_Serial_Easy’ example. The example presumes the RTC is connected to Arduino pins 2, 3 and 4. These pins must be changed to 6, 4 and 3 respectively if using the Nuelectronics datalog shield. Therefore line 15 of the example should be changed to:
DS1302 rtc(6, 4, 3);
The following lines set the current time and the RTC. They should be changed to the current date and time before upload.
rtc.setDOW(FRIDAY); // Set Day-of-Week to FRIDAY
rtc.setTime(12, 0, 0); // Set the time to 12:00:00 (24hr format)
rtc.setDate(6, 8, 2010); // Set the date to August 6th, 2010
The date and time only need to be set once. Therefore the lines should be commented out to use the date and time stored in the RTC.
The RTC, with its coin cell battery backup, will keep track of the date and time even when the Arduino is powered down. I did notice however that each time new code is uploaded to the Arduino the RTC loses a few seconds. If you make lots of mistakes and have to re-load new code often the time loss can become significant.
Bringing it all Together
Download: SD_Card_Temperature_logger.pde
In this Arduino sketch I have brought together the various components: sensing temperature from four DS18B20 operating in parasite power mode on a single bus and logging the values to a time stamped CSV file on an SD card every 30 seconds for 6 days. Click here for more information on the beehive monitoring project.
Figure 3: Temperature sensor testing data plot
Any thoughts / comments are much appreciated. This is my first Arduino based project, I am aware that my programming skills are still in development!