Monday, December 12, 2011

RN-XV+SD shield

RN-XV, SD and magnetometer shield
RN-XV+SD shield. Click on the image for an annotated version.

In my quest to make a low-power magnetometer for AuroraWatch UK there are two additional periphals needed: a Wifi connection for real-time data transfer and an SD card for configuration and data logging. I wasn't happy with any of the existing XBee or SD shields. Many of them use resistor-divider networks which prevent dual 3.3V/5V operation (very useful for development), and those which do use logic-level shifters seem to ignore the problem of mixing 3.3V devices with 5V ones.

In response to this need I designed my own shield. I investigated several Wifi modules, but the main contenders were the XBee wifi module and the similar RN-XV module made by Roving Networks. Although I like the idea of the SPI interface that the XBee module offers in the end I chose the RN-XV, partly because it was cheaper but also for its better availability. Both modules use the same pseudo-standard XBee footprint so to some extent either could be used, although the circuitry is designed for the UART interface and GPIOs of the RN-XV. I also included the circuitry for the PNI MicroMag3 module. This is outside the main shield area so as to be located away from the metal casing of the SD card and away from the Wifi module, which could cause interference. To test for temperature effects an LM61 temperature sensor can be used. Unlike the optional one on Calunium this is powered from a logic output for ultra-low power consumption. The shield is designed for Calunium, but will work with full functionality on the Arduino Mega2560. It will also operate on a standard Arduino but flow control and some of the GPIO features of the RN-XV are not available.

Fitting everything onto a 80 × 100mm PCB (the largest size possible in the free version of Cadsoft Eagle) was difficult so I chose to use surface-mount components. The many jumpers are included to make the board as flexible as possible. I sent the Gerber files to Iteadstudio for manufacture. For maximum yield I used very conservative 0.012" trace widths and 0.012" minimum separation, with 0.024" ground-pour isolation. The magnetometer circuitry is easily removed from the schematic and board design if it is not needed; on the manufactured boards the magnetometer section can be removed with a guillotine without affecting the rest of the circuitry. The cut-out is carefully arranged to avoid obstructing the reset button and the USB and JTAG connectors on Calunium.

RN-XV, SD and magnetometer shield on Calunium
RN-XV+SD shield on Calunium.

Eagle PCB design files available under the Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) licence.

Friday, November 11, 2011

Calunium: PCB version

Calunium. Click on the image for an annotated version.

Calunium is an Arduino clone based on the ATmega1284 microcontroller. Initially a strip board design was created to test the concept. Following the success of the strip board version I decided to create a PCB version. Initially I hoped to include Wifi networking, an SD card and a real-time clock. It soon became apparent that including this many peripherals was not possible with the desired footprint using the free version of Cadsoft Eagle. The final version includes a real-time clock. Wifi networking (using the Roving Networks XV Wifi module) and storage using an SD card is provided by a shield designed specifically for Calunium. The RN-XV/SD shield will be described in a future blog post. The pin mapping of the PCB differs slightly from the strip board version; the Arduino software takes care of the differences provided the correct board type is selected.

  • Shield-compatible with Arduino Uno, with extra I/O laid out to be compatible with Arduino Mega pins. Pin mapping is chosen for maximum compatibility with Uno.
  • I2C (SDA/SCL) mapped to standard location as used by Arduino Mega but jumpers can be used to replace A4/A5 with SDA/SCL signals for compatibility with Arduino Uno.
  • Second UART (D1,D2) signals also mapped to corresponding location on Arduino Mega (TX1,RX1).
  • ISP header in standard location, allowing the Arduino ethernet/SD shield to be used.
  • D13 LED connected via FET to avoid loading D13.
  • Direct USB interface using V-USB, for firmware updates without requiring FTDI cable. Can be disabled by removing jumpers. Not yet tested.
  • Real-time clock (DS1307). Output square wave can be routed to D6 (INT2) or D15 (TOSC1, for input to timer/counter 2). Use either CR2032 or CR1220 battery depending upon battery holder fitted.
  • Power from USB or FTDI connector.
  • Switches, jumpers, connectors and USB socket outside of the standard Arduino shield footprint so they do not interfere with shields and are accessible when shields are fitted.
  • Auxiliary power connector; connect your own voltage regulator or boost converter. 5V from USB (FTDI and/or USB connector) and 3V from RTC battery also available on the connector. 3.3V operation is also possible.
  • Auto-reset can be disabled by removing jumper.
  • Pads to fit LM61 temperature sensor.
  • Usable PCB-mounting holes.
  • JTAG header for debugging/programming.
  • Eagle PCB design files available under Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0 licence.
  • Arduino files for Calunium are available on Github.

