Adafruit Data Logger Shield Created by Bill Earl Last updated on 2015-01-06 08:30:13 AM EST
Guide Contents Guide Contents 2 Overview 4 The new and improved logging shield 4 Features: 4 Installing the Headers 6 Assembly with male headers 6 Cut the headers to length: 7 Position the headers: 8 Position the shield: 8 And solder! 9 Assembly with Stacking Headers: 9 Position the headers: 10 And solder! 11 Shield Overview 12 Using the Real Time Clock 15 What is a Real Time Clock? 15 Talking to the RTC 16 First RTC test 17 Setting the time 19 Reading the time 20 Usi
Build It! 35 Items you'll need: 35 The sensors 36 Wiring it up 38 Position the sensors 38 Prepare some jumpers 38 Install the Jumpers 38 Make the connections 39 Add more jumpers for the Sensors 40 And also for the LEDs 40 Solder and trim all connections 41 Prepare the Battery Pack 43 Use It! 45 Sensor test 45 Logging sketch 47 Plotting with a spreadsheet 47 Using Gnuplot 52 Other plotters 55 Portable logging 55 Fridge logging 56 Conclusion! 58 Code Walkthrough 59
Overview The new and improved logging shield Our latest version of this popular shield has all the features of the popular original, but comes pre-assembled. You can be up and running with it in less than 15 minutes - saving data to files on any FAT16 or FAT32 formatted SD card, to be read by any plotting, spreadsheet or analysis program. This tutorial will also show you how to use two free software programs to plot your data.
Configurable indicator leds Onboard 3.3v regulator is both a reliable reference voltage and also reliably runs SD cards that require a lot of power to run © Adafruit Industries https://learn.adafruit.
Installing the Headers The Adafruit Data Logger shield comes tested assembled with all components and microSD socket already on it, but you'll still need need to put headers on so you can plug it into an Arduino We don't pre-assemble the headers on because there's two options! You can either use plain 0.1" male headers (included with the shield) or Arduino Shield Stacking headers (http://adafru.it/85). Assembly with male headers Most people will be happy with assembling he shield with male headers.
Cut the headers to length: Line the header strip up with the holes on the edge of the shield and cut 4 sections of header strip to fit. © Adafruit Industries https://learn.adafruit.
Position the headers: Insert the header sections - long pins down into the female headers on your Arduino. Position the shield: Align the shield with the header pins and press down. © Adafruit Industries https://learn.adafruit.
And solder! Solder each pin to assure good electrical contact. For tips on soldering, refer to the Adafruit Guide to Excellent Soldering (http://adafru.it/c6b). Assembly with Stacking Headers: Stacking headers give your data logger shield extra flexibility. You can combine it with other shields such as the RGB/LCD Display shield (http://adafru.it/714) to make a compact logging instrument complete with a user interface. You can also stack it with one or more ProtoShields (http://adafru.
Position the headers: Insert the headers fro m the to p of the shield, then flip the shield o ver and place it on a flat surface. Straighten the headers so that they are vertical. Be sure to insert the headers from the TOP of the shield so that they can be soldered from the BOTTOM. © Adafruit Industries https://learn.adafruit.
And solder! Solder each pin for a solid electrical connection. Tip: Solder one pin from each header section. If any of them are crooked, simply re-heat the one solder joint and straighten it by hand. Once all headers are straight, continue soldering the rest of the pins. © Adafruit Industries https://learn.adafruit.
Shield Overview The datalogger shield has a few things to make it an excellent way to track data Top Left - There's a real time clock (RTC) which has a chip, crystal, and backup battery for up to 7 years of timekeeping Middle Left - an on-board 3.3V regulator keeps the shield's 3V parts running smoothly. There's also a green PWR (Power) good LED Top Middle - A big SD card holder can fit any SD/MMC storage up to 32G and and small as 32Meg.
A reset button will reset the entire Arduino, handy for when you want to restart the board Middle - A level shifter keeps the SD card safe from the potentially-damaging 5V signals from the Arduino. It will work with 3V signals as well. We also have some extra breakouts shown above, around the breakout board area 3V - this is the 3V out of the regulator. Its a good quality 3.3V reference which you may want to power sensors. Up to 50mA is available SQ - this is the optional Squarewave output from the RTC.
to use this pad CS - this is the Chip Select pin for the SD card. If you need to cut the trace to pin 10 because it is conflicting, this pad can be soldered to any digital pin and the software re-uploaded L2 and L1 - these are optional user-LEDs. Connect to any digital pin, pull high to turn on the corresponding LED. The LEDs already have 470 ohm resistors in series. © Adafruit Industries https://learn.adafruit.
Using the Real Time Clock What is a Real Time Clock? When logging data, its often really really useful to have timestamps! That way you can take data one minute apart (by checking the clock) or noting at what time of day the data was logged. The Arduino does have a built-in timekeeper called millis() and theres also timers built into the chip that can keep track of longer time periods like minutes or days.
As long as it has a coin cell to run it, the DS1307 will merrily tick along for a long time, even when the Arduino loses power, or is reprogrammed. You MUST have a coin cell installed for the RTC to work, if there is no coin cell, it will act strangly and possibly hang the Arduino so ALWAYS make SURE there's a battery installed, even if its a dead battery. Talking to the RTC The RTC is an i2c device, which means it uses 2 wires to to communicate. These two wires are used to set the time and retreive it.
and then later we'll show how to modify the shield! For the RTC library, we'll be using a fork of JeeLab's excellent RTC library. Please download it now. (http://adafru.it/cfG) Then install it in your Arduino directory (http://adafru.it/aYM) in a folder called RTClib First RTC test The first thing we'll demonstrate is a test sketch that will read the time from the RTC once a second. We'll also show what happens if you remove the battery and replace it since that causes the RTC to halt.
Serial.print(':'); Serial.print(now.minute(), DEC); Serial.print(':'); Serial.print(now.second(), DEC); Serial.println(); Serial.print(" since 1970 = "); Serial.print(now.unixtime()); Serial.print("s = "); Serial.print(now.unixtime() / 86400L); Serial.println("d"); // calculate a date which is 7 days and 30 seconds into the future DateTime future (now.unixtime() + 7 * 86400L + 30); Serial.print(" now + 7d + 30s: "); Serial.print(future.year(), DEC); Serial.print('/'); Serial.print(future.
Whenever the RTC chip loses all power (including the backup battery) it will report the time as 0:0:0 and it won't count seconds (its stopped). Whenever you set the time, this will kickstart the clock ticking. So basically the upshot here is that you should never ever remove the battery once you've set the time.
From now on, you wont have to ever set the time again: the battery will last 5 or more years Reading the time Now that the RTC is merrily ticking away, we'll want to query it for the time. Lets look at the sketch again to see how this is done void loop () { DateTime now = RTC.now(); Serial.print(now.year(), DEC); Serial.print('/'); Serial.print(now.month(), DEC); Serial.print('/'); Serial.print(now.day(), DEC); Serial.print(' '); Serial.print(now.hour(), DEC); Serial.print(':'); Serial.print(now.
There's pretty much only one way to get the time using the RTClib, which is to call no w(), a function that returns a DateTime object that describes the year, month, day, hour, minute and second when you called no w(). There are some RTC libraries that instead have you call something like RTC.year() and RTC.ho ur() to get the current year and hour.
Using the SD Card The other half of the data logger shield is the SD card. The SD card is how we store long term data. While the Arduino chip has a permanent EEPROM storage, its only a couple hundred bytes - tiny compared to a 2 gig SD card. SD cards are so cheap and easy to get, its an obvious choice for long term storage so we use them for the shield. The shield kit doesn't come with an SD card but we carry one in the shop that is guaranteed to work (http://adafru.it/aIH).
Formatting under Windows/Mac If you bought an SD card, chances are it's already pre-formatted with a FAT filesystem. However you may have problems with how the factory formats the card, or if it's an old card it needs to be reformatted. The Arduino SD library we use supports both FAT16 and FAT32 filesystems. If you have a very small SD card, say 8-32 Megabytes you might find it is formatted FAT12 which isnt supported. You'll have to reformat these card.
For Mega and Leonardo Users! If you are using an Leonardo or Mega, you will have to update the SD card library to add 'SD card on any pin' support. To update your library, follow the instructions on this page (http://adafru.it/c75). Next, select the CardInfo example sketch This sketch will not write any data to the card, just tell you if it managed to recognize it, and some information about it. This can be very useful when trying to figure out whether an SD card is supported.
Go to the beginning of the sketch and make sure that the chipSelect line is correct, for the datalogger shield we 're using digital pin 10 so change it to 10! Mega and Leonardo Users! Don't forget to change sd.begin() to specify the pin numbers as below SD.begin(10,11,12,13); OK, now insert the SD card into the Arduino and upload the sketch © Adafruit Industries https://learn.adafruit.
Open up the Serial Monitor and type in a character into the text box (& hit send) when prompted. You'll probably get something like the following: © Adafruit Industries https://learn.adafruit.
Its mostly gibberish, but its useful to see the Vo lume type is FAT16 part as well as the size of the card (about 2 GB which is what it should be) etc. If you have a bad card, which seems to happen more with ripoff version of good brands, you might see: © Adafruit Industries https://learn.adafruit.
The card mostly responded, but the data is all bad. Note that the Pro duct ID is "N/A" and there is no Manufacturer ID or OEM ID. This card returned some SD errors. Its basically a bad scene, I only keep this card around to use as an example of a bad card! If you get something like this (where there is a response but its corrupted) you should toss the card Finally, try taking out the SD card and running the sketch again, you'll get the following, © Adafruit Industries https://learn.adafruit.
It couldn't even initialize the SD card. This can also happen if there's a soldering error or if the card is really damaged If yo u're having SD card pro blems, we suggest using the SD fo rmatter mentio ned abo ve first to make sure the card is clean and ready to use! © Adafruit Industries https://learn.adafruit.
For the Mega and Leonardo If you are using an Leonardo or Mega, you will have to replace the existing SD card library to add 'SD card on any pin' support. If you have an Uno/Duemilanove/Diecimila, this is not required. First, find the "core libraries" folder - if you are using Windows or Linux, it will be in the folder that contains the Arduino executable, look for a libraries folder. Inside you will see an SD folder (inside that will be SD.cpp SD.
Now we'll grab the new SD library, visit https://github.com/adafruit/SD (http://adafru.it/aP6) and click theZIP download button, or click the button below Download the SD Library Zip http://adafru.it/cxl Uncompress and rename the uncompressed folder SD. Check that the SD folder contains SD.cpp and SD.h Place the SD library folder your sketchbook libraries folder. You may need to create the libraries subfolder if its your first library.
// we'll use the initialization code from the utility libraries // since we're just testing if the card is working! while (!card.init(SPI_HALF_SPEED, 10, 11, 12, 13)) { © Adafruit Industries https://learn.adafruit.
Light and Temperature Logger Introduction OK now that we have introduced both the RTC and the SD card and verified that they're working, we can move onto logging! We'll use a pretty good & detailed demonstration to show off the capabilities of this most awesome data logging shield: We'll log both temperature and relative light levels to determine: 1. How much does the temperature in a fridge vary as the compressor turns on and off? 2.
© Adafruit Industries https://learn.adafruit.
Build It! Items you'll need: Arduino (of course!) a Atmega328 type is best (http://adafru.it/aIH) - we always recommend going with an official 'classic' Arduino such as the Uno. Adafruit data logger shield (http://adafru.it/1141) - assembled SD card formatted for FAT (http://adafru.it/aIH) and tested using our example sketch (http://adafru.it/clN) CdS photocell (http://adafru.it/aIH) and a matching 10K pulldown resistor Temperature sensor with analog out, such as TMP36 (http://adafru.
The sensors We'll use two basic sensors to log data, a CdS photocell to track light (http://adafru.it/aIH) (this will tell us when the door has been opened) and a semiconductor temperature sensor to log the ambient fridge temperature. (http://adafru.it/aIH) We have two great tutorials for these sensors on our site, if you haven't used them before or need some refreshment, please read them now (http://adafru.it/c7d)! We will wire the sensors as shown in the diagram below.
© Adafruit Industries https://learn.adafruit.
Wiring it up The prototyping area on the board is a simple array of holes with soldering pads. The steps below show how we built this circuit and illustrate some some basic circuit prototyping techniques. For clarity, we will use the same color wire as shown in the circuit diagram above: Position the sensors The sensors could go anywhere on the prototyping area, but we chose this arrangement to simplify connections between the components later on.
Make the connections Solder the first jumper (red) to the 3v hole. Bend the stripped end of the wire so it rests next to the legs of the light sensor, the temperature sensor and the end of the AREF jumper. Fold the sensor legs and AREF jumper legs over the 3v jumper and solder to make the connection. © Adafruit Industries https://learn.adafruit.
Add more jumpers for the Sensors From Analog Pin 0 to the hole near the light sensor and resistor. (white) From GND to the hole next to the other end of the resistor (black) From the Analog pin 1 to the hole next to the center pin of the temperature sensor (green) And also for the LEDs From L1 to Digital Pin 2 (yellow) From L2 to Digital Pin 3 (yellow) © Adafruit Industries https://learn.adafruit.
Solder and trim all connections Using the same technique of folding the component legs over the jumper - make all connections as shown in the wiring diagram. Make sure that all connections are soldered. Also solder wires and component legs to the board where they pass through the holes. © Adafruit Industries https://learn.adafruit.
© Adafruit Industries https://learn.adafruit.
Prepare the Battery Pack Place the black plastic ferrule from the connector over the battery pack wires. Solder the red wire from the battery pack to the center pin Solder the the black wire to the outer barrel. Crimp to hold the wires securely Screw the black plastic ferrule on to cover the solder joints. Now your Light Temp Logger is wired and ready for testing! © Adafruit Industries https://learn.adafruit.
© Adafruit Industries https://learn.adafruit.
Use It! Sensor test We'll now test the sensors, using this sketch which is a bit of a mashup of the two examples in our tutorials (http://adafru.it/c7d) /* Sensor test sketch for more information see http://www.ladyada.net/make/logshield/lighttemp.html */ #define aref_voltage 3.3 // we tie 3.
} else { Serial.println(" - Very bright"); } tempReading = analogRead(tempPin); Serial.print("Temp reading = "); Serial.print(tempReading); // the raw analog reading // converting that reading to voltage, which is based off the reference voltage float voltage = tempReading * aref_voltage / 1024; // print out the voltage Serial.print(" - "); Serial.print(voltage); Serial.println(" volts"); // now print out the temperature float temperatureC = (voltage - 0.
In my workroom, I got about 24 degrees C and a 'light measurement' of about 400 remember that while the temperature sensor gives an 'absolute' reading in C or F, the light sensor is not precise and can only really give rough readings. Once you've verified that the sensors are wired up correctly & running its time to get to the logging! Logging sketch Download the light and temperature logging sketch from GitHub (http://adafru.it/c7e). Insert the SD card. Upload the sketch to your Arduino.
We'll open the most recent one. If you want to use the same logfile used in the graphing demos, click here to download it (http://adafru.it/cny). The quickest way to look at the data is using something like OpenOffice or Excel, where you can open the .csv file and have it imported directly into the spreadsheet © Adafruit Industries https://learn.adafruit.
You can then perform some graphing by selecting the columns of data Clicking the Chart button and using Lines (we think they are the best for such graphs) © Adafruit Industries https://learn.adafruit.
Setting the First Co lumn as label © Adafruit Industries https://learn.adafruit.
Which will generate this graph You can see pretty clearly how I shaded the sensor and then shone a flashlight on it. You can make the graph display both with different axes (since the change in temperature is a different set of units. Select the temp line (red), right-click and choose Fo rmat Data Series. In the Optio ns tab, Align data series to Seco ndary Y-axis. © Adafruit Industries https://learn.adafruit.
Or you can make another graph with only the temp data Now you can see clearly how I warmed up the sensor by holding it between my fingers Using Gnuplot Gnuplot is an free (but not open source?), ultra-powerful plotting program. Its also a real pain © Adafruit Industries https://learn.adafruit.
to use! But if you can't afford a professional math/plotting package such as Mathematica or Matlab, Gnuplot can do a lot! We're not good enough to provide a full tutorial on gnuplot, here are a few links we found handy. Google will definately help you find even more tutorials and links. Mucking about is the best teacher, too! http://www.cs.hmc.edu/~vrable/gnuplot/using-gnuplot.html (http://adafru.it/c7i) http://www.duke.edu/~hpgavin/gnuplot.html (http://adafru.it/c7k) http://www.ibm.
set y2label "Temperature in Fahrenheit" # set the right Y-axis label set y2tics border # put tics no right side set key box top left set key box linestyle 0 # legend box set xdata time # the x-axis is time set format x "%H:%M:%S" # display as time set timefmt "%s" # but read in as 'unix timestamp' plot "LOGTEST.CSV" using 2:4 with lines title "Light levels" replot "LOGTEST.CSV" using 2:5 axes x1y2 with lines title "Temperature (F)" Which makes this: © Adafruit Industries https://learn.adafruit.
Note the cool double-sided y-axis scales! You can zoom in on stuff pretty easily too. Other plotters Our friend John also suggests Live-Graph as a free plotting program (http://adafru.it/c7o) (http://adafru.it/c7o) - we haven't tried it but its worth looking at if you need to do a lot of plotting! Portable logging Of course, having a datalogger thats chained to a desktop computer isn't that handy. We can make a portable logger with the addition of a battery pack.
Fridge logging With my portable logger ready, its time to do some Fridge Loggin'! Both were placed in the fridge, in the center of the middle shelf. © Adafruit Industries https://learn.adafruit.
I placed it in around 10PM and then removed it around noon the next day. If you don't have a fridge handy, you can grab the data from this zip file and use that (http://adafru.it/cnz). Here is the logged data: You can see in the middle and end the temp and light levels are very high because the logger was outside the fridge. The green line is the temperature so you can see the temperature slowly rising and then the compressor kicking in every half hour or so.
the door is open, even in a few seconds it can climb 4 degrees very quickly! Conclusion! OK that was a detailed project but its a good one to test your datalogging abilities, especially since its harder to fix bugs in the field. In general, we suggest trying other sensors and testing them at home if possible. Its also a good idea to log more data than you need, and use a software program to filter anything you dont need.
Code Walkthrough Introduction This is a walkthrough of the Light and Temperature Logging sketch. Its long and detailed so we put it here for your perusal. We strongly suggest reading through it, the code is very versatile and our text descriptions should make it clear why everything is there! Download the complete file here (http://adafru.it/c7e): Includes and Defines #include "SD.h" #include #include "RTClib.
to kick start the logging. If you have this on you basically can't have it run away from the computer so we'll keep it off (set to 0) for now.
{ Serial.begin(9600); Serial.println(); #if WAIT_TO_START Serial.println("Type any character to start"); while (!Serial.available()); #endif //WAIT_TO_START K now we are onto the code. We begin by initializing the Serial port at 9600 baud. If we set WAIT_TO_START to anything but 0, the Arduino will wait until the user types something in. Otherwise it goes ahead to the next part // initialize the SD card Serial.print("Initializing SD card...
Now the code starts to talk to the SD card, it tries to initialize the card and find a FAT16/FAT32 partition. Next it will try to make a logfile. We do a little tricky thing here, we basically want the files to be called something like LOGGERnn.csv where nn is a number. By starting out trying to create LOGGER00.CSV and incrementing every time when the file already exists, until we get to LOGGER99.
data from the CdS cell and temp is the temperature read. You'll notice that right after each call to lo gfile.print() we have #if ECHO_TO_SERIAL and a matching Serial.print() call followed by a #if ECHO_TO_SERIAL this is that debugging output we mentioned earlier. The lo gfile.print() call is what writes data to our file on the SD card, it works pretty much the same as the Serial version. If you set ECHO_TO_SERIAL to be 0 up top, you won't see the written data printed to the Serial terminal.
Serial.print(", "); #endif // fetch the time now = RTC.now(); // log time logfile.print(now.get()); // seconds since 2000 logfile.print(", "); logfile.print(now.year(), DEC); logfile.print("/"); logfile.print(now.month(), DEC); logfile.print("/"); logfile.print(now.day(), DEC); logfile.print(" "); logfile.print(now.hour(), DEC); logfile.print(":"); logfile.print(now.minute(), DEC); logfile.print(":"); logfile.print(now.second(), DEC); #if ECHO_TO_SERIAL Serial.print(now.get()); // seconds since 2000 Serial.
Then the familiar RTC.no w() call to get a snapshot of the time. Once we have that, we write a timestamp (seconods since 2000) as well as the date in YY/MM/DD HH: MM: SS time format which can easily be recognized by a spreadsheet.
Downloads Download Adafruit SD Library http://adafru.it/cxl If you want to fork or browse the code for the Adafruit SD Library (http://adafru.it/aP6) check the github repository - you should only have to download and replace your SD library if you have a Mega or Leonardo to use with the Datalogging shield (http://adafru.it/c7r) Download Adafruit RTC Library http://adafru.it/cxm If you want to fork or browse code for the Adafruit RTC Library check out the github repository (http://adafru.
Schematic, click to enlarge! © Adafruit Industries https://learn.adafruit.
© Adafruit Industries Last Updated: 2015-01-06 08:30:17 AM EST Page 68 of 68