Getting to know Nanode and Winode Hardware

Part 1. Using  the SD Card and RTC to make a 4 channel datalogger.

 

Nanode and Winode are something of a departure from the usual Arduino hardware, and when functioning as a pair, form a unique extension of the Arduino platform to include ethernet and low power wireless connectivity.

Nanode and Winode are both based on the ubiquitous ATmega328 microcontroller, but include the following common functional blocks.

1.  An RFM12B  low power wireless transceiver module.

2. A MCP79410 Real Time Clock. This provides RTC, two alarms, 64 bytes of battery backed RAM and 1kB of EEPROM.

3.  microSD socket – accepts up to 2GB microSD cards for long term datalogging.

4.  32kB battery backed SRAM.  Can be used for downloading sketches or buffering larger quantities of data from the web.

Using freely available libraries it is possible to utilise these hardware blocks, and quickly put together applications on the Nanode or Winode.

The RFM12 is connected to the SPI bus and is selected by Digital 10

The MCP97410 RTC is an I2C device using An4 and An5. It’s multipurpose output connects to Digital 3 – or Interrupt 1

The SD card is also connected to the SPI bus and is selected by Digital 4

The 23K256 SRAM is connected to the SPI bus and is selected by Digital 8 (Winode) and Digital 9 (Nanode).

 

In this post I will look at the operation of the SD card and the Real Time Clock.  The SD card is extremely useful for long term datalogging applications whilst the RTC, as well as providing clock and calendar functions for real time control, also provides two alarms or a square wave output which can be used to wake up the ATmega from sleep at regular intervals.  The RTC also contains 64 bytes of non-volatile SRAM and 1K of EEPROM.

The  SD card Library is included with the Arduino IDE.  For my examples I am using Arduino IDE 1.0.1.   This is an easy to use library, and if you are a newcomer I suggest Jeremy Blum’s excellent video tutorial.  This has 3 examples, how to write to the SD card,  read and write and how to datalog several sensors to the SD card.

For both the Nanode and Winode, the SD card is selected with Digital 4. You will need to modify the code to use the correct chip select line.

The MCP94710 is a powerful little chip – not just a RTC, but includes 2 independent alarms, 64 bytes of battery backed SRAM and 1024 bytes of E2.  If you buy the MCP94712 version, it also includes a uniquely assigned  64 bit MAC address. These devices are available from Farnell for about £1.00. It is connected to the ATmega via the I2C bus, and so needs the Wire library to support its functionality.  It has a multipurpose output which is connected to the Digital 3 (interrupt 1) input of the ATmega.  This can output a squarewave to generate regular interrupts, or be triggered on either of the Alarm conditions. Please refer to the Microchip MCP9471X data sheet for full details of the internal registers.

I decided to write some code to exercise the main features of this RTC and also make use of the microSDcard for datalogging.

Before using these devices we have to include the SD card and Wire (I2C) libraries – so remember to add the #include statements at the top of the code.

#include <SD.h>
#include <Wire.h>
The sketch initialises the RTC and the alarms, and then writes a 64 character text message to the battery backed SRAM.
The main loop then proceeds to log the analogue input from ADC0 to the SDcard every 5 seconds.  The alarm has been configured to trigger every minute, and print out the 64 byte message to the serial terminal window, as well as illuminating the  LED.
The code for this demo is available here on Github Gist.  It compiles to 18054 bytes on the ATmega328.
This second sketch on Github Gist logs the four analogue input readings to the SD card, once per second.  It compiles to 19166 bytes on the ATmega328.  The sketch sends out the current time, the value of the four analogue input channels – and once per minute, acting on an alarm it outputs the message “The Quick Brown Foxy Leapt over the Lazy Dog whilst he snoozed”.
I found it important to declare and reserve space for the various strings:

String dataString = ”      ”;
String stringZero = ”      ”;
String stringOne =  ”       “;
String stringTwo = ”       “;
String stringThree =  ”     “;
String stringId = ”        ”;

And then form individual strings for the analogue readings which are then concatenated together.
int temp_0 = analogRead(0);
int temp_1 = analogRead(1);
int temp_2 = analogRead(2);
int temp_3 = analogRead(3);stringZero = String(temp_0); // Form strings from the individual ADC readings
stringOne = String(temp_1);
stringTwo = String(temp_2);
stringThree = String(temp_3);
stringId = String(id);

//Create Data string for storing to SD card using the CSV Format

dataString = stringId + “, ” + stringZero + “, ” + stringOne + “, ” + stringTwo + “, ” + stringThree; // Concatenate the strings to write to the SD card

An early attempt using a different approach resulted in a memory leak which caused the ’328 to crash after about 5 writes to the SD card:
This code example will be further developed to make a real time logging, 4 channel temperature controller, as part of a central heating controller project.
The next post will combine the SDcard and RTC code example with simple 2-way wireless packet communication – allowing the temperature measurements to be send to a Nanode Gateway or other RF compatible device.

 

 

 

 

 

 

 

 

 

 

 

Comments


Here's your chance to leave a comment!

HTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>