Intro: Build a Datalogger for Your Wireless Sensor Network
We needed a datalogger that provided a timestamp, and that would last 2 weeks in the woods. Using a laptop would require a generator or humongous battery. This Instructable shows how to make a datalogger from an Arduino and datalogger shield connected to a TelosB wireless sensor board and a battery that is large, but not wheelbarrow large. Your data goes onto a SD memory card on the datalogger for pickup later (whenever you have to change the batteries on all the wireless radios in your network, for example). The main challenge is getting the serial signal out of the TelosB before it gets translated into USB. We could probably have reprogrammed the TelosB to output the serial on another pin, but why program when you can solder?
Step 1: Get the Items
Here is the shopping list. It is about $180 for the electronics, $200 for the case and battery. (US) It is cheaper than a netbook and you would have to buy the case, battery and TelosB anyway.
Get a Crossbow TelosB wireless sensor node--or a Moteiv Tmote Sky. MEMSIC now (July 2010) distributes the open-source Crossbow TelosB boards which is good, Crossbow and Moteiv no longer do.
Get a Datalogger Shield (Adafruit) - in the second picture below it's attached to an Arduino but you're just getting the shield. Buy a 1-2 GB SD-card or a micro-SD card with adapter.
Get an Arduino Mega
Get a waterproof case: we used Pelican 1450 and got a small can of silica desiccant to put inside.
Get a large 6-12 Volt battery. A rechargeable sealed lead acid or deep-cycle marine battery is good. Estimate lifetime: the datalogger uses at most 100 mA at 6V. A 50 Ah 6V battery is good but a 50Ah 6V battery is 26 pounds.
part number OPT-850/6, can be used in any orientation and charged with a 6V "Battery Tender"
This battery should last 500 hours (nearly 3 weeks), more if you carefully write your program to turn off all status LEDs and write to the SD card only occasionally. A 12V battery could also be used with the Arduino Mega. What really happens when it starts to go out is your datalogger turns off and on a lot, probably cycling with the outdoor temperature. Hopefully you collected lots of data before then.
We used hose clamps to connect a power jack to the two large battery terminals. The 2.1 mm power jack for the Arduino Mega came from a wall adapter. Center is positive and outside is negative.
You might also add an external antenna on the TelosB for better reception. Compatible parts available at DigiKey are
SMA connector ACX1233-ND, 30cm cable 602-1066-ND, and antenna A24-HASM-450-ND. While at DigiKey pick up 30 gauge wire, sockets, jumper wires, and a power cord with a 2.1mm jack or a cheap AC adapter for harvesting the power jack.
Step 2: Program the TelosB Board
This step can be done at any time, you just need access to the USB port on the TelosB board. However, it's easiest to do it before the board has wires, cables and antennas sticking out of it.
The TelosB board is programmed with software that "bridges" wireless data to a serial connection. This software is called TOSBase. We use it pretty much unmodified, except it is possible to get in there and turn off the blinking light to save power.
The Tinyos.net site can step you through the basics of compiling and loading software onto the TelosB.
Compile and load TOSBase at 57600 bps (the default communication speed). The TOSBase program listens for data from all other nodes in the vicinity, then sends it to the computer via USB. That is what normally happens. This data starts out on a serial line (the TX line) at the TelosB's processor, and that is where we will grab it to send to the datalogger.
Step 3: Add Power Connections to the TelosB and Tap Into the Serial Line
Get ready for modifying one of your boards with the red wire in the picture (or blue wire or whatever 30 gauge wire you have). First, cut off the 2AA battery pack that comes attached to the board. The board is going to instead get power from the datalogger shield, and the battery pack covers up areas you need to modify.
Find the 3V and ground connections on the TelosB and solder a socket to these. The 3V and ground are labeled with pink labels on the modified TelosB (on the right in the second photo). You will later plug in jumper wires here to give the TelosB power from the Adafruit data logger shield.
Look for the Tx line from the MSP430 processor on the TelosB, and use an X-Acto to scrape off the green soldermask and expose some copper. Heat the copper with a soldering iron and melt some solder onto it.
Remove insulation from 1/16" (1.5 mm) of a 4-inch length of 30 gauge wire (wire-wrap wire). Then apply solder to the exposed wire. Remove about 0.5" of insulation from the other end.
Clip the soldered wire to the soldered copper pad using reversing tweezers and heat with the iron. They should melt and stick. The joint isn't very strong, so you can lace the wire through some unused holes on the TelosB to keep it from getting pulled off.
Solder about a 0.5 inch piece of 22-gauge wire to the free end of the 30 gauge wire and secure with heatshrink. This end is going to get plugged into Serial1 RX (pin 19) on the Arduino Mega. Maybe you could use a regular Arduino, but the Mega has 4 hardware serial ports instead of just 1. This makes it easy to use one of the Mega's serial ports for troubleshooting on a computer WHILE the TelosB communicates on another port.
(Besides the Adafruit logger, this method has successfully connected to the Sparkfun Logomatic--low power but no timestamp--and to a RN-41 Bluetooth modem)
Step 4: Optional--add an External Antenna to the TelosB
The TelosB will be able to collect signals using its default printed circuit antenna even inside the closed suitcase, but the range is limited to less than 100 feet, maybe even 30 feet. So you might add an external SMA antenna connector (see shopping list).
To use an external antenna, you have to move a small capacitor on the TelosB board. The second image shows an unmodified board and the third image shows the moved capacitor. It can be done using a regular soldering iron and heating up both sides of the capacitor, then grabbing it with tweezers. It's easier to do using a hot air tool.
Then solder a SMA connector to the five-pin through hole footprint. A 4-inch, 2.4 GHz antenna can be put directly there or connected by a flexible cable.
Step 5: Build the Logger Shield
Follow good instructions at Adafruit here
To get the red and green LEDs to do anything, you need to add jumper wires. However, lights may not be desirable inside the datalogger suitcase where nobody will see them.
Step 6: Wire Up the Arduino MEGA, Logger Shield and TelosB
Add a socket to the 3V pin on the Logger Shield, and a socket to a ground pin. Connect jumpers from here to the 3V and ground pins on the TelosB. The Logger Shield is a good place to get power out to the TelosB because it has a nice onboard 3V regulator.Plug in the TX wire from the TelosB to the Serial1 RX socket on the Mega. This socket is not connected to the DataLogger shield, it's one of the many extra sockets the Mega has that the regular Arduino doesn't.
Now to communicate with the real-time clock on the Logger, you have 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.Now there should be 5 wires going between the TelosB, LoggerShield and Arduino MEGA:3V, 5V, tx/rx, SDA and SCL. That small orange jumper wire is there to connect up the green LED on the datalogger shield, but it's optional and probably would be smarter not to use it.
Step 7: Make It Stronger by Attaching the Boards to Something
Add acrylic pieces with drilled holes, and nylon spacers to make a sturdy assembly. You don't want the wires getting tugged on. Leave access for the USB/power plugs, reset buttons and getting the SD card and antenna out.
When attaching the TelosB to the acrylic, watch out not to short out any parts on the board with the metal screw or nut! There's a resistor that is very close by a hole near the USB port on the TelosB, and if contacted by the screw, it will heat up. A 0-80 screw we used had a small enough top to not do this, but the cap styles vary so watch out.
Another example with the same 1/8 inch acrylic is shown below (red Sparkfun Logomatic board connected to a different TelosB.) The Logomatic's processor and SD card holder are on the same level, so its construction was simpler than the Mega+shield+TelosB.
Step 8: Program the MEGA Logger and Set the Clock
The datalogger is programmed in the Arduino environment, so you need a computer with this software installed.
Download our code MegaSerialLogger at http://github.com/salamandersensors/MegaSerialLogger/archives/master
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 you have to uncomment the line that says
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.
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, compile, install and run. The clock will be set at the compile time of the program. Then recomment, 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.
Step 9: Pack It Up, Run It and Process Data
Foam time--cut out holes in foam for the battery, logger and desiccant if using. Poke a hole in the side of the case for the external antenna (if using) and seal with epoxy. The bendable antennas are cool but some have a piece of exposed metal cable that is probably going to leak water into your case. So get a straight one, a waterproof one or just seal it above the bending part.
Running the logger: there is no on switch, you just plug in the battery to the MEGA's power connector. At each power-on or reset, it will start a log with a new number. It can only hold up to 100 log names so be sure to clean off the memory card periodically. The memory card needs to be installed in a card reader for this, cannot read it through the USB cable.
Your data will be readable in Excel or a text editor (TextEdit, WordPad, etc) and should have a column of bytes along with the three different timestamps (milliseconds since logger started, seconds since 1/1/1970, and a more user friendly date-time format) The bytes contain radio packet information, signal strength info (if made available), the name of the radio sending the data, the serial number of the individual sensor that collected the data, and four bytes of sensor data that can be translated to temperature, voltage, pressure, flow rate, light intensity, etc.
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. So it has put 2 characters in place of 1. 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.