Skip to content

Code for Arduino Mega to connect the TelosB radio to an Adafruit Data Logger Shield

Notifications You must be signed in to change notification settings

salamandersensors/MegaSerialLogger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MEGASerialLogger Instructions

The code MEGASerialLogger.pde can be compiled and installed in the Arduino programming environment on the Arduino Mega. Instructions online at salamandersensors.org give more details on connecting the Mega to a TelosB radio and the Adafruit logger shield. This README deals with compiling and running the code.

This code is the Adafruit Light and Temperature Logger code, modified to accept serial data, format it and detect the character 7E which denotes the beginning and end of each data packet. There is also a new line RTC.begin() since this seems to work better for whatever reason with our setup. Otherwise the clock wasn't starting.

Also you will need to dowmload RTCLib and sdfatlib from Adafruit, put those folders in your Documents->Arduino -> Libraries folder, and add their . h files to your project. I doubt it is still using WString but it's still in there. 

In the SD2Card.h file found in the SDFat library folder at Adafruit, you have to uncomment the line that says 

#define MEGA_SOFT_SPI 
 
This will let the Mega access the SD card on the SPI pins. Otherwise you will get a "card init" error--and if you run any diagnostics like SDFatInfo you'll get the same results with and without a SD card in the socket. This has nothing to do with formatting the card--it is just that the MEGA is not getting the SPI signal on the right pins, or there's a soldering error that left the pins disconnected.

Now to communicate with the real-time clock on the Logger, you need to use the Mega's hardware SDA and SCL lines but these aren't connected to the right pins on the Logger shield. You have to add a jumper from "SDA" on the Logger Shield to SDA on the Mega. Do the same thing to connect the MEGA SCL and Logger SCL pin.  It's best to install a 2 pin socket on the Logger Shield rather than soldering the jumper wire directly to the logger.  Note that you can't use Mega's pins 4 and 5 for other purposes, because they're already connected to SDA and SCL through the Logger Shield and any additional signals on these pins will mess up communication with the real-time clock.

Hit "verify" which is compile in the Arduino environment. Restart Arduino if it isn't finding your newly added files! The MEGA's multiple hardware serial ports mean you can communicate with your computer on Serial (the common serial port of all Arduinos) at 9600 bps without interfering with the 57600 TelosB signal on Serial 1. You can use Arduino Serial Monitor to watch the bytes coming in from the Telosb.

How to set the clock on the datalogger: uncomment the "RTC.adjust" line in MegaSerialLogger.pde, compile, install and run. The clock will be set at the compile time of the program. Then recomment that line, compile, install and run it as your datalogger program from that point on so it doesn't reset the clock every single time. Must repeat if you ever take out the small battery on the datalogger (don't do this) and want it to report the real time.
The logger should produce data files you can open in Excel ora text editor. They will be called LOGGER00, LOGGER01 etc all the way up to LOGGER99 like the Adafruit example. The first column will contain your TelosB data, the next three are various kinds of timestamps. Use a card reader to read the card; it won't work to plug in the datalogger USB cable to your computer as it does on the Sparkfun Logomatic. Here when your cable is plugged in, the MEGA starts communicating with the Arduino software instead of acting as a card reader.

What are the occasional lines of different length in the TelosB data? The character 7E sometimes shows up as a data byte about 1 in 256 chance, but it's a special character denoting end of line, so when the TelosB encounters this, it puts an escape character in front of the 7E, and changes the 7E to another character. This escape character must also be escaped. It is possible to decode all this in a perl script. The Java application net.tinyos.tools.Listen does this step automatically when reading from the USB serial port.

About

Code for Arduino Mega to connect the TelosB radio to an Adafruit Data Logger Shield

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published