Tutorial – Arduino and MC14489 LED Display Driver
Learn how to use MC14489 LED display driver ICs with Arduino in chapter fifty-one of a series originally titled “Getting Started/Moving Forward with Arduino!” by John Boxall – A tutorial on the Arduino universe. The first chapter is here, the complete series is detailed here.
Updated 12/05/2013
Introduction
Recently we’ve been looking at alternatives to the MAX7219 LED display driver IC due to pricing and availability issues (stay tuned for that one) – and came across an old but still quite useful IC – the MC14489 from Motorola (now Freescale Semiconductor). The MC14489 can drive five seven-segment LED numbers with decimal point, or a combination of numbers and separate LEDs. You can also daisy-chain more than one to drive more digits, and it’s controlled with a simple serial data-clock method in the same way as a 74HC595 shift register. Sourcing the MC14489 isn’t too difficult – it’s available from element14, Newark, Digikey, and so on – or if you’re not in a hurry, try the usual suspects like Futurlec.
For the purpose of the tutorial we’ll show you how to send commands easily from your Arduino or compatible board to control a five-digit 7-segment LED display module - and the instructions are quite simple so they should translate easily to other platforms. Once you have mastered the single module, using more than one MC14489 will be just as easy. So let’s get started.
Hardware
Before moving forward, download the data sheet (pdf). You will need to refer to this as you build the circuit(s). And here’s our subject in real life:
For our demonstration display we’ll be using a vintage HP 5082-7415 LED display module. However you can use almost any 7-segment modules as long as they’re common-cathode - for example, Sparkfun part number COM-11405. If you’re using a four-digit module and want an extra digit, you can add another single digit display. If you want a ruler, the design files are here.
Connecting the MC14489 to an LED display isn’t complex at all. From the data sheet consider Figure 9 (click the image to enlarge):
Each of the anode control pins from the MC14489 connect to the matching anodes on your display module, and the BANK1~5 pins connect to the matching digit cathode pins on the display module. You can find the MC14489 pin assignments on page 1 of the data sheet. Seeing as this is chapter fifty-one - by now you should be confident with finding such information on the data sheets, so I will be encouraging you to do a little more of the work.
Interesting point – you don’t need current-limiting resistors. However you do need the resistor Rx – this controls the current flow to each LED segment. But which value to use? You need to find out the forward current of your LED display (for example 20 mA) then check Figure 7 on page 7 of the data sheet (click image to enlarge):
To be conservative I’m using a value of 2k0 for Rx, however you can choose your own based on the data sheet for your display and the graph above. Next – connect the data, clock and enable pins of the MC14489 to three Arduino digital pints – for our example we’re using 5, 6 and 7 for data, clock and enable respectively. Then it’s just 5V and GND to Arduino 5V and GND – and put a 0.1uF capacitor between 5V and GND. Before moving on double-check the connections – especially between the MC14489 and the LED display.
Controlling the MC14489
To control the display we need to send data to two registers in the MC14489 – the configuration register (one byte) and the display register (three bytes). See page 9 of the data sheet for the overview. The MC14489 will understand that if we send out one byte of data it is to send it the configuration register, and if it receives three bytes of data to send it to the display register. To keep things simple we’ll only worry about the first bit (C0) in the configuration register – this turns the display outputs on or off. To do this, use the following:
digitalWrite(enable, LOW); shiftOut(data, clock, MSBFIRST, B00000001); // used binary for clarity, however you can use decimal or hexadecimal numbers digitalWrite(enable, HIGH); delay(10);
and to turn it off, send bit C0 as zero. The small delay is necessary after each command.
Once you have turned the display on – the next step is to send three bytes of data which represent the numbers to display and decimal points if necessary. Review the table on page 8 of the data sheet. See how they have the binary nibble values for the digits in the third column. Thankfully the nibble for each digit is the binary value for that digit. Furthermore you might want to set the decimal point – that is set using three bits in the first nibble of the three bytes (go back to page 9 and see the display register). Finally you can halve the brightness by setting the very first bit to zero (or one for full brightness).
As an example for that – if you want to display 5.4321 the three bytes of data to send in binary will be:
1101 0101 0100 0011 0010 0001
Let’s break that down. The first bit is 1 for full brightness, then the next three bits (101) turn on the decimal point for BANK5 (the left-most digit). Then you have five nibbles of data, one for each of the digits from left to right. So there’s binary for 5, then four, then three, then two, then one.
digitalWrite(enable, LOW); shiftOut(data, clock, MSBFIRST, B11010101); // D23~D16 shiftOut(data, clock, MSBFIRST, B01000011); // D15~D8 shiftOut(data, clock, MSBFIRST, B00100001); // D7~D0 digitalWrite(enable, HIGH); delay(10);
To demonstrate everything described so far, it’s been neatly packaged into our first example sketch – Example 51.1:
// Example 51.1 // Motorola MC14489 with HP 5082-7415 5-digit, 7-segment LED display // 2k0 resistor on MC14489 Rx pin // John Boxall 2013 CC by-sa-nc
// define pins for data from Arduino to MC14489 // we treat it just like a 74HC595 int data = 5; int clock = 6; int enable = 7;
void setup()
{
pinMode(data, OUTPUT);
pinMode(enable, OUTPUT);
pinMode(clock, OUTPUT);
displayOn(); // display defaults to off at power-up
}
void displayTest1()
// displays 5.4321
{
digitalWrite(enable, LOW); // send 3 bytes to display register. See data sheet page 9
// you can also insert decimal or hexadecimal numbers in place of the binary numbers
// we're using binary as you can easily match the nibbles (4-bits) against the table
// in data sheet page 8
shiftOut(data, clock, MSBFIRST, B11010101); // D23~D16
shiftOut(data, clock, MSBFIRST, B01000011); // D15~D8
shiftOut(data, clock, MSBFIRST, B00100001); // D7~D0
digitalWrite(enable, HIGH);
delay(10);
}
void displayTest2()
// displays ABCDE
{
digitalWrite(enable, LOW); // send 3 bytes to display register. See data sheet page 9
// you can also insert decimal or hexadecimal numbers in place of the binary numbers
// we're using binary as you can easily match the nibbles (4-bits) against the table
// in data sheet page 8
shiftOut(data, clock, MSBFIRST, B10001010); // D23~D16
shiftOut(data, clock, MSBFIRST, B10111100); // D15~D8
shiftOut(data, clock, MSBFIRST, B11011110); // D7~D0
digitalWrite(enable, HIGH);
delay(10);
}
void displayOn()
// turns on display
{
digitalWrite(enable, LOW);
shiftOut(data, clock, MSBFIRST, B00000001);
digitalWrite(enable, HIGH);
delay(10);
}
void displayOff()
// turns off display
{
digitalWrite(enable, LOW);
shiftOut(data, clock, MSBFIRST, B00000000);
digitalWrite(enable, HIGH);
delay(10);
}
void loop()
{
displayOn();
displayTest1();
delay(1000);
displayTest2();
delay(1000);
displayOff();
delay(500);
}
… with the results in the following video:
Now that we can display numbers and a few letters with binary, life would be easier if there was a way to take a number and just send it to the display.
So consider the following function that takes an integer between 0 and 99999, does the work and sends it to the display:
void displayIntLong(long x)
// takes a long between 0~99999 and sends it to the MC14489
{
int numbers[5];
byte a=0;
byte b=0;
byte c=0; // will hold the three bytes to send to the MC14489
// first split the incoming long into five separate digits
numbers[0] = int ( x / 10000 ); // left-most digit (will be BANK5)
x = x % 10000;
numbers[1] = int ( x / 1000 );
x = x % 1000;
numbers[2] = int ( x / 100 );
x = x % 100;
numbers[3] = int ( x / 10 );
x = x % 10;
numbers[4] = x % 10; // right-most digit (will be BANK1)
// now to create the three bytes to send to the MC14489
// build byte c which holds digits 4 and 5
c = numbers[3];
c = c << 4; // move the nibble to the left
c = c | numbers[4];
// build byte b which holds digits 3 and 4
b = numbers [1];
b = b << 4;
b = b | numbers[2];
// build byte a which holds the brightness bit, decimal points and digit 1
a = B10000000 | numbers[0]; // full brightness, no decimal points
// now send the bytes to the MC14489
digitalWrite(enable, LOW);
shiftOut(data, clock, MSBFIRST, a);
shiftOut(data, clock, MSBFIRST, b);
shiftOut(data, clock, MSBFIRST, c);
digitalWrite(enable, HIGH);
delay(10);
}
So how does that work? First it splits the 5-digit number into separate digits and stores them in the array numbers[]. It then places the fourth digit into a byte, then moves the data four bits to the left – then we bitwise OR the fifth digit into the same byte. This leaves us with a byte of data containing the nibbles for the fourth and fifth digit. The process is repeated for digits 2 and 3. Finally the brightness bit and decimal point bits are assigned to another byte which then has the first digit’s nibble OR’d into it. Which leaves us with bytes a, b and c ready to send to the MC14489. Note that there isn’t any error-checking – however you could add a test to check that the number to be displayed was within the parameter, and if not either switch off the display (see example 51.1) or throw up all the decimal points or … whatever you want.
You can download the demonstration sketch for the function – Example 51.2, and view the results in the following video:
You can also display the letters A to F by sending the values 10 to 15 respectivel to each digit’s nibble. However that would be part of a larger application, which you can (hopefully) by now work out for yourself. Furthermore there’s some other characters that can be displayed – however trying to display the alphabet using 7-segment displays is somewhat passé. Instead, get some 16-segment LED modules or an LCD.
Finally, you can cascade more than one MC14489 to control more digits. Just run a connection from the data out pin on the first MC14889 to the data pin of the second one, and all the clock and enable lines together. Then send out more data – see page 11 of the data sheet. If you’re going to do that in volume other ICs may be a cheaper option and thus lead you back to the MAX7219.
Conclusion
For a chance find the MC14489 is a fun an inexpensive way to drive those LED digit displays. We haven’t covered every single possible option or feature of the part – however you will now have the core knowledge to go further with the MC14489 if you need to move further with it. And if you enjoy my tutorials, or want to introduce someone else to the interesting world of Arduino – check out my new book “Arduino Workshop” from No Starch Press.
In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitter, Google+, subscribe for email updates or RSS using the links on the right-hand column? And join our friendly Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other – and we can all learn something.
Book – “Arduino Workshop – A Hands-On Introduction with 65 Projects”
Over the last few years I’ve been writing a few Arduino tutorials, and during this time many people have mentioned that I should write a book. And now thanks to the team from No Starch Press this recommendation has morphed into my new book – “Arduino Workshop“:
Although there are seemingly endless Arduino tutorials and articles on the Internet, Arduino Workshop offers a nicely edited and curated path for the beginner to learn from and have fun. It’s a hands-on introduction to Arduino with 65 projects – from simple LED use right through to RFID, Internet connection, working with cellular communications, and much more.
Each project is explained in detail, explaining how the hardware an Arduino code works together. The reader doesn’t need any expensive tools or workspaces, and all the parts used are available from almost any electronics retailer. Furthermore all of the projects can be finished without soldering, so it’s safe for readers of all ages.
The editing team and myself have worked hard to make the book perfect for those without any electronics or Arduino experience at all, and it makes a great gift for someone to get them started. After working through the 65 projects the reader will have gained enough knowledge and confidence to create many things – and to continue researching on their own. Or if you’ve been enjoying the results of my thousands of hours of work here at tronixstuff, you can show your appreciation by ordering a copy for yourself or as a gift
You can review the table of contents, index and download a sample chapter from the Arduino Workshop website.
Arduino Workshop is available from No Starch Press in printed or ebook (PDF, Mobi, and ePub) formats. Ebooks are also included with the printed orders so you can get started immediately.
In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitter, Google+, subscribe for email updates or RSS using the links on the right-hand column? And join our friendly Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other – and we can all learn something.
Tutorial – Arduino and ILI9325 colour TFT LCD modules
Learn how to use inexpensive ILI9325 colour TFT LCD modules in chapter fifty of a series originally titled “Getting Started/Moving Forward with Arduino!” by John Boxall – A tutorial on the Arduino universe. The first chapter is here, the complete series is detailed here.
Introduction
Colour TFT LCD modules just keep getting cheaper, so in this tutorial we’ll show you how to get going with some of the most inexpensive modules we could find. The subject of our tutorial is a 2.8″ 240 x 320 TFT module with the ILI9325 LCD controller chip. If you look in ebay this example should appear pretty easily, here’s a photo of the front and back to help identify it:
There is also the line “HY-TFT240_262k HEYAODZ110510″ printed on the back of the module. They should cost less than US$10 plus shipping. Build quality may not be job number one at the factory so order a few, however considering the cost of something similar from other retailers it’s cheap insurance. You’ll also want sixteen male to female jumper wires to connect the module to your Arduino.
Getting started
To make life easier we’ll use an Arduino library “UTFT” written for this and other LCD modules. It has been created by Henning Karlsen and can be downloaded from his website. If you can, send him a donation – this library is well worth it. Once you’ve downloaded and installed the UTFT library, the next step is to wire up the LCD for a test.
Run a jumper from the following LCD module pins to your Arduino Uno (or compatible):
- DB0 to DB7 > Arduino D0 to D7 respectively
- RD > 3.3 V
- RSET > A2
- CS > A3
- RW > A4
- RS > A5
- backlight 5V > 5V
- backlight GND > GND
Then upload the following sketch – Example 50.1. You should be presented with the following on your display:
If you’re curious, the LCD module and my Eleven board draws 225 mA of current. If that didn’t work for you, double-check the wiring against the list provided earlier. Now we’ll move forward and learn how to display text and graphics.
Sketch preparation
You will always need the following before void setup():
#include "UTFT.h"
UTFT myGLCD(ILI9325C,19,18,17,16); // for Arduino Uno
and in void setup():
myGLCD.InitLCD(orientation); myGLCD.clrScr();
with the former command, change orientation to either LANDSCAPE to PORTRAIT depending on how you’ll view the screen. You may need further commands however these are specific to features that will be described below. The function .clrScr() will clear the screen.
Displaying Text
There are three different fonts available with the library. To use them add the following three lines before void setup():
extern uint8_t SmallFont[]; extern uint8_t BigFont[]; extern uint8_t SevenSegNumFont[];
When displaying text you’ll need to define the foreground and background colours with the following:
myGLCD.setColor(red, green, blue); myGLCD.setBackColor(red, green, blue);
Where red, green and blue are values between zero and 255. So if you want white use 255,255,255 etc. For some named colours and their RGB values, click here. To select the required font, use one of the following:
myGLCD.setFont(SmallFont); // Allows 20 rows of 40 characters
myGLCD.setFont(BigFont); // Allows 15 rows of 20 characters
myGLCD.setFont(SevenSegNumFont); // allows display of 0 to 9 over four rows
Now to display the text use the function:
myGLCD.print("text to display",x, y);
where text is what you’d like to display, x is the horizontal alignment (LEFT, CENTER, RIGHT) or position in pixels from the left-hand side of the screen and y is the starting point of the top-left of the text. For example, to start at the top-left of the display y would be zero. You can also display a string variable instead of text in inverted commas.
You can see all this in action with the following sketch – Example 50.2, which is demonstrated in the following video:
Furthremore, you can also specify the angle of display, which gives a simple way of displaying text on different slopes. Simply add the angle as an extra parameter at the end:
myGLCD.print(“Hello, world”, 20, 20, angle);
Again, see the following sketch – Example 50.2a, and the results below:
Displaying Numbers
Although you can display numbers with the text functions explained previously, there are two functions specifically for displaying integers and floats.
You can see these functions in action with the following sketch – Example 50.3, with an example of the results below:
Displaying Graphics
There’s a few graphic functions that can be used to create required images. The first is:
myGLCD.fillScr(red, green, blue);
which is used the fill the screen with a certain colour. The next simply draws a pixel at a specified x,y location:
myGLCD.drawPixel(x,y);
Remember that the top-left of the screen is 0,0. Moving on, to draw a single line, use:
myGLCD.drawLine(x1,0,x2,239);
where the line starts at x1,y1 and finishes at x2,y2. Need a rectangle? Use:
myGLCD.drawRect(x1,y2,x2,y2); // for open rectangles
myGLCD.fillRect(x1,y2,x2,y2); // for filled rectangles
where the top-left of the rectangle is x1,y1 and the bottom-right is x2, y2. You can also have rectangles with rounded corners, just use:
myGLCD.drawRoundRect(x1,y2,x2,y2); // for open rectangles
myGLCD.fillRoundRect(x1,y2,x2,y2); // for filled rectangles
instead. And finally, circles – which are quite easy. Just use:
myGLCD.drawCircle(x,y,r); // draws open circle myGLCD.fillCircle(x,y,r); // draws a filled circle
where x,y are the coordinates for the centre of the circle, and r is the radius. For a quick demonstration of all the graphic functions mentioned so far, see Example 50.4 – and the following video:
Displaying bitmap images
If you already have an image in .gif, .jpg or .png format that’s less than 300 KB in size, this can be displayed on the LCD. To do so, the file needs to be converted to an array which is inserted into your sketch. Let’s work with a simple example to explain the process. Below is our example image:
Save the image of the puppy somewhere convenient, then visit this page. Select the downloaded file, and select the .c and Arduino radio buttons, then click “make file”. After a moment or two a new file will start downloading. When it arrives, open it with a text editor – you’ll see it contains a huge array and another #include statement – for example:
Past the #include statement and the array into your sketch above void setup(). After doing that, don’t be tempted to “autoformat” the sketch in the Arduino IDE. Now you can use the following function to display the bitmap on the LCD:
myGLCD.drawBitmap(x,y,width,height, name, scale);
Where x and y are the top-left coordinates of the image, width and height are the … width and height of the image, and name is the name of the array. Scale is optional – you can double the size of the image with this parameter. For example a value of two will double the size, three triples it – etc. The function uses simple interpolation to enlarge the image, and can be a clever way of displaying larger images without using extra memory. Finally, you can also display the bitmap on an angle – using:
myGLCD.drawBitmap(x,y,width,height, name, angle, cx, cy);
where angle is the angle of rotation and cx/cy are the coordinates for the rotational centre of the image.
The bitmap functions using the example image have been used in the following sketch – Example 50.5, with the results in the following video:
Unfortunately the camera doesn’t really do the screen justice, it looks much better with the naked eye.
Running out of space or I/O? Use an Arduino Mega
By now you may have noticed that the library for the LCDs uses up a fair amount of memory, which could be a problem. And using bitmaps eats up memory as well. And the I/O requirements are quite heavy. The solution is to use an Arduino Mega or compatible board – as they have up to eight times the sketch memory available. However the wiring is a little different – so when using a Mega, run a jumper from the following LCD module pins to your Mega (or compatible):
- DB0 to DB7 > Mega D22 to D29 respectively
- RD > 3.3 V
- RSET > D41
- CS > D40
- RW > D39
- RS > D38
- backlight 5V > 5V
- backlight GND > GND
You will also need to change the line
UTFT myGLCD(ILI9325C,19,18,17,16); // for Uno
to
UTFT myGLCD(ILI9325C,38,39,40,41); // for Mega
What about the SD card socket and touch screen?
The SD socket didn’t work, and I won’t be working with the touch screen at this time.
Conclusion
So there you have it – an incredibly inexpensive and possibly useful LCD module. Thank you to Henning Karlsen for his useful library, and if you found it useful – send him a donation via his page.
In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitter, Google+, subscribe for email updates or RSS using the links on the right-hand column? And join our friendly Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other – and we can all learn something.
Review – Schmartboard SMT Boards
In this article we review a couple of SMT prototyping boards from Schmartboard.
Introduction
Sooner or later you’ll need to use a surface-mount technology component. Just like taxes and myki* not working, it’s inevitable. When the time comes you usually have a few options – make your own PCB, then bake it in an oven or skillet pan; get the part on a demo board from the manufacturer (expensive); try and hand-solder it yourself using dead-bug wiring or try to mash it into a piece of strip board; or find someone else to do it. Thanks to the people at Schmartboard you now have another option which might cost a few dollars more but guarantees a result. Although they have boards for almost everything imaginable, we’ll look at two of them – one for QFP packages and their Arduino shield that has SOIC and SOP23-6 areas.
QFP 32-80 pin board
In our first example we’ll see how easy it is to prototype with QFP package ICs. An example of this is the Atmel ATmega328 microcontroller found on various Arduino-compatible products, for example:
Although our example has 32 pins, the board can handle up to 80-pin devices. You simply place the IC on the Schmartboard, which holds the IC in nicely due to the grooved tracks for the pins:
The tracks are what makes the Schmartboard EZ series so great – they help hold the part in, and contain the required amount of solder. I believe this design is unique to Schmartboard and when you look in their catalogue, select the “EZ” series for this technology. Moving forward, you just need some water-soluble flux:
then tack down the part, apply flux to the side you’re going to solder – then slowly push the tip of your soldering iron (set to around 750 degrees F) down the groove to the pin. For example:
Then repeat for the three other sides. That’s it. If your part has an exposed pad on the bottom, there’s a hole in the centre of the Schmartboad that you can solder into as well:
After soldering I really couldn’t believe it worked, so probed out the pins to the breakout pads on the Schmartboard to test for shorts or breaks – however it tested perfectly. The only caveat is that your soldering iron tip needs to be the same or smaller pitch than the the part you’re using, otherwise you could cause a solder bridge. And use flux! You need the flux. After soldering you can easily connect the board to the rest of your project or build around it.
Schmartboard Arduino shield
There’s also a range of Arduino shields with various SMT breakout areas, and we have the version with 1.27mm pitch SOIC and a SOT23-6 footprint. SOIC? For example:
This is the AD5204 four-channel digital potentiometer we used in the SPI tutorial. It sits nicely in the shield and can be easily soldered onto the board. Don’t forget the flux! Although the SMT areas have the EZ-technology, I still added a little solder of my own – with satisfactory results:
The SOT23-6 also fits well, with plenty of space for soldering it in. SOT23? Example – the ADS1110 16-bit ADC which will be the subject of a future tutorial:
Working with these tiny components is also feasible but requires a finer iron tip and a steady hand.
Once the SMT component(s) have been fitted, you can easily trace out the matching through-hole pads for further connections. The shield matches the Arduino R3 standards and includes stacking header sockets, two LEDs for general use, space and parts for an RC reset circuit, and pads to add pull-up resistors for the I2C bus:
Finally there’s also three 0805-sized parts and footprints for some practice or use. It’s a very well though-out shield and should prove useful. You can also order a bare PCB if you already have stacking headers to save money.
Conclusion
If you’re in a hurry to prototype with SMT parts, instead of mucking about – get a Schmartboard. They’re easy to use and work well. Full-sized images available on flickr.
In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitter, Google+, subscribe for email updates or RSS using the links on the right-hand column? And join our friendly Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other – and we can all learn something.
The boards used in this article were a promotional consideration supplied by Schmartboard.
Review – LBE “Magpie” Arduino-compatible board
In this article we review the “Magpie” Arduino Uno-compatible board from Little Bird Electronics.
Introduction
Finally I’m back at the office and have a pile of things to write about. Starting with the subject of this review – the “Magpie” board from Little Bird Electronics in Australia. It seems that a new Arduino-compatible board enters the market every week, thanks to the open-source nature of the platform and the availability of rapid manufacturing. However the Magpie isn’t just any old Arduino Uno knock-off, it has something which helps it stand out from the crowd – status LEDs on every digital and analogue I/O pin. You can see them between the stacking header sockets and the silk-screen labels. For example:
and for the curious, the bottom of the Magpie:
At first glance you might think “why’d they bother doing that? I could just wire up some LEDs myself”. True. However having them on the board speeds up the debugging process as you can see when an output is HIGH or LOW – and in the case of an input pin, whether a current is present or not. For the curious the LEDs are each controlled by a 2N7002 MOSFET with the gate connected to the I/O pin, for example:
An LED will illuminate as long as the gate voltage is higher than the threshold voltage – no matter the status of the particular I/O pin. And if an I/O pin is left floating it may trigger the LED if the threshold voltage is exceeded at the gate. Therefore when using the Magpie it would be a good idea to set all the pins to LOW that aren’t required for your particular sketch. Even if you remove and reapply power the floating will still be prevalent, and indicated visually – for example:
Nevertheless you can sort that out in void setup(), and then the benefits of the LEDs become apparent. Consider the following quick demonstration sketch:
// LBE Magpie board LED demo - John Boxall 18 March 2013
// usual blink delay period
int d=100;
void setup()
{
// digital pins to outputs
for (int a=0; a<14; a++)
{
pinMode(a, OUTPUT);
}
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
pinMode(A2, OUTPUT);
pinMode(A3, OUTPUT);
pinMode(A4, OUTPUT);
pinMode(A5, OUTPUT);
}
void allOn()
// all LEDs on
{
for (int a=0; a<14; a++)
{
digitalWrite(a, HIGH);
}
digitalWrite(A0, HIGH);
digitalWrite(A1, HIGH);
digitalWrite(A2, HIGH);
digitalWrite(A3, HIGH);
digitalWrite(A4, HIGH);
digitalWrite(A5, HIGH);
}
void allOff()
// all LEDs on
{
for (int a=0; a<14; a++)
{
digitalWrite(a, LOW);
}
digitalWrite(A0, LOW);
digitalWrite(A1, LOW);
digitalWrite(A2, LOW);
digitalWrite(A3, LOW);
digitalWrite(A4, LOW);
digitalWrite(A5, LOW);
}
void clockWise(int r, int s)
// blinks on and off each LED clockwise
// r - # rotations, s - blink delay
{
allOff();
for (int a=0; a<r; a++)
{
for (int b=13; b>=0; --b)
{
digitalWrite(b, HIGH);
delay(s);
digitalWrite(b, LOW);
}
digitalWrite(A5, HIGH);
delay(s);
digitalWrite(A5, LOW);
digitalWrite(A4, HIGH);
delay(s);
digitalWrite(A4, LOW);
digitalWrite(A3, HIGH);
delay(s);
digitalWrite(A3, LOW);
digitalWrite(A2, HIGH);
delay(s);
digitalWrite(A2, LOW);
digitalWrite(A1, HIGH);
delay(s);
digitalWrite(A1, LOW);
digitalWrite(A0, HIGH);
delay(s);
digitalWrite(A0, LOW);
delay(s);
}
}
void anticlockWise(int r, int s)
// blinks on and off each LED anticlockwise
// r - # rotations, s - blink delay
{
allOff();
for (int a=0; a<r; a++)
{
for (int b=0; b<14; b++)
{
digitalWrite(b, HIGH);
delay(s);
digitalWrite(b, LOW);
}
digitalWrite(A0, HIGH);
delay(s);
digitalWrite(A0, LOW);
digitalWrite(A1, HIGH);
delay(s);
digitalWrite(A1, LOW);
digitalWrite(A2, HIGH);
delay(s);
digitalWrite(A2, LOW);
digitalWrite(A3, HIGH);
delay(s);
digitalWrite(A3, LOW);
digitalWrite(A4, HIGH);
delay(s);
digitalWrite(A4, LOW);
digitalWrite(A5, HIGH);
delay(s);
digitalWrite(A5, LOW);
delay(s);
}
}
void loop()
{
anticlockWise(3,50);
clockWise(3,50);
for (int z=0; z<4; z++)
{
allOn();
delay(100);
allOff();
delay(100);
}
}
… and the results are demonstrated in the following video:
Apart from the LEDs the Magpie offers identical function to that of an Arduino Uno R2 – except the USB microcontroller is an Atmel 16U2 instead of an 8U2, and the USB socket is a mini-USB and not the full-size type. For the curious you can download the Magpie design files from the product page.
Conclusion
If you’re often experimenting or working with the Arduino’s I/O pins and find yourself wiring up LEDs for testing purposes – the Magpie was made for you. Having those LEDs on the board really does save you if in a hurry to test or check something.
In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitter, Google+, subscribe for email updates or RSS using the links on the right-hand column? And join our friendly Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other – and we can all learn something.
The Magpie board used in this article was a promotional consideration supplied by Little Bird Electronics.
Project: Clock Four – Scrolling text clock
Introduction
Time for another instalment in my highly-irregular series of irregular clock projects. In this we have “Clock Four” – a scrolling text clock. After examining some Freetronics Dot Matrix Displays in the stock, it occurred to me that it would be neat to display the time as it was spoken (or close to it) – and thus this the clock was born. It is a quick project – we give you enough to get going with the hardware and sketch, and then you can take it further to suit your needs.
Hardware
You’ll need three major items – An Arduino Uno-compatible board, a real-time clock circuit or module using either a DS1307 or DS3232 IC, and a Freetronics DMD. You might want an external power supply, but we’ll get to that later on.
The first stage is to fit your real-time clock. If you are unfamiliar with the operation of real-time clock circuits, check out the last section of this tutorial. You can build a RTC circuit onto a protoshield or if you have a Freetronics Eleven, it can all fit in the prototyping space as such:
If you have an RTC module, it will also fit in the same space, then you simply run some wires to the 5V, GND, A4 (for SDA) and A5 (for SCL):
By now I hope you’re thinking “how do you set the time?”. There’s two answers to that question. If you’re using the DS3232 just set it in the sketch (see below) as the accuracy is very good, you only need to upload the sketch with the new time twice a year to cover daylight savings (unless you live in Queensland). Otherwise add a simple user-interface – a couple of buttons could do it, just as we did with Clock Two. Finally you just need to put the hardware on the back of the DMD. There’s plenty of scope to meet your own needs, a simple solution might be to align the control board so you can access the USB socket with ease – and then stick it down with some Sugru:
With regards to powering the clock – you can run ONE DMD from the Arduino, and it runs at a good brightness for indoor use. If you want the DMD to run at full, retina-burning brightness you need to use a separate 5 V 4 A power supply. If you’re using two DMDs – that goes to 8 A, and so on. Simply connect the external power to one DMD’s terminals (connect the second or more DMDs to these terminals):