Sunday, October 23, 2011

Interfacing 3.3V devices to 5V Arduinos

Frequently 3.3V devices need to interface with 5V ones, for instance when connecting an SD card to a 5V Arduino microcontroller board. There are many tutorials about device interfacing which discuss various simple methods of level translation, such as this Sparkfun one. Usually the focus is on protecting the 3.3V inputs from 5V devices but on the SPI bus consideration should be given to protecting the outputs too because there could be 5V devices sharing the SPI interface with 3.3V devices. Unfortunately the simple methods frequently don't account for this possibility. Here is a way to interface 3.3V and 5V logic safely. This approach also the advantage that it can be used to make shields which will work on both 5V Arduinos (e.g. Uno, Mega2560) and 3.3V ones such as the soon-to-be released Arduino DUE. To demonstrate the concept the circuit diagram for an SD card interface is shown below.

SD card interface for 5V microcontroller (PDF).

The 5V signals are safely converted to 3.3V using a 74VLC244 octal buffer powered from 3.3V. I chose this device because the data sheet states its inputs permit 5V logic levels when powered from 3.3V. It is also available in a DIP package which is very convenient for prototyping. The output enable lines of the '244 are permanently grounded (enabled). For SPI slave devices you can share the 3.3V versions of MOSI and SCK control lines with all 3.3V devices. You'll need separate chip select buffers for each device.

The 3.3V logic level output to the microcontroller (MISO) is buffered through one gate of a 74HCT125 quad buffer. The active-low output enable is tied to the chip select line so that when the SD card is not selected the output of the '125 is put into the high-impedance state. This will also occur should the jumper be removed, which is the reason for the pull-up resistor. The 74HCT125 is powered from 5V, so there is no problem when 5V SPI slave devices are also in use.

I used the above circuit to successfully connect an SD card to a 5V Arduino Mega2560. It is also included in a combined Wi-Fly and SD card shield design that is almost ready for manufacture.

Thursday, August 25, 2011

Calunium: Construction

Prepare the strip board
Marking the stripboard
Click on the image for an annotated version.
Mark the locations of the cuts to be made. I found this easiest by printing just the strip board layer from Fritzing onto transparency (use the correct type for your printer). I highlighted the cuts and turned the transparency upside down to give me the view of the copper side of the strip board. I then overlaid the transparency onto the strip board and marked the board. There are 70 cuts to make with a spot-face cutter and 4 with a scalpel. Make sure you cut through all of the track, but avoid damaging the copper of the adjacent tracks. Use a multimeter to check that all of the cuts have been made properly; it is much easier to test and debug an empty board than a populated one. I thought I was careful but found two cuts which had not been made completely.

Add the link wires
Insert the link wires

Begin populating the board with the link wires. Most of the link wires can be safely made with uninsulated wire if you are careful and keep the wire taught and straight. Wires which run closer than 0.1" spacing should be insulated - see the photographs on Flickr. Don't fit any wires to the underside of the board at this time. I colour-coded the wires in the Fritzing layout:

Red+Vcc (digital and analogue)
GreenGround (0V)
BlueMiscellaneous, can be uninsulated
WhiteConnect on underside (or under IC socket if possible)
BrownInsulate due to length

