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.
May 2011 Competition Results
Hello Readers
The month of May has ended and thus another monthly tronixstuff.com competition. There were five questions hidden within the posts – and most entrants were correct. Questions for May were:
- What is the largest integer that can be stored in an ATmega328 EEPROM address? – 255
- Who invented Pong? – Allan Alcorn
- Would you use a rheostat or a potentiometer to divide voltage? A potentiometer
- Name the creator of the fictional computer “Colossus” – Dr Charles Forbin. This question came about after watching the movie “Colossus: The Forbin Project“. To the two people who wrote in calling this a stupid question – have a sense of humour and learn to use Google search. One person wrote in with the author of the book the movie was based on, that answer was also accepted.
- When was TV first broadcast in colour in Australia? Well I should have been more specific with this question as test broadcasting started in 1967 with a full changeover in 1975. So either year was accepted.
The first winner drawn will receive a brand new, hot off the pick and place – Freetronics EtherTen!
The EtherTen must be the ultimate Arduino-Uno compatible board on the market. From the Freetronics website:
Two tastes that taste great together: Arduino and Ethernet. But until now the only way to connect an Arduino to the Internet via a LAN was to add an Ethernet Shield. Wouldn’t it be great if there was an Arduino-compatible board with on-board Ethernet? Better still, what if that board was based on the Freetronics Eleven and theFreetronics Ethernet Shield (with Power-over-Ethernet support!) but merged together into a single, integrated board that was 100% Arduino compatible and network-enabled?
This, folks, is what you’ve been waiting for.
The EtherTen is a 100% Arduino compatible board that can talk to the world. Do Twitter updates automatically, serve web pages, connect to web services, display sensor data online, and control devices using a web browser. The Freetronics EtherTen uses the same ATmega328P as the Duemilanove and the same Wiznet W5100 chip used by the official Arduino Ethernet Shield, so it’s 100% compatible with the Ethernet library and sketches. Any project you would previously have built with an Arduino and an Ethernet shield stacked together, you can now do all in a single, integrated board.
We’ve even added a micro SD card slot so you can store web content on the card, or log data to it.
All the good things about the Eleven and the Ethernet Shield have been combined into this one device so please see those pages for all the specific details, but the highlights include:
- Gold-plated PCB.
- Top and bottom parts overlays.
- Top-spec ATmega328P MCU.
- Mini-USB connector: no more shorts against shields!
- D13 pin isolated with a MOSFET so you can use it as an input.
- Power-over-Ethernet support, both cheapie DIY or full 802.3af standards-compliant.
- Ethernet activity indicators on the PCB and the jack.
- 10/100base-T auto-selection.
- Fully compatible with standard Ethernet library.
- Reset management chip.
- Fixed SPI behavior on Ethernet chipset.
- Robust power filtering.
- Sexy rounded corners. Hmm.
So have fun and keep checking into tronixstuff.com. Why not follow things on twitter, 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.
Once again, thank you to our generous competition sponsor Freetronics
Kit review – nootropic design Hackvision
Hello readers
Time for another kit review – the nootropics design Hackvision, a nice change from test equipment. The purpose of the Hackvision is to allow the user to create retro-style arcade games and so on that can be played on a monitor or television set with analogue video input. Although the display resolution is only 128 by 96 pixels, this is enough to get some interesting action happening. Frankly I didn’t think the Arduino hardware environment alone was capable of this, so the Hackvision was a pleasant surprise.
Assembly is quick and relatively simple, the instructions are online and easy to follow. All the parts required are included:
The microcontroller is pre-loaded with two games so you can start playing once construction has finished. However you will need a 5V FTDI cable if you wish to upload new games as the board does not have a USB interface. The board is laid out very clearly, and with the excellent silk-screen and your eyes open construction will be painless. Note that you don’t need to install R4 unless necessary, and if your TV system is PAL add the link which is between the RCA sockets. Speaking of which, when soldering them in, bend down the legs to lock them in before soldering, as such:
Doing so will keep them nicely flush with the PCB whilst soldering. Once finished you should have something like this:
All there is to do now is click the button covers into place, plug in your video and audio RCA leads to a monitor, insert nine volts of DC power, and go:
Nice one. For the minimalist users out there, be careful if playing games as the solder on the rear of the PCB can be quite sharp. Included with the kit is some adhesive rubber matting to attach to the underside to smooth everything off nicely. However only fit this once you have totally finished with soldering and modifying the board, otherwise it could prove difficult to remove neatly later on. Time to play some games… in the following video you can see how poor my reflexes are when playing Pong and Space Invaders:
[ ... the Hackvision also generates sounds, however my cheap $10 video capture dongle from eBay didn't come through with the audio ... ]
Well that takes me back. There are some more contemporary games and demonstration code available on the Hackvision games web page. For the more involved Hackvision gamer, there are points on the PCB to attach your own hand-held controls such as paddles, nunchuks and so on. There is a simple tutorial on how to make your own paddles here.
Those who have been paying attention will have noticed that although the Hackvision PCB is not the standard Arduino Duemilanove-compatible layout, all the electronics are there. Apart from I/O pins used by the game buttons, you have a normal Arduino-style board with video and audio out. This opens up a whole world of possibilities with regards to the display of data in your own Arduino sketches (software). From a power supply perspective, note that the regulator is a 78L05 which is only good for 100mA of current, and the board itself uses around 25mA.
To control the video output, you will need to download and install the hackvision-version arduino-tvout library. Note that this library is slightly different to the generic arduino-tvout library with regards to function definitions and parameters. To make use of the included buttons easier, there is also the controllers library. Here is a simple, relatively self-explanatory sketch that demonstrates some uses of the tvout functions (download):
/* nootropics Hackvision display demo two http://tronixstuff.wordpress.com > kit reviews John Boxall 13 May 2011 | CC by-sa */
#include "avr/pgmspace.h" #include "TVout.h" #include "video_gen.h" #include "EEPROM.h" #include "Controllers.h"
int x,y=0;
int d=500; // used for various delays
// declare screen resolution
#define W 136
#define H 98
// create instance of TV
TVout tv;
void setup() {
// If pin 12 is pulled LOW, then the PAL jumper is shorted.
pinMode(12, INPUT);
digitalWrite(12, HIGH);
if (digitalRead(12) == LOW) {
tv.begin(_PAL, W, H);
// Since PAL processing is faster, we need to slow the game play down.
}
else {
tv.begin(_NTSC, W, H);
}
randomSeed(analogRead(0));
}
void randomPixels()
{
tv.clear_screen(); // clears the screen
for (int a=0; a<500; a++)
{
x=random(128);
y=random(96);
tv.set_pixel(x,y,1); // 1 for white, 0 for black, 2 for inverse of current colour at that location
delay(10);
}
}
void randomLines()
{
tv.clear_screen(); // clears the screen
for (int a=0; a<128; a++)
{
tv.draw_line(a,1,a,96,1); // x,y to x,y, colour 1 = white
delay(50);
}
}
void rectangles()
{
tv.clear_screen(); // clears the screen
for (int a=0; a<30; a++)
{
x=random(128);
y=random(96);
tv.draw_box(x,y,x+10,y+10,1,0,0,1); // top-left x,y, length, width, colour, fill (0 = no, 1 = yes)
delay(50);
tv.draw_box(x,y,x+10,y+10,1,1,0,1); // top-left x,y, length, width, colour, fill (0 = no, 1 = yes)
delay(50);
}
}
void circles()
{
tv.clear_screen(); // clears the screen
for (int a=0; a<30; a++)
{
x=random(128);
y=random(96);
tv.draw_circle(x,y,a,1,0,1); // x,y coordinates, radius, line colour, fill
delay(50);
tv.draw_circle(y,x,a,1,1,1);
delay(50);
}
}
void loop()
{
randomPixels();
delay(d);
randomLines();
delay(d);
rectangles();
delay(d);
circles();
delay(d);
}
And the resulting video demonstration:
I will be the first to admit that my imagination is lacking some days. However with the sketch above hopefully you can get a grip on how the functions work. But there are some very good game implementations out there, as listed on the Hackvision games page. After spending some time with this kit, I feel that there is a lack of documentation that is easy to get into. Sure, having some great games published is good but some beginners’ tutorials would be nice as well. However if you have the time and the inclination, there is much that could be done. In the meanwhile you can do your own sleuthing with regards to the functions by examining the TVout.cpp file in the Hackvision tvout library folder.
For further questions about the Hackvision contact nootropic design or perhaps post on their forum. However the Hackvision has a lot of potential and is an interesting extension of the Arduino-based hardware universe – another way to send data to video monitors and televisions, and play some fun games. The Hackvision is available from Little Bird Electronics. If you are looking for a shield-based video output device, perhaps consider the Batsocks Tellymate.
As always, thank you for reading and I look forward to your comments and so on. Furthermore, don’t be shy in pointing out errors or places that could use improvement. Please subscribe using one of the methods at the top-right of this web page to receive updates on new posts, follow me on twitter or facebook, or join our Google Group for further discussion.
High resolution images are available on flickr.
[Note - The kit was purchased by myself personally and reviewed without notifying the manufacturer or retailer]
Otherwise, have fun, be good to each other – and make something!
Tutorial: Arduino and the SPI bus
Learn how to use the SPI data bus with Arduino in chapter thirty-four of a series originally titled “Getting Started/Moving Forward with Arduino!” by John Boxall – A seemingly endless tutorial on the Arduino universe. The first chapter is here, the complete series is detailed here.
[Updated 10/01/2013]
This is the first of two chapters in which we are going to start investigating the SPI data bus, and how we can control devices using it with our Arduino systems. The SPI bus may seem to be a complex interface to master, however with some brief study of this explanation and practical examples you will soon become a bus master! To do this we will learn the necessary theory, and then apply it by controlling a variety of devices. In this tutorial things will be kept as simple as possible.
But first of all, what is it? And some theory…
SPI is an acronym for “Serial Peripheral Interface”. It is a synchronous serial data bus – data can travel in both directions at the same time, as opposed to (for example) the I2C bus that cannot do so. To allow synchronous data transmission, the SPI bus uses four wires. They are called:
- MOSI – Master-out, Slave-in. This line carries data from our Arduino to the SPI-controlled device(s);
- MISO – Master-in, Slave out. This line carries data from the SPI-controlled device(s) back to the Arduino;
- SS – Slave-select. This line tells the device on the bus we wish to communicate with it. Each SPI device needs a unique SS line back to the Arduino;
- SCK – Serial clock.
Within these tutorials we consider the Arduino board to be the master and the SPI devices to be slaves. On our Arduino Duemilanove/Uno and compatible boards the pins used are:
- SS – digital 10. You can use other digital pins, but 10 is generally the default as it is next to the other SPI pins;
- MOSI – digital 11;
- MISO – digital 12;
- SCK – digital 13;
Arduino Mega users – MISO is 50, MOSI is 51, SCK is 52 and SS is usually 53. If you are using an Arduino Leonardo, the SPI pins are on the ICSP header pins. See here for more information. You can control one or more devices with the SPI bus. For example, for one device the wiring would be:
Data travels back and forth along the MOSI and MISO lines between our Arduino and the SPI device. This can only happen when the SS line is set to LOW. In other words, to communicate with a particular SPI device on the bus, we set the SS line to that device to LOW, then communicate with it, then set the line back to HIGH. If we have two or more SPI devices on the bus, the wiring would resemble the following:
Notice how there are two SS lines – we need one for each SPI device on the bus. You can use any free digital output pin on your Arduino as an SS line. Just remember to have all SS lines high except for the line connected to the SPI device you wish to use at the time.
Data is sent to the SPI device in byte form. You should know by now that eight bits make one byte, therefore representing a binary number with a value of between zero and 255. When communicating with our SPI devices, we need to know which way the device deals with the data – MSB or LSB first. MSB (most significant bit) is the left-hand side of the binary number, and LSB (least significant bit) is the right-hand side of the number. That is:
Apart from sending numerical values along the SPI bus, binary numbers can also represent commands. You can represent eight on/off settings using one byte of data, so a device’s parameters can be set by sending a byte of data. These parameters will vary with each device and should be illustrated in the particular device’s data sheet. For example, a digital potentiometer IC with six pots:
This device requires two bytes of data. The ADDR byte tells the device which of six potentiometers to control (numbered 0 to 5), and the DATA byte is the value for the potentiometer (0~255). We can use integers to represent these two values. For example, to set potentiometer number two to 125, we would send 2 then 125 to the device.
How do we send data to SPI devices in our sketches?
First of all, we need to use the SPI library. It is included with the default Arduino IDE installation, so put the following at the start of your sketch:
#include "SPI.h"
Next, in void.setup() declare which pin(s) will be used for SS and set them as OUTPUT. For example,
pinMode(ss, OUTPUT);
where ss has previously been declared as an integer of value ten. Now, to activate the SPI bus:
SPI.begin();
and finally we need to tell the sketch which way to send data, MSB or LSB first by using
SPI.setBitOrder(MSBFIRST);
or
SPI.setBitOrder(LSBFIRST);
When it is time to send data down the SPI bus to our device, three things need to happen. First, set the digital pin with SS to low:
digitalWrite(SS, LOW);
Then send the data in bytes, one byte at a time using:
SPI.transfer(value);
Value can be an integer/byte between zero and 255. Finally, when finished sending data to your device, end the transmission by setting SS high:
digitalWrite(ss, HIGH);
Sending data is quite simple. Generally the most difficult part for people is interpreting the device data sheet to understand how commands and data need to be structured for transmission. But with some practice, these small hurdles can be overcome.
Now for some practical examples!
Time to get on the SPI bus and control some devices. By following the examples below, you should gain a practical understanding of how the SPI bus and devices can be used with our Arduino boards.
Example 34.1
Our first example will use a simple yet interesting part – a digital potentiometer (we also used one in the I2C tutorial). This time we have a Microchip MCP4162-series 10k rheostat:
Here is the data sheet.pdf for your perusal. To control it we need to send two bytes of data – the first byte is the control byte, and thankfully for this example it is always zero (as the address for the wiper value is 00h [see table 4-1 of the data sheet]). The second byte is the the value to set the wiper, which controls the resistance. So to set the wiper we need to do three things in our sketch…
First, set the SS (slave select) line to low:
digitalWrite(10, LOW);
Then send the two byes of data:
SPI.transfer(0); // command byte
SPI.transfer(value); // wiper value
Finally set the SS line back to high:
digitalWrite(10, HIGH);
Easily done. Connection to our Arduino board is very simple – consider the MCP4162 pinout:
Vdd connects to 5V, Vss to GND, CS to digital 10, SCK to digital 13, SDI to digital 11 and SDO to digital 12. Now let’s run through the available values of the MCP4162 in the following sketch (download):
/*
Example 34.1 - SPI bus demo using a Microchip MCP4162 digital potentiometer [http://bit.ly/iwDmnd]
http://tronixstuff.com/tutorials > chapter 34 | CC by-sa-nc | John Boxall
*/
#include "SPI.h" // necessary library
int ss=10; // using digital pin 10 for SPI slave select
int del=200; // used for various delays
void setup()
{
pinMode(ss, OUTPUT); // we use this for SS pin
SPI.begin(); // wake up the SPI bus.
SPI.setBitOrder(MSBFIRST);
// our MCP4162 requires data to be sent MSB (most significant byte) first
}
void setValue(int value)
{
digitalWrite(ss, LOW);
SPI.transfer(0); // send command byte
SPI.transfer(value); // send value (0~255)
digitalWrite(ss, HIGH);
}
void loop()
{
for (int a=0; a<256; a++)
{
setValue(a);
delay(del);
}
for (int a=255; a>=0; --a)
{
setValue(a);
delay(del);
}
}
Now to see the results of the sketch. In the following video clip, a we run up through the resistance range and measure the rheostat value with a multimeter:
Before moving forward, if digital potentiometers are new for you, consider reading this short guide written by Microchip about the differences between mechanical and digital potentiometers.
Example 34.2
In this example, we will use the Analog Devices AD5204 four-channel digital potentiometer (data sheet.pdf). It contains four 10k ohm linear potentiometers, and each potentiometer is adjustable to one of 256 positions. The settings are volatile, which means they are not remembered when the power is turned off. Therefore when power is applied the potentiometers are all pre set to the middle of the scale. Our example is the SOIC-24 surface mount example, however it is also manufactured in DIP format as well.
To make life easier it can be soldered onto a SOIC breakout board which converts it to a through-hole package:
In this example, we will control the brightness of four LEDs. Wiring is very simple. Pinouts are in the data sheet.pdf.
And the sketch (download):
// Example 34.2 - SPI bus demo using Analog Devices AD5204 digital potentiometer
#include <SPI.h> // necessary library int ss=10; // using digital pin 10 for SPI slave select int del=5; // used for fading delay
void setup()
{
pinMode(ss, OUTPUT); // we use this for SS pin
SPI.begin(); // wake up the SPI bus.
SPI.setBitOrder(MSBFIRST);
// our AD5204 requires data to be sent MSB (most significant byte) first. See data sheet page 5
allOff(); // we do this as pot memories are volatile
}
void allOff()
// sets all potentiometers to minimum value
{
for (int z=0; z<4; z++)
{
setPot(z,0);
}
}
void allOn()
// sets all potentiometers to maximum value
{
for (int z=0; z<4; z++)
{
setPot(z,255);
}
}
void setPot(int pot, int level)
// sets potentiometer 'pot' to level 'level'
{
digitalWrite(ss, LOW);
SPI.transfer(pot);
SPI.transfer(level);
digitalWrite(ss, HIGH);
}
void blinkAll(int count)
{
for (int z=0; z
void indFade()
{
for (int a=0; a<4; a++)
{
for (int l=0; l<255; l++)
{
setPot(a,l);
delay(del);
}
for (int l=255; l>=0; --l)
{
setPot(a,l);
delay(del);
}
}
}
void allFade(int count)
{
for (int a=0; a<count; a++)="" {="" for="" (int="" l="0;" l<255;="" l++)="" setpot(0,l);="" setpot(1,l);="" setpot(2,l);="" setpot(3,l);="" delay(del);="" }="">=0; --l)
{
setPot(0,l);
setPot(1,l);
setPot(2,l);
setPot(3,l);
delay(del);
}
}
}
void loop()
{
blinkAll(3);
delay(1000);
indFade();
allFade(3);
}
The function allOff() and allOn() are used to set the potentiometers to minimum and maximum respectively. We use allOff() at the start of the sketch to turn the LEDs off. This is necessary as on power-up the wipers are generally set half-way. Furthermore we use them in the blinkAll() function to … blink the LEDs. The function setPot() accepts a wiper number (0~3) and value to set that wiper (0~255). Finally the function indFade() does a nice job of fading each LED on and off in order – causing an effect very similar to pulse-width modulation.
Finally, here it is in action:
Example 34.3
In this example, we will use use a four-digit, seven-segment LED display that has an SPI interface. Using such a display considerably reduces the amount of pins required on the micro controller and also negates the use of shift register ICs which helps reduce power consumption and component count. The front of our example:
and the rear:
Thankfully the pins are labelled quite clearly. Please note that the board does not include header pins – they were soldered in after receiving the board. Although this board is documented by Sparkfun there seems to be issues in the operation, so instead we will use a sketch designed by members of the Arduino forum. Not wanting to ignore this nice piece of hardware we will see how it works and use it with the new sketch from the forum.
Again, wiring is quite simple:
- Board GND to Arduino GND
- Board VCC to Arduino 5V
- Board SCK to Arduino D12
- Board SI to Arduino D11
- Board CSN to Arduino D10
The sketch is easy to use, you need to replicate all the functions as well as the library calls and variable definitions. To display numbers (or the letters A~F) on the display, call the function
write_led(a,b,c);
where a is the number to display, b is the base system used (2 for binary, 8 for octal, 10 for usual, and 16 for hexadecimal), and c is for padded zeros (0 =off, 1=on). If you look at the void loop() part of the example sketch, we use all four number systems in the demonstration. If your number is too large for the display, it will show OF for overflow. To control the decimal points, colon and the LED at the top-right the third digit, we can use the following:
write_led_decimals(1); // left-most decimal point write_led_decimals(2); write_led_decimals(4); write_led_decimals(8); // right-most decimal point write_led_decimals(16); // colon LEDs write_led_decimals(32); // apostrophe LED write_led_decimals(0); // off
After all that, here is the demonstration sketch for your perusal (download):
/* Example 34.3 - SPI bus demo using SFE 4-digit LED display [http://bit.ly/ixQdbT] http://tronixstuff.com/tutorials > chapter 34 Based on code by Quazar & Busaboi on Arduio forum - http://bit.ly/iecYBQ */
#define DATAOUT 11 //MOSI #define DATAIN 12 //MISO - not used, but part of builtin SPI #define SPICLOCK 13 //sck #define SLAVESELECT 10 //ss
char spi_transfer(volatile char data)
{
SPDR = data; // Start the transmission
while (!(SPSR & (1<
{
};
return SPDR; // return the received byte
}
void setup()
{
byte clr;
pinMode(DATAOUT, OUTPUT);
pinMode(DATAIN, INPUT);
pinMode(SPICLOCK, OUTPUT);
pinMode(SLAVESELECT, OUTPUT);
digitalWrite(SLAVESELECT, HIGH); //disable device
SPCR = (1<
clr=SPSR;
clr=SPDR;
delay(10);
write_led_numbers(0x78,0x78,0x78,0x78); //Blank display
write_led_decimals(0x00); // All decimal points off
}
void write_led_decimals(int value)
{
digitalWrite(SLAVESELECT, LOW);
delay(10);
spi_transfer(0x77); // Decimal Point OpCode
spi_transfer(value); // Decimal Point Values
digitalWrite(SLAVESELECT, HIGH); //release chip, signal end transfer
}
void write_led_numbers(int digit1, int digit2, int digit3, int digit4)
{
digitalWrite(SLAVESELECT, LOW);
delay(10);
spi_transfer(digit1); // Thousands Digit
spi_transfer(digit2); // Hundreds Digit
spi_transfer(digit3); // Tens Digit
spi_transfer(digit4); // Ones Digit
digitalWrite(SLAVESELECT, HIGH); //release chip, signal end transfer
}
void write_led(unsigned short num, unsigned short base, unsigned short pad)
{
unsigned short digit[4] = {
0, ' ', ' ', ' ' };
unsigned short place = 0;
if ( (base<2) || (base>16) || (num>(base*base*base*base-1)) ) {
write_led_numbers(' ', 0x00, 0x0f, ' '); // indicate overflow
}
else {
while ( (num || pad) && (place<4) ) {
if ( (num>0) || pad )
digit[place++] = num % base;
num /= base;
}
write_led_numbers(digit[3], digit[2], digit[1], digit[0]);
}
}
void pointDemo()
{
write_led_decimals(1);
delay(1000);
write_led_decimals(2);
delay(1000);
write_led_decimals(4);
delay(1000);
write_led_decimals(8);
delay(1000);
write_led_decimals(16);
delay(1000);
write_led_decimals(32);
delay(1000);
write_led_decimals(0); // non-digits all off
}
void loop()
{
pointDemo();
delay(500);
for (int i = 0; i < 100; i++) {
write_led (i,10,1);
delay(25);
}
delay(500);
for (int i = 100; i >=0; --i) {
write_led (i,10,0);
delay(25);
}
delay(500); // now binary
for (int i = 0; i < 16; i++) {
write_led (i,2,0);
delay(100);
}
delay(500);
for (int i = 15; i >=0; --i) {
write_led (i,2,0);
delay(100);
}
delay(500); // now octal
for (int i = 0; i < 500; i++) {
write_led (i,8,0);
delay(50);
}
delay(500);
// now hexadecimal
for (int i = 20000; i < 22000; i++) {
write_led (i,16,0);
delay(50);
}
delay(500);
}
And a short video of the demonstration:
So there you have it – hopefully an easy to understand introduction to the world of the SPI bus and how to control the devices within. As always, now it is up to you and your imagination to find something to control or get up to other shenanigans. In the next SPI article we will look at reading and writing data via the SPI bus.
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.
Otherwise, have fun, stay safe, be good to each other – and make something!
Discovering Arduino’s internal EEPROM lifespan
How long does the internal EEPROM of an Atmel ATmega328 last for? Let’s find out…
Updated 18/03/2013
Some time ago I published a short tutorial concerning the use of the internal EEPROM belonging to the Atmel ATmega328 (etc.) microcontroller in our various Arduino boards. Although making use of the EEPROM is certainly useful, it has a theoretical finite lifespan – according to the Atmel data sheet (download .pdf) it is 100,000 write/erase cycles.
One of my twitter followers asked me “is that 100,000 uses per address, or the entire EEPROM?” – a very good question. So in the name of wanton destruction I have devised a simple way to answer the question of EEPROM lifespan. Inspired by the Dangerous Prototypes’ Flash Destroyer, we will write the number 170 (10101010 in binary) to each EEPROM address, then read each EEPROM address to check the stored number. The process is then repeated by writing the number 85 (01010101 in binary) to each address and then checking it again. The two binary numbers were chosen to ensure each bit in an address has an equal number of state changes.
After both of the processes listed above has completed, then the whole lot repeats. The process is halted when an incorrectly stored number is read from the EEPROM – the first failure. At this point the number of cycles, start and end time data are shown on the LCD.
In this example one cycle is 1024 sequential writes then reads. One would consider the entire EEPROM to be unusable after one false read, as it would be almost impossible to keep track of individual damaged EEPROM addresses. (Then again, a sketch could run a write/read check before attempting to allocate data to the EEPROM…)
If for some reason you would like to run this process yourself, please do not do so using an Arduino Mega, or another board that has a fixed microcontroller. (Unless for some reason you are the paranoid type and need to delete some data permanently). Once again, please note that the purpose of this sketch is to basically destroy your Arduino’s EEPROM. Here is the sketch to download.
If you are unfamiliar with the time-keeping section, please see part one of my Arduino+I2C tutorial. The LCD used was my quickie LCD shield – more information about that here. Or you could always just send the data to the serial monitor box – however you would need to leave the PC on for a loooooong time… So instead the example sat on top of an AC adaptor (wall wart) behind a couch (sofa) for a couple of months:
The only catch with running it from AC was the risk of possible power outages. We had one planned outage when our house PV system was installed, so I took a count reading before the mains was turned off, and corrected the sketch before starting it up again after the power cut. Nevertheless, here is a short video – showing the start and the final results of the test:
So there we have it, 1230163 cycles with each cycle writing and reading each individual EEPROM address. If repeating this odd experiment, your result will vary.
Well I hope someone out there found this interesting. Please refrain from sending emails or comments criticising the waste of a microcontroller – this was a one off.
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.
May 2011 Competition
Hello Readers
The May competition has now closed and the results will be published shortly. Thank you to all those who entered in May!
Another month has commenced and that means time for another competition! To enter is very easy. There will be five(!) questions hidden within articles published in the month of May (but not this one!). Once you have answers to all five, email them to competition at tronixstuff dot com with “May 2011″ in the subject line. Then in the first week of June, I will compile a list of people with the correct answers, and randomly select two winners. Please note competition rules at end of article.
The first winner drawn will receive a brand new, hot off the pick and place – Freetronics EtherTen!
The EtherTen must be the ultimate Arduino-Uno compatible board on the market. From the Freetronics website:
Two tastes that taste great together: Arduino and Ethernet. But until now the only way to connect an Arduino to the Internet via a LAN was to add an Ethernet Shield. Wouldn’t it be great if there was an Arduino-compatible board with on-board Ethernet? Better still, what if that board was based on the Freetronics Eleven and the Freetronics Ethernet Shield (with Power-over-Ethernet support!) but merged together into a single, integrated board that was 100% Arduino compatible and network-enabled?
This, folks, is what you’ve been waiting for.
The EtherTen is a 100% Arduino compatible board that can talk to the world. Do Twitter updates automatically, serve web pages, connect to web services, display sensor data online, and control devices using a web browser. The Freetronics EtherTen uses the same ATmega328P as the Duemilanove and the same Wiznet W5100 chip used by the official Arduino Ethernet Shield, so it’s 100% compatible with the Ethernet library and sketches. Any project you would previously have built with an Arduino and an Ethernet shield stacked together, you can now do all in a single, integrated board.
We’ve even added a micro SD card slot so you can store web content on the card, or log data to it.
All the good things about the Eleven and the Ethernet Shield have been combined into this one device so please see those pages for all the specific details, but the highlights include:
- Gold-plated PCB.
- Top and bottom parts overlays.
- Top-spec ATmega328P MCU.
- Mini-USB connector: no more shorts against shields!
- D13 pin isolated with a MOSFET so you can use it as an input.
- Power-over-Ethernet support, both cheapie DIY or full 802.3af standards-compliant.
- Ethernet activity indicators on the PCB and the jack.
- 10/100base-T auto-selection.
- Fully compatible with standard Ethernet library.
- Reset management chip.
- Fixed SPI behavior on Ethernet chipset.
- Robust power filtering.
- Sexy rounded corners. Hmm.
As with any other competition, there needs to be some rules:
- Prizes will be delivered via Australia Post domestic or regular international air mail. Winners may elect for other methods upon payment of real cost;
- Winners outside of Australia will be responsible for any taxes, fees or levies imposed by your local Governments (such as import levies, excise, VAT, etc.) upon importation of purchased goods;
- Prizes may take up to 45 days to be received;
- If you have won a previous competition you cannot enter;
- The Judge’s decision is final with regards to any dispute;
- Entries will be accepted until 2359h GMT on 3rd June 2011.
So have fun and keep checking into tronixstuff.com. Why not follow things on twitter, 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.
Once again, thank you to our generous competition sponsor Freetronics
April 2011 Competition – Results
Hello readers
The month of April has ended and thus another monthly tronixstuff.com competition. There were six questions hidden within the posts, and once again all entrants were correct with their answers. Questions for April were:
- Name the two people who founded the predecessor to Agilent Technologies – Bill Hewlett and Dave Packard;
- Name the magazine that originally described this kit (Current clamp meter adaptor) – Silicon Chip;
- What does the acronym FTDI mean – Future Technology Devices International;
- What is the mains power frequency in Australia? 50 Hz;
- What is the name of the Evil Mad Science Arduino-compatible development board – Diavolino;
- Unit of measurement for elastance – the daraf.
The first winner drawn will receves a full PoGa system bundle courtesy of 4D Systems, an Australian-based company who are a worldwide leader in the development and manufacture of intelligent graphic display modules.
What is a PoGa you may ask? Here is an example:
As you can see, the PoGa is an amazing piece of work. The people at 4D Systems have really put together a fun and accessible way to develop your own games. However the PoGa is a lot more powerful than the retail price would suggest:
PoGa Features:
- Single chip, low cost educational game development platform, incorporating the tiny GOLDELOX-PoGa graphics processor chip.
- Comes in an easy to build kit form with very low parts count and cost: GOLDELOX-PoGa chip, 6 buttons, Colour LCD-TFT, Battery Holder and few discrete components.
- Display: 1.44″, 128xRGBx128 resolution, 65K colour TFT-LCD (directly interfaced to the GOLDELOX-PoGa chip).
- Colours: 65K simultaneous colours.
- microSD Card Interface: Supports the PoGa-Disk which can store and load up to 512 games and other applications as well as images and video clips. It can also be used as a storage medium for data logging applications during run time.
- Sound Support: Single channel sound engine with extended RTTTL format and allows complex generation of game sounds.
- Console: Layout fashion follows most standard game consoles with 6 buttons for game and non game related application control.
- Expandable: Power and UART lines are available via 8pin expansion port.
- Battery: Supports 3 x AAA batteries for mobility (hight capacity alkaline or lithium recommended).
- Supports the high level 4DGL language platform, syntax very similar to C.
- Software Tools: Free fully integrated 4D Workshop3 IDE software development tool suite.
- RoHS compliant.
PoGa Specifications:
- CPU: GOLDELOX-PoGa chip.
- Total RAM: 510 bytes (or 255 word sized variables).
- Program Memory: 11K bytes (more than adequate for all PoGa applications).
- Speed: 12Mips (internal).
- Screen: 1.44″ LCD-TFT, with greater than 160deg viewing angle.
- Resolution: 128 x RGB x 128 pixels.
- Colours: 65K colours. Pixels arranged in a 5:6:5 colour format (Red:5 bits, Green:6 bits, Blue: 5 bits).
- Graphics:Supports all primitives such as:
- Lines, Circles, Rectangles, Dots, Triangles
- Chars, Strings, Text Buttons
- Images and Video clips.
- Sprites: Up to 64 sprites can be defined, simultaneous display of sprites is unlimited.
- Sound: Single channel mono, supports extended RTTTL format and allows complex generation of game sounds.
- Console: 4 x Navigation keys, 2 x Selection keys.
- PoGa-Disk: microSD card interface that supports most uSD memory cards for video, images, game and application storage. 2Gb and larger size cards can support PoGa file system application storage.
- Expansion: External expansion port, (RX, TX, VBat, 3.3V and GND).
The first prize not only includes a fully-assembled PoGa unit, to enable extended application and experimentation with their PoGa the winner also receives a USB programming cable, external breakout board and the GPS receiver module as shown below:
The second prize winner receives exactly the same as the first! Except for being the review hardware used to play… test out the PoGa here at tronixstuff. Nevertheless both winners will have a ball playing the sample games, or spending time to develop their own games, quizzes, possible GPS applications including reverse geocaching, and so on. In the next week I will review the PoGa system in more detail and document my experience with it.
To get your hands on a PoGa, they can be ordered directly from 4DSystems, Little Bird Electronics, Sparkfun and their resellers, or Tigal for EU customers.
So have fun and keep checking into tronixstuff.com. Why not follow things on twitter, 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.
Once again, thank you to our generous competition sponsor 4D Systems!
Kit review – High Accuracy LC Meter
Hello readers
Time for another kit review. Lately one of my goals has been to make life easier and in doing so having some decent test equipment. One challenge of meeting that goal is (naturally) keeping the cost of things down to a reasonable level. Unfortunately my eyesight is not the best so I cannot read small capacitor markings – which makes a capacitance meter necessary. Although I have that function within my multimeter, it is often required to read resistors in the same work session.
Thus the reason for this kit review. A day trip to Altronics saw me return with (amongst other things) their High Precision LC Meter kit. The details were originally published in the May 2008 issue of Australia’s Silicon Chip magazine. The meter specifications are:
- Capacitance – 0.1pF to over 800 nF with four-digit resolution;
- Inductance – 10 nH to over 70 mH with four-digit resolution;
- Accuracy of better than +/- 1% of the reading;
- Automatic range selection, however only non-polarised capacitors can be measured.
The power drain is quite low, between 8 (measurement) and 17 milliamps (calibration). Using a fresh 9V alkaline battery you should realise around fifty to sixty hours of continuous use. At this point some of you may be wondering if it is cheaper to purchase an LC meter or make your own. A quick search found the BK Precision 875B LCR meter with the same C range and a worse L range for over twice the price of the kit. Although we don’t have resistance measurement in our kit, if you are building this you already have a multimeter. So not bad value at all. And you can say you built it
Speaking of building, assembly time was just under two hours, and the kit itself is very well produced. The packaging was the typical retail bag:
The first thing that grabs your attention is the housing. It is a genuine, made in the US Hammond enclosure – and has all the required holes and LCD area punched out, so you don’t need to do any drilling at all:
The enclosure has nice non-slip rubberised edging (the grey area) and also allows for a 9V battery to be housed securely. The team at Altronics have done a great job in redesigning the kit for this enclosure, much more attractive than the magazine version. The PCB is solder-masked and silk-screened to fine standard:
There are two small boards to cut and file off from the main PCB. We will examine them later in the article. All required parts for completion were included, and it is good to see 1% resistors and an IC socket for the microcontroller:
At first I was a little disappointed to not have a backlit LCD module, however considering the meter is to be battery operated (however there is a DC socket for a plugpack) and you wouldn’t really be using this in the dark, a backlight wouldn’t be necessary. Construction was easy enough, the layout on the PCB is well labelled, and plenty of space between pins. Lately I have started using a lead-former, and can highly recommend the use of one:
Assembly was quite simple, just start with the lower profile components:
… then mount the LCD and the larger components:
… the switches and others – and we’re done:
The only problem at this point was the PCB holes for the selector switch, one hole was around 1mm from where it needed to be. Instead of drilling out the hole, it was easier to just bend up the legs of the switch and keep going:
At this stage one has to cut out two supports from the enclosure, which can be done easily. Then insert the PCB and solder to the sockets and power (9V battery snap). Initial testing was successful (after adjusting the LCD contrast…):
If you look at the area of PCB between the battery and the left-hand screw there are eight pins – these are four pairs of inputs used to help calibrate and check operation of the meter. For example, by placing a jumper over a pair you can display the oscillator frequency at various stages:
Furthermore, those links can also be used to fine-tune the meter. For example one can increase or decrease the scaling factor and the settings are then stored in the EEPROM within the microcontroller. However my example seemed ok from the start, so it was time to seal up the enclosure and get testing. Starting with a ceramic capacitor, the lowest value in stock:
Spot-on. That was a good start, however trying to bend the leads to match the binding posts was somewhat inconvenient, so I cut up some leads and fitted crocodile clips on the end. The meter’s zero button allows you to reset the measurement back to zero after attaching the leads, so stray capacitance can be taken into account.
Next, time to check the measurement with something more accurate, a 1% tolerance silvered-mica 100 picofarad capacitor:
Again, the meter came through right on specification. My apologies to those looking for inductor tests – I don’t have any in stock to try out. If you are really curious I could be persuaded to order some in, however as the capacitance measurement has been successful I am confident the inductance measurement would also fall within the meter’s specifications.
As shown earlier, there were two smaller PCBs included:
The top PCB is a shorting bar used to help zero the inductance reading, and the lower PCB is used to help measure smaller capacitors and also SMD units. A nice finishing touch that adds value to the meter. The only optional extra to consider would be a set of short leads with clips or probes to make measurement physically easier.
When reading this kit review it may appear to be somewhat positive and not critical at all. However it really is a good instrument, considering the accuracy, price, and enjoyment from doing it yourself. It was interesting, easy to build, and will be very useful now and in the future. So if you are in the market for an LC meter, and don’t mind some work – you should add this kit to your checklist for consideration. It is available from Altronics stores and resellers.
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.
Kit review – Evil Mad Science Larson Scanner
Hello readers
Time yet again for another kit review. Today’s kit is the Larson Scanner from Evil Mad Science. What a different name for a company; their byline is “DIY and open source hardware for art, education and world domination”. Art? Yes. Education? Definitely. World domination? Possibly – you could use the blinking LEDs to hypnotise the less intelligent world leaders out there.
Anyhow, what is a Larson Scanner? Named in honour of Glen A. Larson the creator of television shows such as Battlestar Galactica and Knight Rider – as this kit recreates the left and right blinking motion used in props from those television shows. For example:
The kit itself is quite inexpensive, easy to assemble – yet can be as complex as you want it to be. More about that later, for now let’s put one together and see how it performs. There are two versions of the kit, one with 5mm clear LEDs and our review model with 10mm diffused red LEDs. The kit arrives inside a huge resealable anti-static bag, as such:
Upon opening the bag we have the following parts (there was an extra LED and resistor, thanks):
… the PCB:
… which is nicely done with a good silk-screen and solder mask. And finally:
A very handy item – a battery box with power switch. The kit is powered by 2 x AA cells (not included!). And finally, the instructions:
At this point you can see that this kit is designed for the beginner in mind. The instructions are easy to read, clear, and actually very well done. If you are looking for a kit to get someone interested in electronics and to practice their soldering, you could do a lot worse than use this kit.
Construction was very easy, starting with the resistors:
followed by the capacitor and button:
then the microcontroller:
… no IC socket. For a beginners’ kit, perhaps one should have been included. Next was the battery box. Some clever thinking has seen holes in the PCB to run the wires through before soldering into the board – doing so provides a good strain relief for them:
… and finally the LEDs. Beginners may solder them in one at a time:
however it is quicker to line them up all at once than solder in one batch:
… which leaves us with the final product:
Operation is very simple – the power switch is on the battery box. The button on the PCB controls the speed of LED scrolling, and if held down switches the brightness between low and high. Now for some action video of the Larson Scanner in operation:
Well that really was fun, a nice change from the usual things around here.
After sitting my Larson Scanner next to the computer tower for a few minutes, I had contemplated fitting it into a 5.25″ drive bay to make my own Cylon PC, however that might be a little over the top. However my PC case has some dust filters on the front, which would allow LEDs to shine through in a nicely subdued way. Mounting the Larson Scanner PCB inside the computer case will be simple, and power can be sourced from the computer power supply – 5V is available from a disk drive power lead.
If you are going to modify your PC in a similar fashion, please read my disclaimer under “boring stuff” first.
The Larson Scanner can run on 3.3V without any alteration to the supplied components. What needs to be done is to use a voltage regulator to convert the 5V down to 3.3V. My example has used a 78L33 equivalent, the TI LP2950 as it is in stock. The power comes from a drive power cable splitter as such:
You may have a spare power plug in your machine, so can tap from that. 5V is the red lead, and GND is the adjacent black lead. Don’t use yellow – it is 12V. It is then a simple matter of running 5V from the red lead to pin 1 of the regulator, GND from the Larson Scanner and PC together to pin 2, and 3.3V out from the regulator to the PCB 3.3V. Insulation is important with this kind of work, so use plenty of heatshrink:
… then cover the whole lot up:
Now to locate a free power plug in the machine. It has been a while since opening the machine – time for a dust clean up as well:
Mounting the PCB is a temporary affair until I can find some insulated mounting standoffs:
However it was worth the effort, the following video clip shows the results in action:
So there you have it. The Larson Scanner is an ideal kit for the beginner, lover of blinking LEDs, and anyone else that wants to have some easy blinking fun. You can buy Larson Scanner kits in Australia from Little Bird Electronics, or directly from Evil Mad Science for those elsewhere.

As always, thank you for reading and I look forward to your comments and so on. Furthermore, don’t be shy in pointing out errors or places that could use improvement. Please subscribe using one of the methods at the top-right of this web page to receive updates on new posts, follow me on twitter or facebook, or join our Google Group for further discussion.
High resolution images are available on flickr.
[Note - The kit was purchased by myself personally and reviewed without notifying the manufacturer or retailer]
Otherwise, have fun, be good to each other – and make something! ![]()

































