The Arduino Sketch
You can download the sketch from here. It was written only for Arduino v1.0.1. The sketch has the usual functions to set and retrieve the time from DS1307/3232 real-time clock ICs, and as usual with all our clocks you can enter the time information into the variables in void setup(), then uncomment setDateDs1307(), upload the sketch, re-comment setDateDs1307, then upload the sketch once more. Repeat that process to re-set the time if you didn’t add any hardware-based user interface.
Once the time is retrieved in void loop(), it is passed to the function createTextTime(). This function creates the text string to display by starting with “It’s “, and then determines which words to follow depending on the current time. Finally the function drawText() converts the string holding the text to display into a character variable which can be passed to the DMD.
And here it is in action:
Conclusion
This was a quick project, however I hope you found it either entertaining or useful – and another random type of clock that’s easy to reproduce or modify yourself. We’re already working on another one which is completely different, so stay tuned.
In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitter, Google+, subscribe for email updates or RSS using the links on the right-hand column? And join our friendly Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other – and we can all learn something.
Arduino and KTM-S1201 LCD modules
Learn how to use very inexpensive KTM-S1201 LCD modules in this edition of our Arduino tutorials. This is chapter forty-nine of a series originally titled “Getting Started/Moving Forward with Arduino!” by John Boxall – A tutorial on the Arduino universe. The first chapter is here, the complete series is detailed here.
Introduction
After looking for some displays to use with another (!) clock, I came across some 12-digit numeric LCD displays. They aren’t anything flash, and don’t have a back light – however they were one dollar each. How could you say no to that? So I ordered a dozen to try out. The purpose of this tutorial is to show you how they are used with an Arduino in the simplest manner possible.
Moving forward – the modules look like OEM modules for desktop office phones from the 1990s:
With a quick search on the Internet you will find a few sellers offering them for a dollar each. The modules (data sheet) use the NEC PD7225 controller IC (data sheet):
They aren’t difficult to use, so I’ll run through set up and operation with a few examples.
Hardware setup
First you’ll need to solder some sort of connection to the module – such as 2×5 header pins. This makes it easy to wire it up to a breadboard or a ribbon cable:
The rest of the circuitry is straight-forward. There are ten pins in two rows of five, and with the display horizontal and the pins on the right, they are numbered as such:
Now make the following connections:
- LCD pin 1 to 5V
- LCD pin 2 to GND
- LCD pin 3 to Arduino D4
- LCD pin 4 to Arduino D5
- LCD pin 5 to Arduino D6
- LCD pin 6 to Arduino D7
- LCD pin 7 – not connected
- LCD pin 8 – Arduino D8
- LCD pin 9 to the centre pin of a 10k trimpot – whose other legs connect to 5V and GND. This is used to adjust the contrast of the LCD.
The Arduino digital pins that are used can be changed – they are defined in the header file (see further on). If you were curious as to how low-current these modules are:
That’s 0.689 mA- not bad at all. Great for battery-powered operations. Now that you’ve got the module wired up, let’s get going with some demonstration sketches.
Software setup
The sketches used in this tutorial are based on work by Jeff Albertson and Robert Mech, so kudos to them – however we’ve simplified them a little to make use easier. We’ll just cover the functions required to display data on the LCD. However feel free to review the sketches and files along with the controller chip datasheet as you’ll get an idea of how the controller is driven by the Arduino.
When using the LCD module you’ll need a header file in the same folder as your sketch. You can download the header file from here. Then every time you open a sketch that uses the header file, it should appear in a tab next to the main sketch, for example (click to enlarge):
There’s also a group of functions and lines required in your sketch. We’ll run through those now – so download the first example sketch, add the header file and upload it. Your results should be the same as the video below:
So how did that work? Take a look at the sketch you uploaded. You need all the functions between the two lines of “////////////////////////” and also the five lines in void setup(). Then you can display a string of text or numbers using
ktmWriteString();
which was used in void loop(). You can use the digits 0~9, the alphabet (well, what you can do with 7-segments), the degrees symbol (use an asterix – “*”) and a dash (use - “-”). So if your sketch can put together the data to display in a string, then that’s taken care of.
If you want to clear the screen, use:
ktmCommand(_ClearDsp);
Next – to individually place digits on the screen, use the function:
ktmPrnNumb(n,p,d,l);
Where n is the number to be displayed (zero or a positive integer), p is the position on the LCD for the number’s (the positions from left to right are 11 to 0…), d is the number of digits to the right of the decimal point (leave as zero if you don’t want a decimal point), and l is the number of digits being displayed for n. When you display digits using this function you can use more than one function to compose the number to be displayed – as this function doesn’t clear the screen.
To help get your head around it, the following example sketch (download) has a variety of examples in void loop(). You can watch this example in the following video:
Conclusion
So there you have it – an incredibly inexpensive and possibly useful LCD module. Thank you to Jeff Albertson and Robert Mech for their help and original code.
In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitter, Google+, subscribe for email updates or RSS using the links on the right-hand column? And join our friendly Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other – and we can all learn something.
mbed and the Freescale FRDM-KL25Z development board
In this article we examine the mbed rapid prototyping platform with the Freescale FRDM-KL25Z ARM® Cortex™-M0+ development board.
Introduction
A while ago we looked at the mbed rapid prototyping environment for microcontrollers with the cloud-based IDE and the NXP LPC1768 development board, and to be honest we left it at that as I wasn’t a fan of cloud-based IDEs. Nevertheless, over the last two or so years the mbed platform has grown and developed well – however without too much news on the hardware side of things. Which was a pity as the matching development boards usually retailed for around $50 … and most likely half the reason why mbed didn’t become as popular as other rapid development platforms.
Also – a few months ago – we received the new Freescale Freedom FRDM-KL25Z development board from element14. I started to write about using the board but frankly it did my head in, as at the time the IDE was almost a one gigabyte download and the learning curve too steep for the time I had available. Which was a pity as the board is inexpensive and quite powerful. So the board went into the “miscellaneous dev kit” box graveyard. Until now. Why?
You can now use the Freedom board with mbed.
It isn’t perfect – yet – but it’s a move in the right direction for both mbed and Freescale. It allows educators and interested persons access to a very user-friendly IDE and dirt-cheap development boards.
What is mbed anyway?
mbed is a completely online development environment. That is, in a manner very similar to cloud computing services such as Google Docs or Zoho Office. However there are some pros and cons of this method. The pros include not having to install any software on the PC – as long as you have a web browser and a USB port you should be fine; any new libraries or IDE updates are handled on the server leaving you to not worry about staying up to date; and the online environment can monitor and update your MCU firmware if necessary. However the cons are that you cannot work with your code off-line, and there may be some possible privacy issues. Here’s an example of the environment (click to enlarge):
As you can see the IDE is quite straight-forward. All your projects can be found on the left column, the editor in the main window and compiler and other messages in the bottom window. There’s also an online support forum, an official mbed library and user-submitted library database, help files and so on – so there’s plenty of support. Code is written in C/C++ style and doesn’t present any major hurdles. When it comes time to run the code, the online compiler creates a downloadable binary file which is copied over to the hardware via USB.
And what’s a Freedom board?
It’s a very inexpensive development board based on the Freescale ARM® Cortex™-M0+ MKL25Z128VLK4 microcontroller. How inexpensive? In Australia it’s $9 plus GST and delivery.
Features include (from the product website):
- MKL25Z128VLK4 MCU – 48 MHz, 128 KB flash, 16 KB SRAM, USB OTG (FS), 80LQFP
- Capacitive touch “slider,” MMA8451Q accelerometer, tri-color LED
- Easy access to MCU I/O
- Sophisticated OpenSDA debug interface
- Mass storage device flash programming interface (default) – no tool installation required to evaluate demo apps
- P&E Multilink interface provides run-control debugging and compatibility with IDE tools
- Open-source data logging application provides an example for customer, partner and enthusiast development on the OpenSDA circuit
And here it is:
In a lot of literature about the board it’s mentioned as being “Arduino compatible”. This is due to the layout of the GPIO pins – so if you have a 3.3 V-compatible Arduino shield you may be able to use it – but note that the I/O pins can only sink or source 3 mA (from what I can tell) – so be careful with the GPIO . However on a positive side the board has the accelerometer and an RGB LED which are handy for various uses. Note that the board ships without any stacking header sockets, but element14 have a starter pack with those and a USB cable for $16.38++.
Getting started
Now we”ll run through the process of getting a Freedom board working with mbed and creating a first program. You’ll need a computer (any OS) with USB, an Internet connection and a web browser, a USB cable (mini-A to A) and a Freedom board. The procedure is simple:
- Download and install the USB drivers for Windows or Linux from here.
- Visit mbed.org and create a user account. Check your email for the confirmation link and follow the instructions within.
- Plug in your Freedom board – using the USB socket labelled “OpenSDA”. It will appear as a disk called “bootloader”
- Download this file and copy it onto the “bootloader” drive
- Unplug the Freedom board, wait a moment – then plug it back in. It should now appear as a disk called “MBED”, for example (click to enlarge):
There will be a file called ‘mbed’ on the mbed drive – double-click this to open it in a web browser. This process activates the board on your mbed account – as shown below (click to enlarge):
Now you’re ready to write your code and upload it to the Freedom board. Click “Compiler” at the top-right to enter the IDE.
Creating and uploading code
Now to create a simple program to check all is well. When you entered the IDE in the previous step, it should have presented you with the “Guide to mbed Online Compiler”. Have a read, then click “New” at the top left. Give your program a name and click OK. You will then be presented with a basic “hello world” program that blinks the blue LED in the RGB module. Adjust the delays to your liking then click “Compile” in the toolbar.
If all is well, your web browser will present you with a .bin file that has been downloaded to the default download directory. (If not, see the error messages in the area below the editor pane). Now copy this .bin file to the mbed drive, then press the reset button (between the USB sockets) on the Freedom board. Your blue LED should now be blinking.
Moving forward
You can find some code examples that demonstrate the use of the accelerometer, RGB LED and touch sensor here. Here’s a quick video of the touch sensor in action:
So which pin is what on the Freedom board with respect to the mbed IDE? Review the following map:
All the pins in blue – such as PTxx can be referred to in your code. For example, to pulse PTA13 on and off every second, use:
#include "mbed.h"
DigitalOut pulsepin(PTA13);
int main() {
while(1) {
pulsepin = 1;
wait(1);
pulsepin = 0;
wait(1);
}
}
The pin reference is inserted in the DigitalOut assignment and thus “pulsepin” refers to PTA13. If you don’t have the map handy, just turn the board over for a quick-reference (click to enlarge):
Just add “PT” to the pin number. Note that the LEDs are connected to existing GPIO pins: green – PTB19, red – PTB18 and blue – PTB.
Where to from here?
It’s up to you. Review the Freedom board manual (from here) and the documentation on the mbed website, create new things and possibly share them with others via the mbed environment. For more technical details review the MCU data sheet.
Conclusion
The Freedom board offers a very low cost way to get into microcontrollers and programming. You don’t have to worry about IDE or firmware revisions, installing software on locked-down computers, or losing files. You could teach a classroom full of children embedded programming for around $20 a head (a board and some basic components). Hopefully this short tutorial was of interest. We haven’t explored every minute detail – but you now have the basic understanding to move forward with your own explorations.
The Freescale Freedom FRDM-KL25Z development board used in this article was a promotional consideration supplied by element14.
Arduino tutorial 15a – RFID with Innovations ID-20
Learn how to use RFID readers with your Arduino. In this instalment we use the Innovations ID-20 RFID reader. The ID-12 and ID-2 are also compatible. If you have the RDM630 or RDM6300 RFID reader, we have a different tutorial.
This is part of a series originally titled “Getting Started with Arduino!” by John Boxall – A tutorial on the Arduino universe. The first chapter is here, the complete series is detailed here.
Updated 26/02/2013
RFID – radio frequency identification. Some of us have already used these things, and they have become part of everyday life. For example, with electronic vehicle tolling, door access control, public transport fare systems and so on. It sounds complex – but isn’t. In this tutorial we’ll run through the basics of using the ID-20 module then demonstrate a project you can build and expand upon yourself.
Introduction
To explain RFID for the layperson, we can use a key and lock analogy. Instead of the key having a unique pattern, RFID keys hold a series of unique numbers which are read by the lock. It is up to our software (sketch) to determine what happens when the number is read by the lock. The key is the tag, card or other small device we carry around or have in our vehicles. We will be using a passive key, which is an integrated circuit and a small aerial. This uses power from a magnetic field associated with the lock. Here are some key or tag examples:
In this tutorial we’ll be using 125 kHz tags – for example. To continue with the analogy our lock is a small circuit board and a loop aerial. This has the capability to read the data on the IC of our key, and some locks can even write data to keys. And out reader is the Innovations ID-20 RFID reader:
Unlike the RDM630 reader in the other RFID tutorial – the ID-20 is a complete unit with an internal aerial and has much larger reader range of around 160 mm. It’s a 5V device and draws around 65 mA of current. If you have an ID-12 it’s the same except the reader range is around 120mm; and the ID-2 doesn’t have an internal aerial. Connecting your ID-20 reader to the Arduino board may present a small challenge and require a bit of forward planning. The pins on the back of the reader are spaced closer together than expected:
… so a breakout board makes life easier:
… and for demonstration and prototyping purposes, we’ve soldered on the breakout board with some header pins:
The first thing we’ll do is connect the ID-20 and demonstrate reading RFID tags. First, wire up the hardware as shown below:
If you’re using the breakout board shown earlier, pin 7 matches “+/-” in the diagram above. Next, enter and upload the following sketch (download):
// Example 15a.1
#include <SoftwareSerial.h>
SoftwareSerial id20(3,2); // virtual serial port
char i;
void setup()
{
Serial.begin(9600);
id20.begin(9600);
}
void loop ()
{
if(id20.available()) {
i = id20.read(); // receive character from ID20
Serial.print(i); // send character to serial monitor
Serial.print(" ");
}
}
Note that we’re using a software serial port for our examples. In doing so it leaves the Arduino’s serial lines for uploading sketches and the serial monitor. Now open the serial monitor window, check the speed is set to 9600 bps and wave some tags over the reader – the output will be displayed as below (but with different tag numbers!):
Each tag’s number starts with a byte we don’t need, then twelve that we do, then three we don’t. The last three aren’t printable in the serial monitor. However you do want the twelve characters that appear in the serial monitor. While running this sketch, experiment with the tags and the reader… get an idea for how far away you can read the tags. Did you notice the tag is only read once – even if you leave it near the reader? The ID-20 has more “intelligence” than the RDM630 we used previously. Furthermore when a tag is read, the ID-20 sends a short PWM signal from pin 10 which is just under 5V and lasts for around 230 ms, for example (click image to enlarge):
This signal can drive a piezo buzzer or an LED (with suitable resistor). Adding a buzzer or LED would give a good notification to the user that a card has been read. While you’re reading tags for fun, make a note of the tag numbers for your tags – you’ll need them for the next examples.
RFID Access System
Now that we can read the cards, let’s create a simple control system. It will read a tag, and if it’s in the list of allowed tags the system will do something (light a green LED for a moment). Plus we have another LED which stays on unless an allowed tag is read. Wire up the hardware as shown below (LED1 is red, LED2 is green – click image to enlarge):
Now enter and upload the following sketch (download):
// Example 15a.2
#include SoftwareSerial id20(3,2); // virtual serial port
// add your tags here. Don't forget to add to decision tree in readTag(); String Sinclair = "4F0023E2129C"; String Smythe = "4F0023CC9737"; String Stephen = "010044523C2B";
String testcard; char testtag[12]; int indexnumber = 0; char tagChar;
void setup()
{
Serial.begin(9600);
pinMode(7, OUTPUT); // this if for "rejected" red LED
pinMode(9, OUTPUT); // this will be set high when correct tag is read. Use to switch something on, for now - a green LED.
id20.begin(9600);
digitalWrite(7, LOW);
digitalWrite(9, LOW);
}
void approved()
// when an approved card is read
{
digitalWrite(9, HIGH);
Serial.println("yes");
delay(1000);
digitalWrite(9, LOW);
}
void notApproved()
// when an unlisted card is read
{
digitalWrite(7, HIGH);
Serial.println("no");
delay(100);
digitalWrite(7, LOW);
}
void readTag()
{
tagChar = id20.read();
if (indexnumber != 0) // never a zero in tag number
{
testtag[indexnumber - 1] = tagChar;
}
indexnumber++;
if (indexnumber == 13 ) // end of tag number
{
indexnumber = 0;
testcard = String(testtag);
if (testcard.equals(Sinclair)) {
approved();
}
else if (testcard.equals(Smythe)) {
approved();
}
else if (testcard.equals(Stephen)) {
approved();
}
else {
notApproved();
}
}
}
void loop()
{
readTag();
}
In the function readCard() the sketch reads the tag data from the ID-20, and stores it in an array testtag[]. The index is -1 so the first unwanted tag number isn’t stored in the array. Once thirteen numbers have come through (the one we don’t want plus the twelve we do want) the numbers are smooshed together into a string variable testcard with the function String. Now the testcard string (the tag just read) can be compared against the three pre-stored tags (Sinclair, Smythe and Stephen).
Then it’s simple if… then… else to to see if we have a match, and if so – call the function approved() or disApproved as the case may be. In those two functions you store the actions you want to occur when the correct card is read (for example, control a door strike or let a cookie jar open) or when the system is waiting for another card/a match can’t be found. If you’re curious to see it work, check the following video where we take it for a test run and also show the distances that you have to work with:
Hopefully this short tutorial was of interest. We haven’t explored every minute detail of the reader – but you now have the framework to move forward with your own projects.
First look: Arduino Due
Updated 27/02/2013
Introduction
After much waiting the Arduino Due has been released, so let’s check it out. We’ll run through the specifications and some areas of interest, see what’s different, some random notes – then try out some of the new features. Before moving forward note that it might look the same - the Due is not a drop-in replacement for older boards – even the Mega2560. It’s different.
First announced in late 2011, the Due is the Arduino team’s first board with a 32-bit processor – the Atmel SAM3X8E ARM Cortex-M3 CPU. With an 84 Mhz CPU speed and a host of interfaces and I/O, this promises to be the fastest and most functional Arduino board ever. According to the official Arduino press release:
Arduino Due is ideal for those who want to build projects that require high computing power such as the remotely-controlled drones that, in order to fly, need to process a lot of sensor data per second.
Arduino Due gives students the opportunity to learn the inner workings of the ARM processor in a cheaper and much simpler way than before.
To Scientific projects, which need to acquire data quickly and accurately, Arduino Due provides a platform to create open source tools that are much more advanced than those available now.
The new platform enables the open source digital fabrication community (3d Printers, Laser cutters, CNC milling machines) to achieve higher resolutions and faster speed with fewer components than in the past.
Sounds good – and the Due has been a long time coming, so let’s hope it is worth the wait. The SAM3X CPU holds a lot of promise for more complex projects that weren’t possible with previous ATmega CPUs, so this can be only a good thing.
Specifications
First of all, here’s the Due in detail – top and bottom (click to enlarge):
You can use Mega-sized protoshields without any problem (however older shields may miss out on the upper I2C pins) – they’ll physically fit in … however their contents will be a different story:
The specifications of the Due are as follows (from Arduino website):
| Microcontroller | AT91SAM3X8E | |
| Operating Voltage | 3.3V | |
| Input Voltage (recommended) | 7-12V | |
| Input Voltage (limits) | 6-20V | |
| Digital I/O Pins | 54 (of which 12 provide PWM output) | |
| Analog Input Pins | 12 | |
| Analog Outputs Pins | 2 (DAC) | |
| Total DC Output Current on all I/O lines | 130 mA | |
| DC Current for 3.3V Pin | 800 mA | |
| DC Current for 5V Pin | 800 mA | |
| Flash Memory | 512 KB all available for the user applications | |
| SRAM | 96 KB (two banks: 64KB and 32KB) | |
| Clock Speed | 84 MHz |
Right away a few things should stand out – the first being the operating voltage – 3.3V. That means all your I/O needs to work with 3.3V – not 5V. Don’t feed 5V logic line into a digital input pin and hope it will work – you’ll damage the board. Instead, get yourself some logic level converters. However there is an IOREF pin like other Arduino boards which intelligent shields can read to determine the board voltage. The total output current for all I/O lines is also 130 mA … so no more sourcing 20mA from a digital ouput for those bright LEDs.
The power regulator for 5V has been changed from linear to switching – so no more directly inserting 5V into the 5V pin. However the 3.3V is through an LDO from 5v.
Each digital I/O pin can source 3 or 15 mA – or sink 6 or 9 mA … depending on the pin. High-current pins are CAN-TX, digital 1, 3~12, 23~51, and SDA1. The rest are low current. And there’s still an LED on digital 13. You will need to redesign any existing projects or shields if moving to the Due.
The analogue inputs now have a greater resolution – 12-bits. That means it can return a value of 0~4095 representing 0~3.3V DC. To activate this higher resolution you need to use the function analogReadResolution(12).
Memory – there isn’t any EEPROM in the SAM3X – so you’ll need external EEPROMs to take care of more permanent storage. However there’s 512 KB of flash memory for sketches – which is huge. You have to see it to believe it:
Excellent. A new feature is the onboard erase button. Press it for three seconds and it wipes out the sketch. The traditional serial line is still digital 0/1 – which connect to the USB controller chip.
Hardware serial – there’s four serial lines. Pulse-width modulation (PWM) is still 8-bit and on digital pins 2~13.
The SPI bus is on the ICSP header pins to the right of the microcontroller – so existing shields that use SPI will need to be modified – or experiment with a LeoShield:
You can also use the extended SPI function of the SAM3X which allow the use of digital pins 4, 10 or 52 for CS (chip select).
The SAM3X supports the automtive CAN bus, and the pins have been brought out onto the stacked header connectors – however this isn’t supported yet in the IDE.
There are two I2C buses – located on digital 20/21 and the second is next to AREF just like on the Leonardo.
There’s a 10-pin JTAG mini-header on the Due, debug pins and a second ICSP for the ATmega16U2 which takes care of USB. Speaking of USB – there’s two microUSB sockets. One is for regular programming via the Arduino IDE and the USB interface, the other is a direct native USB programming port direct to the SAM3X.
The SAM3X natively supports Ethernet, but this hasn’t been implemented on the hardware side for the Due. However some people in the Arduino forum might have a way around that.
Using the Due
First of all – at the time of writing – you need to install Arduino IDE v1.5.1 release 2 – a beta version. Windows users – don’t forget the USB drivers. As always, backup your existing installation and sketch files somewhere safe – and you can run more than one IDE on the same machine.
When it comes time to upload your sketches, plug the USB cable into the lower socket on the Due – and select Arduino Due (Programming Port) from the Tools>Board menu in the IDE.
Let’s upload a sketch now (download) – written by Steve Curd from the Arduino forum. It calculates Newton Approximation for pi using an infinite series. As you can see from the results below, the Due is much faster (690 ms) than the Mega2560 (5765 ms). Click the image to enlarge:
Next, let’s give the digital-to-analogue converters a test. Finally we have two, real, 12-bit DACs with the output pins being … DAC0 and DAC1. No more mucking about with external R-C filters to get some audio happening. These pins provides true analogue outputs which is controlled by the analogWrite() function. To use them is very simple – consider the following example sketch which creates a triangle wave:
void setup()
{
analogWriteResolution(12); // 12-bit!
}
void loop()
{
for(int x=0; x<4096; x++)
{
analogWrite(DAC0, x); // use DAC1 for ... DAC1
}
for(int x=4095; x>=0; --x)
{
analogWrite(DAC0, x);
}
}
And the results from the DSO (click image to enlarge):