Add the remaining components
Add the remaining components, except for 1N4001 diode, starting with the lowest ones first. Some of the decoupling capacitors are fitted inside the IC socket; keep the leads short so that they do not stop the microprocessor from being inserted. Align the IC socket so that the notch indicates pin 1 end. Ensure that the metal can of the crystal does not touch any of the surrounding wires. Add the ISP header and solder the wires to the underside of the board.

Finally add the headers. Remember that the D8-D13 header is an offset header. I found it easiest to use an ethernet shield to hold the headers at the correct spacing.

Test the board
Before inserting the microprocessor test all of the connections. Then add the FTDI cable/breakout board and power the board from USB. The red LED should light indicating that power is applied. Then check that +5V power is applied to the correct locations of the IC (pins 10 and 30). Check that the GND connections are good (pins 11 and 31). Now add the reverse protection diode; if the polarity of the power supply is reversed the diode will conduct and trip out the polyfuse.

Insert the microprocessor, taking care to get the correct orientation. There's several possible options, see this feature comparison to select the most appropriate one. If you are intending to upload sketches via USB you will need to add a bootloader to the microprocessor. (To be covered in a later post).

Use the blink sketch to test the board. If everything is ok it should just work (it did for me).

Further photos are available on Flickr. The Fritzing files are on GitHub.

Bill of materials
QuantityItemOrder code
1ATmega164P, ATmega324P, ATmega644P or ATmega1284P
1MCP1702 LDO 3V regulator
12N7000 FET
1red LED (3 or 5mm)
1green LED (3 or 5mm)
11N4001 diode
1RXEF025 500mA polyfuseOnecall 1175860
Sparkfun COM-08357
116MHz crystal, 18pF load capacitance, HC49 case
222pF ceramic capacitor
6100nF ceramic capacitor
1100µF electrolytic capacitor, 16V
21kΩ resistor, 0.25W
110kΩ resistor, 0.25W
1SPST switchOnecall 1813689
Sparkfun COM-00097
140 pin 0.6" IC socketOnecall 4285669
Sparkfun PRT-07944
14 pin stackable headerProtopic PP4PSHF
16 pin stackable headerSparkfun PRT-09280
38 pin stackable headerSparkfun PRT-09279
18 pin offset stackable headerSparkfun PRT-09374
23 pin 0.1" header (male)
12×3 pin 0.1" header (male)
1Break-away headers, straightSparkfun PRT-00116
1Break-away headers, longSparkfun PRT-10158
1Break-away headers, right-angleSparkfun PRT-00553
42 pin jumperSparkfun PRT-09044
1stripboard, 38 strips, 30 holes long
wire, 22AWG
Most of the components I bought from Onecall (CPC/Farnell); some I already had. The Sparkfun components I bought from Proto-pic.

Comparison of Calunium with Arduino

Feature comparison
Comparison of the standard Arduino microcontrollers with those which can be used with Calunium.

(8 bit)
ATmega328P322161As used by Uno
ATmega256025684144As used by Mega2560
ATmega164P1610.562Compatible with Calunium
ATmega324P322162Compatible with Calunium
ATmega644644261Compatible with Calunium
ATmega644P644262Compatible with Calunium
ATmega1284P12816482Compatible with Calunium

The ATmega2560 actually has 15 but only 14 are made available on the Arduino Mega2560 headers.

Comparison of PWM output pins

Digital pinArduino UnoArduino Mega2560Calunium
When using ATmega1284P microprocessor.

Tuesday, August 16, 2011

Introducing the Calunium - An Arduino clone based on the ATmega644P/ATmega1284P

Calunium 644P
Calunium built on stripboard. This version uses the ATmega644P, but the ATmega1284P can also be used. Click on the image for an annotated version.

Aims of the project
  • Create an Arduino clone with more than 32K program memory.
  • Produce a design which uses only through-hole components.
  • Shield-compatible - with pin functionality as close as possible to the original Arduino. 

