SD Card Logging with Nuelectronics Real-time Datalog & IO Shield
Created 26th October - by Glyn Hudson
This documentation was compiled as a result 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 was used to log the readings to an SD card. The RTC (Real time clock) on the shield was used to add a time stamp to 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 from the DS18B20 temperature sensors is documented here
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 software section from further 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 RTC (Real-time clock) in the form of a DS1302
timekeeping chip and a 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 looses power.
The DS1302 chip communicates with the Arduino through digital pins 3, 4 and 6.
Figure 2: RTC Schematic from Nuelectronics Data-log Shield Datasheet
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 basically performs a SD card self test. This should pickup any potential SD card incompatibility errors.
I wanted the sensor data to be 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 since the RTC chip used on Ladyada logging shield (DS1307) is different to the RTC chip on the Nuelectronics shield (DS1302).
RTC (Real-time clock)
The Nuelectronics data-logging shield uses the DS1302 RTC chip. Download the library from here
Once the library has been installed open the ‘DS1302_Serial_Easy’ example. The example presumes the chip 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 are used to set the current time and time of 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 needs to be set once. Therefore the lines should be commented out to use the data and time stored in the RTC.
The RTC chip with its coin cell battery backup will keep track of the data 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 (like me!) this time loss can add up to be significant.
Bringing it all Together
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, logging the values every 30 seconds for 6 days to a .csv file on an SD card with a RTC time stamp. See here for more information on the bee hive 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!