This opens up all sorts of audio possibilities. With appropriate wavetable data saved in memory you could create various effects. However the DAC doesn’t give a full 0~3.3V output – instead it’s 1/6 to 5/6 of the Aref voltage. With the IDE there are example sketches that can play a .wav file from an SDcard – however I’d still be more inclined to use an external shield for that. Nevertheless for more information, have a look at the Audio library. Furthermore, take heed of the user experiences noted in the Arduino forum – it’s very easy to destroy your DAC outputs. In the future we look forward to experimenting further with the Due – so stay tuned.
Getting a Due
Good luck … at the time of writing – the Dues seem to be very thin on the ground. This may partly be due to the limited availability of the Atmel SAM3X8E. My contacts in various suppliers say volumes are quite limited.
Quality
I really hope this is a rare event, however one of the Dues received had the following fault in manufacturing:
One side of the crystal capacitor wasn’t in contact with the PCB. However this was a simple fix. How the QC people missed this … I don’t know. However I’ve seen a few Arduinos of various types, and this error is not indicative of the general quality of Arduino products.
Where to from here?
Visit the official Arduino Due page, the Due discussion section of the Arduino forum, and check out the reference guide for changes to functions that are affected by the different hardware.
Conclusion
Well that’s my first take on the Due – powerful and different. You will need to redesign existing projects, or build new projects around it. And a lot of stuff on the software side is still in beta. So review the Due forum before making any decisions. With that in mind – from a hardware perspective – it’s a great step-up from the Mega2560.
So if you’re interested – get one and take it for a spin, it won’t disappoint. The software will mature over time which will make life easier as well. If you have any questions (apart from Arduino vs. Raspberry Pi) leave a comment and we’ll look into it.
Have fun and keep checking into tronixstuff.com. Why not follow things on twitter, Google+, subscribe for email updates or RSS using the links on the right-hand column, or join our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other – and we can all learn something.


























