Sanguino and other related designs
How does this differ from the Sanguino and other related designs (Bobuino, Mosquino etc)? The Sanguino can't accept Arduino shields. Although it is possible to program it with the Arduino IDE the pin mapping is functionally very different to the Arduino; for example the first UART is connected to D8-D9, not D0-D1, and the SPI pins are connected to D5-D7, not D11-D13. The Bobuino looks to be a very nice design but I ruled it out as it uses surface mount components, and the ISP header is not in the standard location (as required for the Ethernet shield). The headers on the Mosquino aren't shield compatible.

Sign-Advancetech appear to make a board which appears very close to what I want - I'd probably get one if I could easily buy it in the UK.

Fritzing design files and software

Calunium stripboard design
Click on image for annotated version.

The Fritzing design files can be found on GitHub, Modifications to the Arduino IDE to support Calunium are under development but will be added soon.

Creative Commons Licence
Calunium by Steve Marple is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

About the name
As Arduino is an Italian project, this project takes its name from the Roman name for Lancaster, Calunium, where the design of this clone originates.

Building the Calunium
Future blog posts will show the construction of the Calunium. I also have a design for a shield-compatible strip board Arduino but I haven't had time to put it together yet.

Pin mapping
D23-PD7 (OC2A/PCINT31)

Monday, August 8, 2011

Test magnetometer results

Test magnetometer
Magnetometer electronics in their temporary housing.

On Friday I deployed my magnetometer to the same site used by SAMNET for the Lancaster magnetometer. I knew that several coronal mass ejections (CMEs) were due to impact the Earth's magnetosphere. The predictions were correct, on Saturday AuroraWatch UK issued an amber alert. Below is a comparison of the data from my test magnetometer and the SAMNET magnetometer.

Test magnetometer (top-panel) and the D component from SAMNET's Lancaster magnetometer (bottom panel).
Sensor temperature for the same period.
The results are encouraging even though at present the test magnetometer isn't calibrated, and the orientation is only approximately aligned with the magnetic east component ("D"). The baseline differences can be ignored as SAMNET does not make full-field measurements, just variations from a fixed baseline. I haven't measured it yet but the test sensor has a large temperature coefficient; if the FGM-1 behaves in the same way as the FGM-3 then I expect it to be around 25nT/°C. The graph shows the temperature over the same period varied from 16.5°C to 30°C.

Clearly some kind of temperature stabilisation is going to be needed. One option is to bury the sensor. Another is active temperature control, but care will be needed to ensure that DC currents for the heater do not affect the magnetic field being measured!

Sunday, July 31, 2011

Shield-compatible breadboard Arduino

Breadboard Arduino
Click on the image for an annotated version.

My experience with my Arduino web server has shown that the 32kB program memory of the Uno isn't enough to run a full-featured web server and do other interesting things at the same time. As I'm using an Arduino Mega2560 memory isn't an issue at the moment. Unfortunately taking these ideas beyond the prototype stage means either using one of the surface mount ATmega line or experimenting with the ATmega644P/ATmega1284P, both of which are available in a convenient dual in-line package. Before attempting a shield-compatible Sanguino clone I wanted to be sure I could make a standard Arduino clone based on the ATmega328. This has been done many times before; I found the ITY tutorial helpful (see also the updated version on the Arduino web site). As far as I can find no-one has built a shield-compatible breadboard Arduino before.

Offset headers and the 0.16" spacing problem
For reasons I don't understand the designers of the Arduino chose to space two of the headers by 0.16", which causes problems when using breadboards and stripboard (Veroboard), both of which haves holes at 0.1" spacing. Fortunately 8 pin offset stackable headers can be used to solve this problem.

8 pin offset stackable header
Offset header for use with Arduino shields.

Breadboard layout

Breadboard Arduino
Ethernet shield removed to show the ATmega328 and wiring. Click on the image for an annotated version.

I basically followed the ITY tutorial so I'll just report the differences.

I clipped together two Wisher WBU-TJ breadboards, with the ATmega328P straddling the join. The two parts from the Wisher WBU-DJ breadboard are fitted at the top and bottom to provide power rails. I chose to align A5 with pin 28 on the ATmega328P. That aligns D0 with pin 1 (reset). Since the headers are fitted to a different section of the breadboard that is not a problem.

I chose not to connect AREF, see this warning.

In addition to fitting the AVR programming adapter I also fitted a 2×3 header connected via wires to send the ICSP/SPI signals to the ethernet shield.

I adapted the reset circuitry to allow auto-reset.
Auto-reset circuit.

Breadboard Arduino
Note the offset header used for D8-D13. Click on the image for an annotated version.

Parts list
  • Breadboard (e.g. 1 × Wisher WBU-DJ, 2 × Wisher WBU-TJ)
  • 1 × ATmega328P microprocessor
  • 1 × red LED
  • 1 × 16MHz crystal, 18pF load capacitance
  • 1 × 1kΩ resistor
  • 1 × 220Ω resistor
  • 1 × 10kΩ resistor
  • 2 × 22pF capacitors
  • 3 × 100nF capacitors
  • 1 × 100µF capacitor
  • 1 × FTDI breakout board (Sparkfun DEV-09716)
  • 1 × AVR programming adapter (Sparkfun BOB-08508)
  • 1 × ICSP lead (2×3 pins), else use 6 wires
  • 4 × 6 pin stackable headers (Sparkfun PRT-09280)
  • 3 × 8 pin stackable headers (Sparkfun PRT-09279)
  • 1 × 8 pin offset stackable headers (Sparkfun PRT-09374)
  • 1 × reset switch
  • 22 AWG wire
The next step
The next step is to try this with the ATmega644P before moving the circuit to stripboard.

Wednesday, July 13, 2011

Web server for Arduino

For my magnetometer project I've been using the Arduino micro-controller system to measure and log the magnetic field strength. For real-time data the Arduino sends a UDP packet to a remote server, using the ethernet shield. The shield also contains a microSD slot, allowing data to be logged in case of network outage. What I really want to do is fetch the archived data from the microSD card without disrupting data logging. I could use TFTP but HTTP clients are much more widespread. Using HTTP also gives the potential for a friendly interface to control the magnetometer, not just fetch the data.

There is already the webduino library but it doesn't serve files from the SD card, and it processes the HTTP request as one task. For my purpose I need the HTTP request to be split into many tasks so that web clients cannot disrupt data logging. For this reason I've created my own WwwServer library, which can be found on Github: At a convenient place in loop() make a call to processRequest() so that any pending or ongoing requests can be processed. You must pass a buffer for the web server code to use, but you are free to use the buffer for other purposes before or after the call to processRequest().

If you plan on using the code you'll need a beta of the upcoming 1.0 version of the Arduino IDE (the new-extension branch on Github). This is a big improvement over the 0022 release, DHCP is built into the Ethernet class and the SD library supports multiple open files. The beta release from January 2011 has a bug which breaks DHCP offers containing more than one DNS server. I've made some binaries available of my version at; it includes a fix for the DHCP bug.

How well does it work? Serving a 40KB file from the SD card takes several seconds, so its not very fast. The important thing is that worst case call to processRequest() is completed in under 30ms. That's over 10× faster than the blink of an eye, and fast enough that I only need add a small amount of 'guard time' to ensure that web requests don't affect data logging.

A simple magnetometer for detecting auroral activity

I've been playing with the idea of creating a simple magnetometer which can be used for detecting times when the aurora might be visible. AuroraWatch UK already provides a service for this, with email and Twitter alerts. The AuroraWatch web pages also show how to build a simple pop-bottle magnetometer, and a compass detector, but I wanted something which could easily output digital data. Now I've found a suitable sensor, I've started building a prototype using the open-source Arduino micro-controller platform.The recent Howduino workshop at Lancaster was very helpful in finding (and fixing) a few bugs in the DHCP support.

Arduino with protoyping shield 

A short test at home didn't reveal much, except that cars cause far too much disturbance to the magnetic field. The next test will be at a more remote location but first I need to extend the sensor lead and add some buffering and protection circuitry. It's unlikely I'll have a network connection for time keeping so using NTP won't be possible so I'll probably add a real-time clock.