Tag Archive | "project"

Project – Arduino “Book Monster”


Recently we saw a neat project by the people from Evil Mad Scientist – their “Peek-O-Book“, a neat take on a book with a shy monster inside, based on hardware from their Snap-O-Lantern kit. Not wanting to fork out for the postage to Australia we decided to make our own version, of which you can follow along.

This is a fun project that doesn’t require too much effort and has a lot of scope for customisation. There’s no right or wrong when making your own (or this one!) so just have fun with it.


First, you’ll need a book of some sort, something large enough to hide the electronics yet not too large to look “suspicious” – then cut the guts out to make enough space for the electronics. Then again it’s subjective, so get whatever works for you. Coincidentally we found some “dummy books” (not books for dummies) that were perfect for the job:

dummy book

After spraying the inside with matt black paint, the inside is better suited for the “eyes in the dark” effect required for the project:

dummy book internal

The “book” had a magnet and matching metal disk on the flap to aid with keep the cover shut, however this was removed as it will not allow for smooth opening with the servo.

The electronics are quite simple if you have some Arduino or other development board experience. Not sure about Arduino? You can use any microcontroller that can control a servo and some LEDs. We’re using a Freetronics LeoStick as it’s really small yet offers a full Arduino Leonardo-compatible experience, and a matching Protostick to run the wires and power from:

Freetronics Leostick and Protostick

By fitting all the external wiring to the Protostick you can still use the main LeoStick for other projects if required. The power is from 4 x AA cells, with the voltage reduced with a 1n4004 diode:

battery power and diode

And for the “eyes” of our monster – you can always add more if it isn’t too crowded in the book:

Arduino LEDs

We’ll need a resistor as well for the LEDs. As LEDs are current driven you can connect two in series with a suitable dropping resistor which allows you to control both if required with one digital output pin. You can use the calculator here to help determine the right value for the resistor.

Finally a servo is required to push the lid of the book up and down. We used an inexpensive micro servo that’s available from Tronixlabs:

Arduino servo

The chopsticks are cut down and used as an extension to the servo horn to give it more length:

Arduino servo mounted

Don’t forget to paint the arm black so it doesn’t stand out when in use. We had a lazy attack and mounted the servo on some LEGO bricks held in with super glue, but it works. Finally, here is the circuit schematic for our final example – we also added a power switch after the battery pack:

book monster schematic small

To recap  – this is a list of parts used:

After some delicate soldering the whole lot fits neatly in the box:

Arduino book monster final

Arduino Sketch

The behaviour of your “book monster” comes down to your imagination. Experiment with the servo angles and speed to simulate the lid opening as if the monster is creeping up, or quickly for a “pop-up” surprise. And again with the LED eyes you can blink them and alter the brightness with PWM. Here’s a quick sketch to give you an idea:

You can watch our example unit in this video.

Frankly the entire project is subjective, so just do what you want.


Well that was fun, and I am sure this will entertain many people. A relative is a librarian so this will adorn a shelf and hopefully give the children a laugh. Once again, thanks to the people from Evil Mad Science for the inspiration for this project – so go and buy something from their interesting range of kits and so on.

And if you enjoyed this article, or want to introduce someone else to the interesting world of Arduino – check out my book (now in a third printing!) “Arduino Workshop”.

visit tronixlabs.com

Have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column, or join our forum – 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.

Posted in arduino, evil mad science, freetronics, leostick, projects, tronixlabs, tronixstuff, tutorialComments (0)

Project – LED Cube Spectrum Analyzer


A few weeks ago I was asked about creating a musical-effect display with an RGB LED cube kit from Freetronics, and with a little work this was certainly possible using the MSGEQ7 spectrum analyser IC. In this project we’ll create a small add-on PCB containing the spectrum analyser circuit and show how it can drive the RGB LED cube kit.

Freetronics CUBE4 RGB LED cube kit

Assumed knowledge

To save repeating myself, please familiarise yourself with the MSGEQ7 spectrum aanalyserIC in Chapter 48 of our Arduino tutorials. And learn more about the LED cube from our review and the product page.

You can get MSGEQ7 ICs from various sources, however they had varying results. We now recommend using the neat module from Tronixlabs.

The circuit

The LED cube already has an Arduino Leonardo-compatible built in to the main PCB, so all you need to do is build a small circuit that contains the spectrum analyzer which connects to the I/O pins on the cube PCB and also has audio input and output connections. First, consider the schematic:

MSGEQ7 CUBE4 spectrum analyser schematic

For the purposes of this project our spectrum analyser will only display the results from one channel of audio – if you want stereo, you’ll need two! And note that the strobe, reset and DCOUT pins on the MSGEQ7 are labelled with the connections to the cube PCB. Furthermore the pinouts for the MSGEQ7 don’t match the physical reality – here are the pinouts from the MSGEQ7 data sheet (.pdf):

MSGEQ7 pinouts

The circuit itself will be quite small and fit on a small amount of stripboard or veroboard. There is plenty of room underneath the cube to fit the circuit if so desired:


With a few moments you should be able to trace out your circuit to match the board type you have, remember to double-check before soldering. You will also need to connect the audio in point after the 1000 pF capacitor to a source of audio, and also pass it through so you can connect powered speakers, headphones, etc.

One method of doing so would be to cut up a male-female audio extension lead, and connect the shield to the GND of the circuit, and the signal line to the audio input on the circuit. Or if you have the parts handy and some shielded cable, just make your own input and output leads:

MSGEQ7 input output leads

Be sure to test for shorts between the signal and shield before soldering to the circuit board. When finished, you should have something neat that you can hide under the cube or elsewhere:

MSGEQ7 RGB cube LED spectrum analyzer board

Double-check your soldering for shorts and your board plan, then fit to the cube along with the audio source and speakers (etc).

Arduino Sketch

The sketch has two main functions – the first is to capture the levels from the MSGEQ7 and put the values for each frequency band into an array, and the second function is to turn on LEDs that represent the level for each band. If you’ve been paying attention you may be wondering how we can represent seven frequency bands with a 4x4x4 LED cube. Simple – by rotating the cube 45 degrees you can see seven vertical columns of LEDs:

MSGEQ7 LED cube spectrum analyzer columns

So when looking from the angle as shown above, you have seven vertical columns, each with four levels of LEDs. Thus the strength of each frequency can be broken down into four levels, and then the appropriate LEDs turned on.

After this is done for each band, all the LEDs are turned off and the process repeats. For the sake of simplicity I’ve used the cube’s Arduino library to activate the LEDs, which also makes the sketch easier to fathom. The first example sketch only uses one colour:

… and a quick video demonstration:

For a second example, we’ve used various colours:

… and the second video demonstration:

A little bit of noise comes through into the spectrum analyser, most likely due to the fact that the entire thing is unshielded. The previous prototype used the Arduino shield from the tutorial which didn’t have this problem, so if you’re keen perhaps make your own custom PCB for this project.

visit tronixlabs.com

Have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column, or join our forum – dedicated to the projects and related items on this website.

Posted in analyzer, arduino, com-10468, cube, freetronics, LED, MSGEQ7, projects, rgb, RGB LED, spectrum, tronixlabs, tronixstuff, tutorial

Build an Arduino-controlled Larson Scanner


For fun and a little bit of learning, let’s make a Larson Scanner. This isn’t a new project, for example we reviewed a kit in the past – however after finding some large LEDs we decided to make our own version. We’ll use an Arduino-compatible circuit to control the LEDs, and explain both the hardware and required Arduino sketch – then build a temporary small and a more permanent large version (and a bonus project).

So what is a Larson Scanner anyway? 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:

Making your own is quite simple, it’s just eight LEDs or lamps blinking in a certain order. If you’re not familiar with the Arduino hardware, please have a quick review of this tutorial before continuing.

Small version

If you’re just interested in whipping up a solderless breadboard or small version, it will take less than fifteen minutes. Just get an Arduino Uno or compatible board and construct the following circuit (the resistors are 560Ω):

Arduino Larson Scanner

The sketch is also very simple. There are two ways to address those digital output pins, and to save sanity and clock cycles we’re going to use port manipulation instead of many digitalWrite() functions. So for our circuit above, enter and upload the following sketch:

Notice how the ones and zeros in the byte send to PORTD (digital pins 7~0) represent the “movement” of the scanner? You’d have to agree this is a better method of addressing the LEDs. Have some fun and experiment with the patterns you can generate and also the delay. In the following video we’ve quickly demonstrated the circuit on a solderless breadboard using different delay periods:

Large Version

Now to make something more permanent, and much larger. There are many ways of completing this project, so the following version will be a design narrative that you can follow to help with planning your own. The first consideration will be the LEDs you want to use. For our example we used some Kingbright DLC2-6SRD 20mm bright red versions we had in stock:


However you can use what you have available. The key to success will be driving the LEDs at their maximum brightness without damage. So you need to find out the best forward voltage and current for the LEDs, then do some basic mathematics. From our example LEDs’ data sheet, the maximum brightness is from 60 mA of current, at just under 6 V. A quick connection to a variable power supply shows the LEDs at this setting:

LED on

We can’t get this kind of brightness from our Arduino 5V circuit, so instead we’ll increase the circuit supply voltage to 9V and use resistors to reduce the current for the LEDs. To find the resistor value, use the following:

resistor formula… where Vs is the supply voltage (9), VLED is the forward voltage for the LED (5.6), and ILED is the forward current (60 mA). The value for R is 56.66 Ω – however you can’t get that value, so 68 Ω will be the closest value from the supplier. Finally, the power of the resistor required (in watts) is calculated by W = VA. So W = 3.4 (voltage drop over resistor) * 0.06 = 0.204 W. So we’ll need 68 Ω 0.25 W resistors for our LEDs. Thus instead of running the LED straight off a digital output, it will be switched on and off via a simple BC548 transistor – shown in the following schematic example:

transistor switchThe digital output for each LED is connected to the 1k Ω resistor and thus switches the transistor on to allow the current to flow through the LED when required. This is repeated for each LED we intend to use – which for the case of our large scanner project is six. (Why six? Someone bought a board which was too narrow for eight…) Next is the Arduino-compatible circuit. Timing isn’t critical so we’ll save components by using a ceramic resonator instead of a crystal and two capacitors. And as shown below (note that although the image on the microcontroller says ATmega168, we’ll use an ATmega328P):

basic Arduino circuit

(If you’re not up for making your own Arduino-compatible circuit, there’s plenty of alternative small boards you can use such as the Nano or LeoStick). Although the symbol for Y1 (the resonator) looks complex, it’s just a resonator – for example:

resonatorthe centre pin goes to GND and the outside pins go to XTAL1 and XTAL2 on the microcontroller. It isn’t polarised so either direction is fine.

At this point you may also want to consider how you’ll upload and update sketches on the project. One method is to mount the microcontroller in a socket, and just yank it between an Arduino board to upload the sketch, and then put it back in the project board. If you use this method then you’ll need a microcontroller with the Arduino bootloader.  However a more civilised method is to add ICSP header pins – they’re the 2 x 3 pins you see on most boards, for example:


With which you can use a USBASP programmer to connect your board directly to a computer just like a normal Arduino. Just use Ctrl-Shift-U to upload your sketch via the programmer. Furthermore you can use bare microcontrollers without the bootloader, as all the necessary code is included with the direct upload. So if this method interests you, add the following to your circuit:

ICSP schematicThe RESET pin is connected to pin 1 of the microcontroller. Speaking of which, if you’re unsure about which pins on the ATmega328P are which, a variety of suppliers have handy labels you can stick on top, for example:

ATmega328 Arduino label

At this point it’s time to put it all together. We’re using a random piece of prototyping PCB, and your final plan will depend on your board. As an aside, check out the Lochmaster stripboard planning software if you use stripboard a lot. As mentioned earlier your final schematic will vary depending on the number of LEDs, their requirements with respect to current and your choice of Arduino platform. By now you have the knowledge to plan the circuit yourself. After some work here’s our final board:

larson scanner

… and the scanner in action. We used the same sketch as for the temporary version – however reduce it to six outputs (D0~5) to match the LEDs.

 Bonus project – Electronic Die

What else can you do with six LEDs? Make an electronic die! Here’s a simple sketch that simply picks a random number every five seconds. The random number generator is seeded from unused an analogue input pin.

And a quick video of our die in action:


We hope you found this interesting and at least made a temporary scanner on a breadboard – or at least learned something. Kudos if you went ahead and made a larger one. If you made a video, share it with us in the comments. And if you made it this far – 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 twitterGoogle+, 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.

Posted in arduino, dice, die, larson scanner, LED, projects, tronixstuff, tutorialComments (6)

Project: Clock Four – Scrolling text clock


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.


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. Please use IDE 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:


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 twitterGoogle+, 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.

Posted in arduino, clocks, dmd, ds1307, DS3232, freetronics, learning electronics, LED matrix, microcontrollers, projects, scrolling, time clock, timing, tutorialComments (10)

Results – February 2012 Competition

Competition over.

Posted in competition

Project: Clock Two – Single digit clock

Let’s hack an Ikea lamp into a single-digit clock! How? Read on…

Updated 18/03/2013

Time for another instalment in my irregular series of clock projects. (Or should that be “Time for another instalment in the series of irregular clock projects”?) In contrast with the extreme “blinkiness” of Clock One, in this article we describe how to build this single-digit digital clock:

Once again the electronics of the clock will be based from an Arduino-compatible board with a DS1307 real-time clock IC added to the board. On top of this we add a shield with some extra circuitry and two buttons – but more on this later. The inspiration for this clock came from a product that was recently acquired at Ikea – the “Kvart” work lamp, for example:

from www.ikea.com.au

If you are shopping for one, here are the Ikea stock details:

The goal is to place the electronics of the clock in the base, and have one single-digit LED display at the top of the neck which will blink out the digits. There will be two buttons under the base that are used to set the time. It will be powered by a 9V battery or an AC adaptor which is suitable for a typical Arduino board.


This article is a diary of my construction, and you can always use your own knowledge and initiative. It is assumed that you have a solid knowledge of the basics of the Arduino system.  If not, review my series of tutorials available from here. Furthermore, feel free to modify the design to work with what you have available – I hope this article can be of some inspiration to you.


It is much easier to prototype the clock and get the Arduino sketch working how you like it before breaking down the lamp and building up the clock. To do this involves some jumper wires and a solderless breadboard, for example:

Although there are four buttons on the board we only use two. They are connected to digital pins eight and nine (with 10k pull-down resistors). The LED display segments a~g are connected to Arduino digital pins 0~6 respectively. The decimal point is connected to the pulse output pin of the DS1307 – which will be set to a 1Hz output to have a nice constant blinking to show the clock is alive and well.

If you are unfamiliar with operating the DS1307 real-time clock IC please review this tutorial. Operation of the clock has been made as simple for the user as possible. To set the time, they press button A (on digital eight) while the current time is being displayed, after which point the user can select the first digit (0~2) of the time by pressing button A. Then they press button B (on digital nine) to lock it in and move to the second digit (0~9) which is again chosen with button A and selected with button B. Then they move onto the digits in the same manner.

After this process the new time is checked for validity (so the user cannot enter invalid times such as 2534h) – and is ok, the clock will blink the hyphen twice and then carry on with the new time. If the entered time is invalid, the clock reverts back to the current time. This process is demonstrated in the following video clip:

You can download the Arduino sketch from here.


The parts required to replicate the Clock Two in this article are:

  • One Arduino-compatible board with DS1307 real-time clock IC as described in this article
  • One Arduino protoshield and header pins
  • One common-cathode 7-segment LED display of your choosing
  • Seven current-limiting resistors to reduce the output current from Arduino digital outputs going to the LED segments. In our example we use a 560 ohm resistor network to save time
  • Two buttons and two 10k ohm pull-down resistors
  • One meter of nine-core wire that will fit inside the neck and stand of the Kvart lamp – an external diameter of less than 6mm will be fine
  • And of course – the lamp

The protoshield is used to hold the buttons, resistor network and the terminus for the wires between the LED display and the Arduino digital outputs, for example:

At this stage you will need to do some heavy deconstruction on the lamp. Cut off the mains lead at the base and remove the plastic grommet from the stand that surrounded the AC lead. Next,  with some elbow grease you can twist off the lamp-shade unit from the end of the flexible neck. You could always reuse the lamp head and AC lead if wired by a licensed electrician.

Now you need to feed the multicore wire through the neck and down to the base of the lamp. You can pull it through the hole near the base, and then will need to drill a hole in the base to feed it through to the electronics as such:

Take care when feeding the cable though so you don’t nick the insulation as shown above. Leave yourself a fair bit of slack at the top which will make life easier when soldering on the LED display, for example:

The next step is to solder the wires at the top to the LED display. Make notes to help recall which wires are soldered to the pins of the display. If your soldering skills (like mine) aren’t so good, use heatshrink to cover the soldering:

Most displays will have two GND pins, so bridge them so you only need to use one wire in the multicore back to base:

At this point use the continuity function of a multimeter or a low-voltage power source to test each LED segment using the other end of the cable protruding from the base. Once you are satisfied the segments have been soldered correctly, carefully draw the cable back through the neck and base in order to reduce the slack between the display and the top of the lamp neck. Then solder the individual LED segment wires to the protoshield.

Now if you have not already done so, upload the sketch into the Arduino board – especially if you are going to permanently mount the circuitry into the base. A simple method of mounting would be using  a hot glue gun, but for the purpose of demonstration we have just used blu-tac:

 Although this does look a little rough, we are using existing stock which kept the cost down. If you are going to power the clock with an AC adaptor, you will also need to cut out small opening to allow the lead to protrude from the side of the base. And now for the resulting clock – our Clock Two:

So there you have it, the second of many clocks we plan to describe in the future.

In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, 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.

Posted in arduino, clocks, ds1307, DS3232, hardware hacking, Ikea, kvart, tutorialComments (17)

February 2012 Competition

Competition over

Posted in competition

Results – January 2012 Competition

Competition over!

Posted in competitionComments (0)

Project: Clock One

Let‘s make a huge analogue and digital clock using a dot-matrix display. 

Updated 18/03/2013

For some strange reason I have a fascination with various types of electronic clocks (which explains this article). Therefore this project will be the start of an irregular series of clock projects whose goal will be easy to follow and produce interesting results. Our “Clock One” will use a Freetronics Dot Matrix Display board as reviewed previously. Here is an example of an operating Clock One:

As you can see, on the left half of the board we have a representation of an analogue clock. Considering we only have sixteen rows of sixteen LEDs, it isn’t too bad at all. The seconds are illuminated by sixty pixels that circumnavigate the square clock throughout the minute. On the right we display the first two letters of the day of the week, and below this the date. In the example image above, the time is 6:08. We omitted the month – if you don’t know what month it is you have larger problems.


To make this happen you will need:

  • Freetronics Dot Matrix Display board;
  • If you want the run the display at full brightness (ouch!) you will need a 5V 2.8A power supply – however our example is running without the external supply and is pretty strong
  • An Arduino board of some sort, an Uno or Eleven is a good start
  • A Maxim DS1307 real-time clock IC circuit. How to build this is explained here. If you have a Freetronics board, you can add this circuit directly onto the board!


Planning the clock was quite simple. As we can only draw lines, individual pixels, and strings of text or individual characters, some planning was required in order to control the display board. A simple method is to use some graph paper and note down where you want things and the coordinates for each pixel of interest, for example:

Using the plan you can determine where you want things to go, and then the coordinates for pixels, positions of lines and so on. The operation for this clock is as follows:

  • display the day of week
  • display the date
  • draw the hour hand
  • draw the minute hand
  • then turn on each pixel representing the seconds
  • after the 59th second, turn off the pixels on the left-hand side of the display (to wipe the clock face)

There isn’t a need to wipe the right hand side of the display, as the characters have a ‘clear’ background which takes care of this when updated. At this point you can download the Arduino sketch from here. Note that the sketch was written to get the job done and ease of reading and therefore not what some people would call efficient. Some assumed knowledge is required – to catch up on the use of the display, see here; and for DS1307 real-time clock ICs, see here.

The sketch uses the popular method of reading and writing time data to the DS1307 using functions setDateDs1307 and getDateDs1307. You can initally set the time within void setup() – after uploading the sketch, comment out the setDateDs1307 line and upload the sketch again, otherwise every time the board resets or has a power outage the time will revert to the originally-set point.

Each display function is individual and uses many switch…case statements to determine which line or pixel to draw. This was done again to draw the characters on the right due to function limitations with the display library. But again it works, so I’m satisfied with it. You are always free to download and modify the code yourself.  Moving forward, here is a short video clip of the Clock One in action:

For more information about the display used, please visit the Freetronics product pageDisclaimer – The display module used in this article is a promotional consideration made available by Freetronics.

In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, 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.

Posted in arduino, clocks, dmd, ds1307, DS3232, freetronics, LED matrix, timing, tutorialComments (16)

January 2012 Competition

Competition over.

Posted in competition

Initial Review: Akafugu Akafuino-X Microcontroller Board

Hello Readers

Time to get back to work for 2012 and in doing so we review another interesting product from a new company based in Japan – akafugu. From their website:

Akafugu Corporation is a small electronics company that operates out of Tokyo, Japan. We specialize in fun and easy to use electronic gadgets. Our goal is to provide products that not only make prototyping faster and easier, but are also perfect for incorporation in finalized products.

And with this in mind we examine the Akafuino-X microcontroller board:


The observant among you will notice the similarity to our usual Arduino Uno and compatible boards. However there are some differences which bring changes and improvements over the original Arduino design. The biggest point of difference is the microcontroller, the Akafuino uses an Atmel XMega32A4. The benefit of this over the normal ATmega328 is:

  • Speed! 32 MHz – twice as fast as the ATmega328;
  • Two-channel DAC (digital to analogue) converter – output analogue signals between 0V and Vcc straight from the board. A library is included with the new IDE to control them. The DAC uses digital pins seven and eight;
  • Not one, two or even four, but five UARTs;
  • Two I2C buses;
  • Sixteen PWM pins – great for LED effects…

Thankfully the designers have detailed the extra I/O pins and other useful information on the rear of the board:


Other changes include:

  • It’s a 3.3V board – so no 5V supply for you. However the inputs are tolerant to 5V;
  • On-board real time clock. You can also add an optional 32.768 kHz crystal to increase accuracy – see the space on the board near the reset pin;
  • A very refreshing red colour (note that ‘aka(i)’ ** is red in Japanese) and a happy puffer fish (‘fugu’) on the silk-screening 🙂
  • And libraries for other Akafugu products such as the TWI Display module are available.

Getting started is easy, however due to the difference in hardware the Arduino IDE needs modification. But don’t panic – instead of modifying your existing v1.0 Arduino IDE – download and install the Akafuino-X version from here and run your usual and the Akauino-X IDE on the same machine (it’s ok to do this). You should also review the usage instructions here and note that this is a derivative of the v1.0 IDE. Furthermore at the time of writing the software side of things is still in beta, and can be monitored via Github – however don’t let this put you off, as the Akafuino-X has a lot of potential.

If you find any bugs in use the issue tracker in Github to let the team know.

In the meanwhile we’ve conducted a quick speed test – by running the same sketch on an Arduino Uno and also the Akafuino-X. The test is a whole lot of multiplication, nothing too scientific. At the end the duration of the exercise is shown in milliseconds. Here’s the code:

And here are the results of running the sketch four times on each board:


Our Akafuino-X beta only took 2704ms versus the Arduino Uno taking 4212ms. Very good so far.

Update! The team at akafugu have been experimenting with overclocking the Akafuino-X. And also check out the errata page

So there you have it, another contender in the Arduino-compatible board stakes. Considering the extra  I/O, PWM and bus connectivity the Akafuino-X is a very capable board. I look forward to the evolution of the IDE and will return with the Akafuino-X in an upcoming project. And we also have one to give away. So stay tuned! In the meanwhile the Akafuino-X and other goodies are available directly from akafugu.jp

Disclaimer – The parts reviewed in this article are a promotional consideration made available by akafugu.

Have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, 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.

** Yes I know it’s an i-type adjective

Posted in akafugu, akafuino, arduino, product review, review, XMega32A4Comments (6)

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:

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 twitterGoogle+, 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.

Posted in arduino, atmega328, atmel, EEPROM, hardware hacking, lesson, microcontrollers, projects, tutorialComments (5)

Tutorial: Control AC outlets via SMS

Learn how to control AC outlets via SMS text message. This is chapter thirty-three 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 02/03/2013

Assumed understanding for this article is found in part one. If you have not already done so, please read and understand it.

In this chapter we will continue with the use of the SM5100 cellular shield to turn digital outputs on and off via SMS. However please read chapters twenty-six and twenty-seven first if you are unfamiliar with using the GSM shield with Arduino. As an extension of chapter twenty-seven, we will use our Arduino to turn on or off AC outlets via a common remote-control AC outlet pack. Please note this is more of a commentary of my own experience, and not an exact tutorial. In other words, by reading this I hope you will gain some ideas into doing the necessary modifications yourself and in your own way.

Firstly, we need some remote-control AC outlets. Most electrical stores or giant retail warehouses may have something like this:


Nothing too original, just a wireless remote control that can switch on or off receiver outlets on a choice of four radio frequencies. Before moving forward I would like to acknowledge that this article was inspired by the wonderful book Practical Arduino – Cool Projects for Open Source Hardware by Jon Oxer and Hugh Blemings. In chapter two an appliance remote-control system is devised using a similar system.

At first glance the theory behind this project is quite simple – using the hardware in example 27.2, instead of controlling LEDs, activate the buttons on the wireless remote control for the AC outlets – leaving us with AC outlets controlled via SMS. However there are a few things to keep in mind and as discovered during the process, various pitfalls as well.

Before voiding the warranty on your remote control, it would be wise to test the range of the remote control to ensure it will actually work in your situation. I found this was made a lot easier by connecting a radio to the remote outlet – then you can hear when the outlet is on or off. If this is successful, make a note of the amount of time required to press the on and off buttons – as we need to control the delay in our Arduino sketch.

The next step is to crack open the remote control:


… and see what we have to work with:


Straight away there are two very annoying things – the first being the required power supply – 12 volts; and the second being the type of button contacts on the PCB. As you can see above we only have some minute PCB tracks to solder our wires to. It would be infinitely preferable to have a remote control that uses actual buttons soldered into a PCB, as you can easily desolder and replace them with wires to our Arduino system. However unless you can casually tear open the remote control packaging in the store before purchase, it can be difficult to determine the type of buttons in the remote.

As you can see in the photo above, there is an off and on pad/button each for four channels of receiver. In my example we will only use two of them to save time and space. The next question to solve is how to interface the Arduino digital outputs with the remote control. In Practical Arduino, the authors have used relays, but I don’t have any of those in stock. However I do have a quantity of common 4N25 optocouplers, so will use those instead. An optocoupler can be thought of as an electronic switch that is isolated from what is it controlling – see my article on optocouplers for more information.

Four optocouplers will be required, two for each radio channel. To mount them and the associated circuitry, we will use a blank protoshield and build the Arduino-remote control interface onto the shield. The circuitry for the optocoupler for each switch is very simple, we just need four of the following:

As the LED inside the optocoupler has a forward voltage of 1.2 volts at 10mA, the 390 ohm resistor is required as our Arduino digital out is 5 volts. Dout is connected to the particular digital out pin from the Arduino board. Pins 4 and 5 on the optocoupler are connected to each side of the button contact on our remote control.

The next consideration is the power supply. The remote control theoretically needs 12 volts, however the included battery only measured just over nine. However for the optimum range, the full 12 should be supplied. To save worrying about the battery, our example will provide 12V to the remote control. Furthermore, we also need to supply 5 volts at a higher current rating that can be supplied by our Arduino. In the previous GSM chapters, I have emphasised that the GSM shield can possibly draw up to two amps in current. So once again, please ensure your power supply can deliver the required amount of current. From experience in my location, I know that the GSM shield draws around 400~600 milliamps of current – which makes things smaller and less complex.

The project will be supplied 12 volts via a small TO-92 style 78L12 regulator, and 5 volts via a standard TO-220 style 7805 regulator. You could always use a 7812, the 78L12 was used as the current demand is lower and the casing is smaller. The power for the whole project will come from a 15V DC 1.5A power supply. So our project’s power supply schematic will be as follows:

Now to mount the optocouplers and the power circuitry on the blank protoshield. Like most things in life it helps to make a plan before moving forward. I like to use graph paper, each square representing a hole on the protoshield, to plan the component layout. For example:

It isn’t much, but it can really help. Don’t use mine – create your own, doing so is good practice. After checking the plan over, it is a simple task to get the shield together. Here is my prototype example:


It isn’t neat, but it works. The header pins are used to make connecting the wires a little easier, and the pins on the right hand side are used to import the 15V and export 12V for the remote. While the soldering iron is hot, the wires need to be soldered to the remote control. Due to the unfortunate size of the PCB tracks, there wasn’t much space to work with:


But with time and patience, the wiring was attached:


Again, as this is a prototype the aesthetics of the modification are not that relevant. Be careful when handling the remote, as any force on the wiring can force the soldered wire up and break the PCB track. After soldering each pair of wires to the button pads, use the continuity function of a multimeter to check for shorts and adjust your work if necessary.

At this stage the AC remote control shield prototype is complete. It can be tested with a simple sketch to turn on and off the related digital outputs. For example, the following sketch will turn on and off each outlet in sequence:

Now to get connected with our GSM shield. It is a simple task to insert the remote shield over the GSM shield combination, and to connect the appropriate power supply and (for example) GSM aerial. The control sketch is a slight modification of example 27.2, and is shown below

The variable pressdelay stores the amount of time in milliseconds to ‘press’ a remote control button. To control our outlets, we send a text message using the following syntax:

Where a/b are remote channels one and two, and x is replaced with 0 for off and 1 for on.

So there you have it – controlling almost any AC powered device via text message from a cellular phone. Imagine trying to do that ten, or even five years ago. As always, now it is up to you and your imagination to find something to control or get up to other shenanigans.


Have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, 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.

Posted in AC power, arduino, CEL-00675, CEL-09607, cellphone hacking, cellular, GSM, hardware hacking, lesson, SM5100, SMS, tutorial

Tutorial: Arduino and Infra-red control

Learn how to use Arduino and infra-red remote controls in chapter thirty-two 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 10/07/2013

In this article we will look at something different to the usual, and hopefully very interesting and useful – interfacing our Arduino systems with infra-red receivers. Why would we want to do this? To have another method to control our Ardiuno-based systems, using simple infra-red remote controls.

A goal of this article is to make things as easy as possible, so we will not look into the base detail of how things work – instead we will examine how to get things done. If you would like a full explanation of infra-red, perhaps see the page on Wikipedia. The remote controls you use for televisions and so on transmit infra-red beam which is turned on and off at a very high speed – usually 38 kHz, to create bits of serial data which are then interpreted by the receiving unit. As the wavelength of infra-red light is too high for human eyes, we cannot see it. However using a digital camera – we can. Here is a demonstration video of IR codes being sent via a particularly fun kit – the adafruit TV-B-Gone:

Now to get started. You will need a remote control, and a matching IR receiver device. The hardware and library used in this tutorial only  supports NEC, Sony SIRC, Philips RC5, Philips RC6, and raw IR protocols. Or you can purchase a matching set for a good price, such as this example:


Or you may already have a spare remote laying around somewhere. I kept this example from my old Sony Trinitron CRT TV after it passed away:


It will more than suffice for a test remote. Now for a receiver – if you have purchased the remote/receiver set, you have a nice unit that is ready to be wired into your Arduino, and also a great remote that is compact and easy to carry about. To connect your receiver module – as per the PCB labels, connect Vcc to Arduino 5V, GND to Arduino GND, and D (the data line) to Arduino digital pin 11.

Our examples use pin 11, however you can alter that later on. If you are using your own remote control, you will just need a receiver module. These are very cheap, and an ideal unit is the Vishay TSOP4138 (data sheet .pdf). These are available from element-14 and the other usual retail suspects. They are also dead-simple to use. Looking at the following example:

From left to right the pins are data, GND and Vcc (to Arduino +5V). So it can be easily wired into a small breadboard for testing purposes. Once you have your remote and receiver module connected, you need to take care of the software side of things. There is a new library to download and install, download it from here. Please note that library doesn’t work for Arduino Leonardo, Freetronics Leostick, etc with ATmega32U4. Instead, use this library (and skip the modification steps below). Extract the IRremote folder and place into the ..\arduinoxxx\libraries folder. Then restart your Arduino IDE if it was already open.

Using Arduino IDE v1.0 or greater? Open the file “IRRemoteInt.h” in the library folder, and change the line

Then save and close the file, restart the Arduino IDE and you’re set.

With our first example, we will receive the commands from our remote control and display them on the serial monitor:

Open the serial monitor box, point your remote control to the receiver and start pressing away. You should see something like this:

What have we here? Lots of hexadecimal numbers. Did you notice that each button on your remote control resulted in an individual hexadecimal number? I hope so. The number FFFFFFFF means that the button was held down. The remote used was from a yum-cha discount TV. Now I will try again with the Sony remote:

This time, each button press resulted in the same code three times. This is peculiar to Sony IR systems. However nothing to worry about. Looking back at the sketch for example 32.1, the

section is critical – if a code has been received, the code within the if statement is executed. The hexadecimal code is stored in the variable

with which we can treat as any normal hexadecimal number. At this point, press a few buttons on your remote control, and take a note of the matching hexadecimal codes that relate to each button. We will need these codes for the next example…

Now we know how to convert the infra-red magic into numbers, we can create sketches to have our Arduino act on particular commands. As the IR library returns hexadecimal numbers, we can use simple decision functions to take action. In the following example, we use switch…case to examine each inbound code, then execute a function. In this case we have an LCD module connected via I2C, and the sketch is programmed to understand fifteen Sony IR codes. If you don’t have an LCD you could always send the output to the serial monitor. If you are using the DFRobot I2C LCD display, you need to use Arduino v23.

Furthermore you can substitute your own values if not using Sony remote controls. Finally, this sketch has a short loop after the translateIR(); function call which ignores the following two codes – we do this as Sony remotes send the same code three times. Again. you can remove this if necessary. Note that when using hexadecimal numbers in our sketch we preced them with 0x:

And here it is in action:

You might be thinking “why would I want to make things appear on the LCD like that?”. The purpose of the example is to show how to react to various IR commands. You can replace the LCD display functions with other functions of your choosing.

At the start working with infra-red may have seemed to be complex, but with the previous two examples it should be quite simple by now. So there you have it, another useful way to control our Arduino systems. Hopefully you have some ideas on how to make use of this technology. In future articles we will examine creating and sending IR codes from our Arduino. Furthermore, a big thanks to Ken Shirriff for his Arduino library.


Have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, 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.

Posted in arduino, control, DFR0107, dfrobot, education, infrared, IR, learning electronics, lesson, microcontrollers, remote, tronixstuff, tutorialComments (17)

Arduino Game: Tic-Tac-Toe

[Updated 19/02/2013]

Let’s recreate the game of Tic-tac-toe with our Arduino systems. This game is also known as Noughts and Crosses or Three-in-a-row. Whatever we call it, I’m sure you will be familiar with the game from your childhood or general messing about. For the uninitiated, there is an excellent explanation of the game over at Wikipedia.


In the following examples, a human will play against the machine (Arduino). The demonstration sketches are almost identical except for one function – machineMove();. This function contains the method of deciding a move for the machine. By localising the machine’s decision making into that function we can experiment with levels of intelligence without worrying about the rest of the sketch. In writing this article it is assumed the reader has some basic Arduino or programming experience. If not, perhaps read some of my Arduino tutorials indexed here.

However first we will examine the hardware. I have used my well-worn Freetronics Eleven board, which is equivalent to the Arduino Uno. For a display, the Sparkfun LCD shield is used. For user input we have two buttons connected to digital pins 6 and 7, using 10k pull-down resistors as normal. The buttons are wired via a ScrewShield set. To save time I have used my generic button-board, whose schematic is below:



If you were to construct a more permanent example, this could be easily done. One could possibly use a DS touch-screen over their LCD. Perhaps for mark II? Nevertheless, time to move on. Now to explain how the sketch works – please download a copy from here so you can follow along with the explanation.

I have tried to make the sketch as modular as possible to make it easy to follow and modify. The sketch itself is relatively simple. We use an array board[] to map the pieces of the game board in memory – board[0] being the top-left and board[8] being the bottom-right position. We create a graphical representation of the board by drawing rectangles for the horizontal and vertical lines, lines to form crosses, and circles for … circles. The function drawBoard(); takes care of the board lines and calls drawPiece(); to place the players’ pieces. drawBoard(); reads the board[] array to determine if a position is blank (zero), a nought (1) or a cross (2).

The flow of the sketch is easy to follow. First the function introScreen() is called – it displays the introductory screen. Then drawBoard() is called to draw the initially-blank game board. Then the main function playGame(); is called. We have a global variable winner, whose value determine the winner of the game (0 – game still in play, 1 – human, 2 – machine, 3 – draw). playGame(); and other functions will refer to winner throughout the sketch. Within playGame();, the human and machine take turns placing their pieces. The function humanMove(); accepts the human’s choice in piece position, storing it into board[], and not allowing false moves. The function machineMove(); controls the decision-making process for the machine’s moves. In the first example, the machine moves by randomly selecting a board position. If the position is taken, another random position is selected (and so on) until a valid move can be made.

After each instance of humanMove(); and machineMove();, the function checkWinner(); is called. This function compares the contents of the array board[] against all possible scenarios for a win by either player, and calls the function drawTest(); – which checks for a draw – and stores the result in the variable winner as described earlier. Checking for a win is simple, however checking for a draw was a little more complex. This involves counting the number of 1s and 2s in the board[] array. If there are five 1s and four 2s or four 1s and five 2s ( in other words, the board is full) there is a draw. Easy!

If, after the function checkWinner(); is called, the varible winner >0 – then something to end the game has happened – either a win or a draw. This is determined using the switch…case function at the end of checkWinner();. At this point a function relative to the game status is called, each of which display the outcome and wait for the user to press button A to start a new game. At the end of each of these functions, we call the function clearBoard(); – which resets the array board[] and winner back to zero, ready for the next battle of wits.

Now for our first example in action. The function machineMove() is an example of the simplest form of play – the machine randomly selects blank positions on the board until the game ends. In the following video clip you can see this in action:

For the forthcoming examples, we will allow the choice of who moves first. This is accomplished with the function moveFirst(); which sets the variable whofirst to 1 for human first, or 2 for machine first. This is read by playGame() to determine the first move. Now let’s inject some strategy into our machineMove(); function to give the machine a slight edge above sheer randomness.

In the following example, the machine will first only use the centre or corners until those positions have been taken. This is accomplished by placing the position numbers into another array strategy1[]={0,2,4,6,8} which the machine will randomly select from until those positions are used.  Once all those positions have been filled, the machine will revert to random positioning to attempt a win. You can download this example sketch from here. Do you think the machine can win if allowed to move first? Let’s see what happens in the following video clip:

In the second example the player who moves first will generally have the advantage. From this point, how could we strengthen the machine’s level of intelligence to improve its strategy? If you have a better method, and can integrate it into the example sketch, and are happy to publish it under Creative Commons – email the sketch to john at tronixstuff dot com.

So there you have it, some variations on a classic game translated for our Arduino systems. I hope you found it interesting… or at least something different to read about.

In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, 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.

Posted in arduino, education, games, LCD-09363, lesson, microcontrollers, tutorialComments (4)

Tutorial: Your Arduino’s inbuilt EEPROM

This is chapter thirty-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 09/01/2013]

Today we are going to examine the internal EEPROM in our Arduino boards. What is an EEPROM some of you may be saying? An EEPROM is an Electrically Erasable Programmable Read-Only Memory. It is a form of non-volatile memory that can remember things with the power being turned off, or after resetting the Arduino. The beauty of this kind of memory is that we can store data generated within a sketch on a more permanent basis.

Why would you use the internal EEPROM? For situations where data that is unique to a situation needs a more permanent home. For example, storing the unique serial number and manufacturing date of a commercial Arduino-based project – a function of the sketch could display the serial number on an LCD, or the data could be read by uploading a ‘service sketch’. Or you may need to count certain events and not allow the user to reset them – such as an odometer or operation cycle-counter.

What sort of data can be stored? Anything that can be represented as bytes of data. One byte of data is made up of eight bits of data. A bit can be either on (value 1) or off (value 0), and are perfect for representing numbers in binary form. In other words, a binary number can only uses zeros and ones to represent a value. Thus binary is also known as “base-2″, as it can only use two digits.

How can a binary number with only the use of two digits represent a larger number? It uses a lot of ones and zeros. Let’s examine a binary number, say 10101010. As this is a base-2 number, each digit represents 2 to the power of x, from x=0 onwards:

binary2 binary12

See how each digit of the binary number can represent a base-10 number. So the binary number above represents 85 in base-10 – the value 85 is the sum of the base-10 values. Another example – 11111111 in binary equals 255 in base 10.


Now each digit in that binary number uses one ‘bit’ of memory, and eight bits make a byte. Due to internal limitations of the microcontrollers in our Arduino boards, we can only store 8-bit numbers (one byte) in the EEPROM. This limits the decimal value of the number to fall between zero and 255. It is then up to you to decide how your data can be represented with that number range. Don’t let that put you off – numbers arranged in the correct way can represent almost anything!

There is one limitation to take heed of – the number of times we can read or write to the EEPROM. According to the manufacturer Atmel, the EEPROM is good for 100,000 read/write cycles (see the data sheet). One would suspect this to be a conservative estimate, however you should plan accordingly. *Update* After some experimentation, the life proved to be a lot longer

Now we know our bits and and bytes, how many bytes can be store in our Arduino’s microcontroller? The answer varies depending on the model of microcontroller. For example:

  • Boards with an Atmel ATmega328, such as Arduino Uno, Uno SMD, Lilypad or the Freetronics KitTen/Eleven – 1024 bytes (1 kilobyte)
  • Boards with an Atmel ATmega1280 or 2560, such as the Arduino Mega series – 4096 bytes (4 kilobytes)
  • Boards with an Atmel ATmega168, such as the original Arduino Lilypad, old Nano, Diecimila etc – 512 bytes.

If y0u are unsure have a look at the Arduino hardware index or ask your board supplier.

If you need more EEPROM storage than what is available with your microcontroller, consider using an external I2C EEPROM as described in the Arduino and I2C tutorial part two.

At this point we now understand what sort of data and how much can be stored in our Arduino’s EEPROM. Now it is time to put this into action. As discussed earlier, there is a finite amount of space for our data. In the following examples, we will use a typical Arduino board with the ATmega328 with 1024 bytes of EEPROM storage.

To use the EEPROM, a library is required, so use the following library in your sketches:

The rest is very simple. To store a piece of data, we use the following function:

The parameter a is the position in the EEPROM to store the integer (0~255) of data b. In this example, we have 1024 bytes of memory storage, so the value of a is between 0 and 1023. To retrieve a piece of data is equally as simple, use:

Where z is an integer to store the data from the EEPROM position a. Now to see an example.

This sketch will create random numbers between 0 and 255, store them in the EEPROM, then retrieve and display them on the serial monitor. The variable EEsize is the upper limit of your EEPROM size, so (for example) this would be 1024 for an Arduino Uno, or 4096 for a Mega.

The output from the serial monitor will appear as such:

So there you have it, another useful way to store data with our Arduino systems. Although not the most exciting tutorial, it is certainly a useful.


Have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, 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.

Posted in arduino, education, EEPROM, lesson, microcontrollers, tutorialComments (33)

The DFRobot LCD4884 LCD Shield

Learn how to use the DFRobot LCD4884 Arduino LCD shield.

Updated 19/03/2013

This needs to be updated for use with Arduino IDE v1.0.1 and greater… however we no longer have a shield to test it. Stay tuned via twitter to find out when this is updated.

This article is my response to a request on how to use the LCD4884 LCD shield from DFRobot in China. It is a simple way of displaying text and the odd graphic, as well as another way to accept user input. Here is the shield in question:


From a hardware perspective the LCD has a resolution of 84 by 48 pixels, with a blue back light. It can easily display six rows of fourteen alphanumeric characters, or two rows of six very large characters. Furthermore, it can display bitmap images that are appropriately sized. At the top-left of the shield digital pins eight to thirteen have been expanded with matching Vcc and GND pins, and at the bottom right the same has been done with analogue pins one through to five. Therefore if using this shield, you will lose digital pins two through to seven and analogue zero.

Along the bottom-left of the shield are solder pads for some other I/O options, however I couldn’t find any documentation on how these are used. Below the LCD is a small four-way joystick that also has an integral button. This is connected to analog pin zero via a resistor network. This joystick can be used for user input and also to create some nifty menu systems. To the right is a power-on LED which is really too bright, I would recommend sanding it a little to reduce the intensity, or just melting it off with a soldering iron.

The shield requires an Arduino library which can be downloaded from the shield’s wiki page. There is also a good demonstration sketch on the wiki, however some of our readers may find this to be somewhat complex. Therefore where possible I will break down and explain the functions in order to simplify use of the shield, then use them in a demonstration sketch.

Controlling the backlight is very easy, just use:

digitalWrite(7, HIGH/LOW)

to turn it on and off. Don’t forget to put

pinMode(7, OUTPUT) in void setup();.

Reading the joystick position is accomplished via analogRead(0);. It returns the following values as such:

  • Up – 505
  • Down – 0
  • Left – 740
  • Right – 330
  • pressed in – 144
  • Idle (no action) – 1023

By using analogRead(0) and if… statements you can read the joystick in a simple way. Don’t forget to allow for some tolerance in the readings. Attempts to press the button while forcing a direction did not return any different values. In the example sketch later on, you can see how this is implemented. Always remember to insert:

in void setup() to create an instance of the LCD, and

at the start of your sketch to enable the library.

Now to display text on the LCD. Here is an example of the standard font text:


Using the standard font, we can position text using the following function:

The parameter x is for the x-coordinate of the first character – measured in pixels, not characters. However y is the coordinate in character lines (!). The screen can display six lines of fourteen characters. To display the larger font, for example:


use the following:

Unfortunately the library only supports the digits 0~9, +, – and decimal point. You can modify the file font_big.h in the library folder and create your own characters. Once again the x parameter is the number of pixels across to place the first character, and y is 0 for the top line and 3 for the bottom line. Notice that the characters in this font are proportional, however the maximum number of digits to plan for in one line would be six.

To clear the display, use:

By now you will be able to display text, control the backlight and read the joystick. The following demonstration sketch puts it all together so far:

Next is to create and display bitmap images. Images can be up to 84 x 48 pixels in size. There are no shades of grey in the images, just pixels on or off. To display a bitmap is a convoluted process but can be mastered. We need to convert a bitmap image into hexadecimal numbers which are then stored in a text file for inclusion into the sketch. To do so, follow these steps:

Create your monochrome image using an editor such as Gimp. Make sure your file name ends with .bmp. Such as:


Next, download the BMP2ASM program from this website. [Sorry, could only find a Windows version]. Open your .bmp file as created above, and you will see a whole bunch of hexadecimal numbers at the bottom of the window:


Turn on the check boxes labelled “Stretch”, “Use Prefix” and “Use suffix”. Then click “Convert”. Have a look in your folder and you will find a text file with an extension .asm. Open this file in a text editor such as Notepad. Remove all the instances of “dt”, as well as the top line with the file path and name. Finally, put commas at the end of each line.

You should now be left with a file of hexadecimal numbers. Encase these numbers in the form of an array as such:


What we have done is places the hexadecimal numbers inside the

declaration. To make life simpler, ensure the filename (ending with .h) is the same as the variable name, as in this example it is called hellobmp(.h). And make sure you have saved this file in the same folder as the sketch that will use it. Finally, we include the hellobmp.h file in our example sketch to display the image:

Notice in the function lcd.LCD_draw_bmp_pixel the filename hellobmp is the same as in the #include declaration is the same as the hellobmp.h file we created. They all need to match. Furthermore, the four numerical parameters are the bitmap’s top-left x-y and bottom-right x-y coordinates on the LCD. So after all that, here is the result:


So there you have it. If you have any questions about this LCD shield contact DF Studio, or ask a question in our Google Group.

In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, 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.

Posted in arduino, DFR0092, dfrobot, education, LCD, LCD4884, lesson, review, tutorialComments (19)

Moving Forward with Arduino – Chapter 30 – twitter

Learn how to tweet from your Arduino in chapter thirty of a series originally titled “Getting Started/Moving Forward with Arduino!” by John Boxall – A tutorial on the Arduino universe.

[Updated 26/7/2013]

In this article we will learn how to send messages from our Arduino to twitter. For the uninitiated who may be thinking “what is all this twitter nonsense about?”, twitter is a form of microblogging. You can create a message with a maximum length of 140 characters, and broadcast this on the twitter service. For people to receive your messages (or tweets) they also need to be a member of twitter and choose to subscribe to your tweets.

Generally people will use the twitter service using one of three methods: using a web browser on a personal computer or internet device, on a mobile phone, or using a specific application such as TweetDeck on one of the aforementioned devices. For example, here is a typical web browser view:

And here is an example of a twitter application running on an Android OS smartphone:


So as you can see, it is easy enough to read peoples’ tweets. Therein lies the reason for this article – we can harness twitter as an output device for our Arduino systems. We can broadcast various messages, so systems can be created to monitor specific parameters and report on their status at regular intervals, upon an event occurring, and so on.

In some areas, you can set twitter to send tweets from a certain user to your mobile phone via SMS – however if doing so be careful to confirm possible charges to your mobile phone account. Finally, if you are worried about privacy with regards to your tweets, you can set your account to private and only allow certain people to follow your tweets.

So let’s get started. First of all – you will need a twitter account. If you do not have one, you can sign up for one here. If you already have a twitter account, you can always open more for other uses – such as an Arduino. For example, my twitter account is @tronixstuff, but my demonstration machine twitter account is @tronixstuff2. Then I have set my primary account to follow my machine’s twitter account. Once you have logged into twitter with your machine account, visit this page and get yourself a token by following the Step One link. Save your token somewhere safe, you’ll need to insert it into your Arduino sketch.

Next, you will need some hardware. Apart from your usual Arduino board, you will need an Ethernet shield. However to save space and money I’ll be using the Freetronics EtherTen:

If you are unfamiliar with using Arduino and Ethernet, please review chapter sixteen before continuing forward with this article. From a software perspective, we will need another library for our Arduino IDE. Download and install the twitter library from here. Now, at this point – please run the Webserver example described in chapter sixteen and ensure it is working before moving forward from this point. While you do that, we’ll have a break…


Now it is time to send our first tweet. The following sketch is a modification of the demonstration version, in which we have isolated the tweet-sending into a separate function called (strangely enough) tweet();. It is not complex at all:

So after uploading the above sketch, running a network cable from your access point to the Ethernet shield, and powering up the Arduino board – your tweet should appear as such:

Excellent – it works. And I hope yours did as well. If it did not, open the serial monitor box to get some feedback from the sketch. From experimentation the most amount of errors are caused by incorrect IP and trying to send multiple tweets too quickly. If you get excited and try to run the sketch again by hitting reset, twitter will reply back with an error – it does not allow duplicate tweets to be sent (over a short period of time). Twitter will reply to your tweet with a code which describes the result of your tweet. This code is stored in an integer variable using the function:

For example, 200 means the tweet was sent successfully, and 403 means you have attempted a duplicate tweet. However you can omit the code-checking if you are not fussed about your tweet’s status.

Although it was fun tweeting Hello world, let’s create an example that reacts to various events and tweets about them. To simulate some events I have connected four buttons to digital inputs (using the button board from chapter twelve). Pressing a button sends of the matching message. However you can use any form of digital output or decision-making in your sketch. For now, here is the example sketch:

And here is a screen shot of the results after pressing buttons one, four, two then three:

So there you have it, another useful way to send information from your Arduino to the outside world. Stay tuned for upcoming Arduino tutorials by subscribing to the blog, RSS feed (top-right), twitter or joining our Google Group. Big thanks to @neocat for their work with the twitter  Arduino libraries.


Have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, 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.

Posted in arduino, cellular, ethernet, learning electronics, microcontrollers, tutorial, twitterComments (2)

Kit review – ogi lumen Nixie Tube system

Hello readers

Time to finish off the month with a fascinating kit review  – the ogi lumen nixie tube system. The younger readers amongst us may be thinking “what is a nixie tube?” Here is an example of four in a row:


If you cast your mind back to before the time of LCDs, and before LEDs… to the mid-1950s. Nixie tubes were used to display data in various forms on electrical devices, from test equipment, scales, elevator indicators, possible doomsday machines, clocks – anything that required visual output would be a candidate. Although nixie tubes are now totally out of date, as with many things there is a growing trend to use them again, for cool retro-style, nostalgia and those people who enjoy living in the past.

How nixie tubes work is quite simple, an element is within a vacuum tube full of gas, such as neon. When a high-voltage (~190 volts DC) current flows through the element, it glows. For more information, here is a great explanation. You will note that they are similar to in look but different in design to the vacuum-fluorescent displays, as used in the ice tube clock reviewed a few months previously. The tubes used in this kit are the Soviet model IN-12A:


The IN-12A tube can display the digits zero to nine, with a nice orange glow.  For the uninitiated, sourcing and making nixie tubes can be quite difficult. Apart from procuring the tubes themselves, you need a suitable power supply and logic ICs that can handle the higher voltage to control the tubes. Thankfully Ogi Lumen have put together a system of kits to make using these nixie tubes simple and interesting. There are three components to the system, the first being the power supply:


Note that the power supply is preassembled. This supply can generate the necessary 150 to 220 volts DC to energise our nixie tubes. Yes – up to 220 volts! For example:


However the current required is quite small – one power supply can handle up to twenty-four IN12A nixie tubes. My example in the photograph above is drawing 110~120 milliamps from a 12V DC supply. For those of you assembling these kits, please be careful. It can be easy to physically move the kit about whilst in operation, and touching the live HV pads will hurt a lot. After bumping the HV line on the PCB, my whole left arm went into a spasm and hurt for the time it took to see my doctor. So be careful.

The second item required is the driver kit. This is a board that takes care of the shift-registers and power for two of the nixie tubes. Driver kits can be slotted together to form a row of nixie tubes. The third and final item is the nixie duo kit. This contains two IN-12A tubes, matching sockets and a PCB to muont them. This PCB then slots into the driver kit PCB. You can buy the driver and duo kit as a set for a discount.

From a hardware perspective, assembling the kits is relatively simple. There isn’t any tricky soldering or SMD to worry about, however you will need a lot of solder. The contents of the duo and driver kits are as follows:


Before you start soldering, please download and take note of the instructional .pdf files available for the duo and driver board kits. Assembling the driver kit (on the right) is very straight forward. However – please read the instructions! An interesting part of note is the K155ИД1IC:


This is the Russian equivalent of the 74141. This is a BCD-decimal decoder IC that can handle the high voltages required for nixie tubes. When soldering the resistors, take care with R2 – it will need to be positioned horizontally so as to not rub against the duo board:


When it is time to assemble the duo board, you will need time and patience. At a first glance, one would imagine that the sockets drop into the PCB, and the nixie tubes will happily be seated into the sockets. This is not so, don’t solder in the sockets first! The pins on the bottom of the socket also form part of the socket for the tube legs – which can alter the positioning of the socket legs. Make sure you have the socket with pin 1 at the top of the PCB. After some trial and error, the best way to insert the tubes is to first partially place the sockets into the PCB:


… then fully insert the tubes into their sockets. Make sure the tube is the right way up – check that the digit 3 in the tube is the right way up. Then push the whole lot into the PCB. At this point you should check to make sure the sockets are in line with each other:


(Notice how thick the PCB is…) At which point you can solder them in, followed by the row of connector pins:


By this stage you will need some fresh air from all that soldering. The PCB holes for the socket pins really take a lot. Now you can connect the power supply to the driver board and give the tubes a test-toast:


All the tubes should have their elements glowing. This is a good start. The next step is to connect the appropriate microcontroller and start displaying. As noted in the instructions, the 74141 BCD-decimal ICs are controlled by standard 74HC595 shift-register ICs, so your microcontroller needs to send out a data, clock and latch line. My following examples have been created using the Ardiuno system and a compatible board.

The first example is a method of displaying integers. It uses the Nixie library which you can download here.

That was just an arbitrary demonstration to get some numbers displayed. Here is a short video clip of it in action:

Now for another, more useful example. By using a DS1307 real-time clock IC with the Arduino, we can make a nice clock that displays the time and date. For more information on using the DS1307 with Arduino, please visit this tutorial. You can download the example nixie clock .pde file from here. And finally, here is the clock in action:

The problem with these tubes is that you will never have enough. Already I have thought of a few things to make that require a lot more tubes, so in the next month or so stay tuned to tronixstuff.com as there will be more projects with these kits.

In conclusion, this was a great kit and anyone looking to use some numerical nixie tubes will do very well with the Ogi Lumen products. Furthermore the designs are released under Creative Commons by-sa-nc, and the files are available to download from the product pages. And finally, it is a lot of fun – people will generally ask you about the tubes as they may have never seen them before.

Remember, if you have any questions about these modules please contact Ogi Lumen via their website. Higher resolution images available on flickr.

Have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, 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.

[Note – the kit assembled in this article was received from Ogi Lumen for review purposes]

Posted in arduino, kit review, learning electronics, nixie, ogilumenComments (11)

Various 555 Timer circuits

Hello readers

The purpose of this article is to follow on from our explanation of the 555 timer IC by demonstrating some simple yet interesting, noisy and plain annoying uses of the 555. They are by no means that complex, and intended to help move theory into practice.

Button de-bouncer

De-bouncer? How does one bounce a button in the first place? Many years ago I bounced a button on the arcade Sonic the Hedgehog – hit it so hard it popped out and bounced over the table… But seriously, when working with digital logic circuits, you may need to use  a momentary button to accept user input. For example, to pulse a trigger or so on. However with some buttons, they are not all that they seem to be. You press them once, but they can register multiple contacts – i.e. register two or more ‘presses’ for what seems like only one press. This could possibly cause trouble, so we can use a 555 timer monostable circuit to solver the problem. In our de-bounce example, when the button is pressed, the output is kept at high for around half a second. Here is the schematic:


What we have is a basic monostable timer circuit. For my example the output delay (t) is to be half a second. The formula for t is: t=1.1xR1xC1. The closest resistor I had at hand was 2k ohms, so to find the required value for C1, the formula is rearranged into: C1=t/(1.1xR1). Substituting the values for t and R1 gives a value of C1 as 227.274 uF. So for C1 we have used a 220 uF capacitor.

Now for a visual demonstration of the de-bouncer at work. In the following video clip, the oscilloscope is displaying the button level on the lower channel, and the output level on the upper channel. The button level when open is high, as the 555 requires a low pulse to activate. The output level is normally low. You can see when the button is pressed that the button level momentarily drops to low, and then the output level goes high for around half a second:

Make some noise

As we know the 555 can oscillate at frequencies from less than 1Hz to around 500 kHz. The human ear can theoretically hear sounds between (approximately) 20 and 20 kHz. So if we create an astable timing circuit with an output frequency that falls within the range of the human ear, and connect that output to a small speaker – a range of tones can be emitted.

The circuit required is a standard 555 astable, with the output signal heading through a small 8 ohm 0.25 watt speaker and a 4.7 uF electrolytic capacitor to ground. The capacitor stops any DC current flowing to ground, without this we will overload the current-handling ability of the 555. (I couldn’t help myself by trying it without the capacitor – pulled 550 mA from the 555 before it stopped working…). To choose the values of R1 and C1 to emit out required frequency, the following formula is used: f (frequency) = 1.4 / {(R1 + [2 x R2]) x C1}. To cover the range required, a 100k ohm trimpot was used for R1. Here is the resulting schematic:


The input voltage can fall within the specification of the 555, however for optimum results a supply of between 5 and 9 volts DC should be used. In the following demonstration, we used a 9V supply. The purpose of the video is to learn the relationship between the tones and their frequencies. You can see the frequency on my old counter and hopefully hear the result:

Our next example is to create a  siren effect, using two 555 circuits – one for a low frequency and one for a high frequency. To determine the value for R1 for the low and high frequency, I used the previous circuit and chose two tones that were quite different, and measured the resistance of the trimpot (R1) at those frequencies. My R1 value for the ‘low’ tone is 82k ohm and 36k ohm for the ‘high’ frequency.

The switching between low and high frequency will be handled by a 4047 multivibrator – the Q and Q outputs will control NPN transistors. The transistors are used as switches to allow current to flow from the supply to the 555 high or low tone circuit. We use this method as the 4047 is not able to source enough current to drive the 555 circuits. Here is the schematic:


Don’t forget to connect pin 14 of the 4047 to supply voltage. This circuit has been tested with a supply voltage between 5 and 12 volts. As the supply voltage increases, so does the amplitude of the square wave emanating from the 555 output pins, which in turn in creases the volume of the siren. At 5 volts, the entire circuit drew only 20 milliamps. Speaking of which, you can listen to a recording of the output here. If you wish to alter the time for each tone, adjust the value of what is the 47k ohm resistor on pins 2 and 3 of the 4047.

In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, 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.

Posted in 4047, 555, arduino, COM-09273, education, learning electronics, lesson, tutorialComments (0)

Tutorial: Arduino and TFT LCD

Old and now unsupported tutorial for 4D Systems 1.44″ TFT serial interface LCD.

Update 20/04/2013 

The Arduino library for this module hasn’t been updated to work with Arduino v1.0.1+ – so you need to use Arduino IDE v22 or v23. And the module itself has been discontinued. For the time being I’m leaving the tutorial here until a more suitable item can be used. We can’t help you with the 4D module

Nevertheless – if you have one – here’s the subject of the tutorial- the 4D Systems 1.44″ TFT serial interface LCD:

The LCD is an LED-backlit thin-film transistor type, resolution is 128 x 128 pixels, with an RGB colour range of 65536.

As an aside, this is a very powerful piece of hardware. The module not only contains a 1.44″ square TFT LCD, there is also a dedicated graphics processor and a microSD card interface. One can program the display processor in the same manner as another microcontroller platform for incredibly interesting results. For more information, please visit:


However in the spirit of keeping things simple, this article will focus on driving the LCD directly using our Arduino or compatible boards. There are two firmware versions of this module – the GFX and the SGC. We need to have the SGC firmware, as this allows control via the serial TX/RX pins from our Arduno board. If you have purchased the SGC module, you’re ready to go. Scroll down until you see “And we’re back…”. However if you have the GFX version, please read the following instructions on how to change your LCD’s firmware from GFX to SGC…

Changing the firmware from GFX to SGC

  • At the moment this process only seems available to users of Microsoft Windows. All complaints to 4D Systems.
  • Unfortunately this process may not work with an Arduino Mega board.
  • First of all, remove the ATmega328 from your Arduino board. Please be careful, use a chip puller if possible. We are going to use the board as a simple serial-USB converter;
  • Insert your LCD module into a solderless breadboard;
  • Connect Arduino pin 0 (RX) to display pin 7 (RX); connect Arduino pin 1 (TX) to display pin 8 (TX). [Yes – TX>TX, RX>RX];
  • Connect Arduino 5V to display pin 9; connect Arduino GND to display pin 6; your LCD should display the following:


  • Visit http://www.4dsystems.com.au/prod.php?id=46, download and open the PmmC Loader application; visit http://www.4dsystems.com.au/prod.php?id=120 and download the .pmmc file to your local drive;
  • Connect your Arduino board via USB to the computer; then run the PmmC loader application;
  • Select the appropriate COM: port, load in the .pmmc file, then click Load. The firmware update should take less than sixty seconds;
  • When finished, you will be presented with the following on the computer:


… and the following on your LCD:


  • At this point unplug the USB lead from your Arduino board and all leads into the Arduino board;
  • Re-insert the ATmega328 back into your Arduino board;
  • Reconnect the wires from the LCD module to the Arduino, but this time connect Arduino TX to LCD RX; and LCD TX to Arduino RX.
  • Now you have  the serial-interface SGC firmware model LCD.

And we’re back…

To control this LCD, it requires commands to be sent via Serial.write(), and such commands are in the form of hexadecimal numbers. (You see something new every day). You can download the reference book with all the commands:


and bypass the library by directly writing the hexadecimal numbers directly to the module.

However, to get up to speed as fast as possible we can use a library with more of the popular functions included. Kudos and thanks to Oscar Gonzalez for writing a very useful library. Download the library from:


and install into your ../Arduino-002x/libraries folder, then re-start the Arduino IDE if you had it running. You may be wondering why the library is named displayshield4d – the LCD manufacturer sells this LCD on an Arduino shield. Although that would be great for experimenting, one would need to purchase another standalone LCD if their project moved forward – myself included. So that’s why we’re using the bare LCD board.

To connect the LCD to our Arduino is very simple:

  • LCD pin 5 to Arduino RST;
  • LCD pin 6 to Arduino GND;
  • LCD pin 7 to Arduino D1;
  • LCD pin 8 to Arduino D0;
  • LCD pin 9 to Arduino 5V.

In the following examples we will demonstrate the various functions available in the library. As this is chapter 29, I will no longer explain the more basic functions or ideas that you should know by now, instead relying on comments within the sketch if it feels necessary. It can take a short moment for the LCD controller to process, so always put a short delay between functions.

When uploading a sketch to your Arduino you may need to disconnect the LCD from Arduino D0/D1 as it can interfere with the serial process.

Firstly we will demonstrate text display. Initialising the display requires a few functions:

The second line creates an instance of lcd to be used with the relevant functions. Next, within void setup():

To write text to the LCD, the following function is required:

This line sets the font transparency. If we use the parameter OLED_FONT_TRANSPARENT the unused pixels in the character area will be transparent and continue to show what they were set to before the text was over-written with. You can also use OLED_FONT_OPAQUE, which blocks the item displayed “behind” the text.

Whenever a function requires a colour parameter, we use:

where x, y and z are numerical values (between 0 and 255) for the red, green and blue components of the required colour. If you need an RGB numerical reference, download this handy chart. Finally, to display some text we use the following:

The parameters required are:

  • a – the x-position of the first character. E.g. if this was a zero, the top-left pixel of the first character would be on the left-most pixel column of the LCD;
  • b – the y-position of the first character. e.g. if both a and b were zero, the text would start from the top-left of the LCD;
  • c – numerical code for the font to use: 1 is for 5×7 pixel characters, 2 for 8×8 and 3 for 8×12;
  • the three values within the lcd.RGB() function determine the colour of the text;
  • d – x-axis resolution multiplier. E.g. if you double this and use the 5×7 font, the characters will be double-width;
  • e – y-axis resolution multiplier.

Now let’s see this in action with the following sketch:

And a short video clip of the example in action: – http://www.youtube.com/watch?v=t3yypXL022w

As you can see the display update speed is much better than the LCD from the previous chapter. Although this example was short, don’t be afraid to try out your own parameters in the example sketch.

Next we will demonstrate the various graphics functions in the library. Creating graphics isn’t rocket science, it just takes some imagination (something I admit to lacking) and following the parameters for each function. Our first is

which places a pixel on the screen at location x,y of colour described using lcd.RGB(). Next we have

which draws a line from x1, y1 to x2, y2 of colour rgb. One can also create rectangles and so on using

This will create a rectangle with the top-left point at x,y; width is l pixels, height is h pixels, and a new parameter z. If z is 0, the function will draw a solid shape, if z is 1, it will display only a wire-frame rectangle with a pixel width of one. Circles are created using

where x and y are the coordinates for the centre of the circle, r is the radius, and z is the solid/wireframe parameter. And finally – triangles:

This will draw a triangle with the corners at the coordinate parameters; z again is the solid/wireframe parameter. However you need to order the corners in an anti-clockwise order. This will become evident in the example sketch below. In this example we run through the graphical functions described above. By following through the sketch you should gain an idea of how the graphical functions are used, in order to create your own displays.

And here is the video of example 29.2 in action … brought to you by Mr Blurrycam: – http://www.youtube.com/watch?v=BKy-GuKWGZ8


Posted in 4d systems, arduino, education, LCD, learning electronics, lesson, microcontrollers, TFT, tutorial

Review – CD4047 Astable/Monostable Multivibrator

Hello readers!

Today we are going to examine an older but still highly useful integrated circuit – the 4047 Astable/Monostable multivibrator:


My reason for doing this is to demonstrate another way to create a square-wave output for digital circuits (astable mode) and also generate single pulses (monostable mode). Sometimes one can get carried away with using a microcontroller by default – and forget that there often can be simpler and much cheaper ways of doing things. And finally, the two can often work together to solve a problem.

What is a multivibrator? In electronics terms this means more than one vibrator. It creates an electrical signal that changes state on a regular basis (astable) or on demand (monostable). You may recall creating monostable and astable timers using the 555 timer described in an earlier article. One of the benefits of the 4047 is being able to do so as well, but with fewer external components. Here is the pinout diagram for a 4047 (from the Fairchild data sheet):

Note that there are three outputs, Q, Q and OSC out. Q is the normal output, Q is the inverse of Q – that is if Q is high, Q is low – at the same frequency. OSC output provides a signal that is very close to twice the frequency of Q. We will consider the other pins as we go along. In the following small video, we have LEDs connected to all three outputs – you can see how Q and Q alternate, and the increased frequency of OSC out:

That was an example of the astable mode.  The circuit used is shown below. The only drawback of using a 4047 is that you cannot alter the duty cycle of your astable output – it will always be 50% high and 50% low. The oscillator output is not guaranteed to have a 50% duty cycle, but comes close. The time period (and therefore the frequency) is determined by two components – R1 and the capacitor:

[Quick update – in the schematic below, also connect 4047 pin 14 to +5V]


The values for R2~R4 are 560 ohms, for the LEDs. R1 and the capacitor form an RC circuit, which controls the oscillation frequency. How can we calculate the frequency? The data sheet tells us that time (period of time the oscillator is ‘high’) is equal to 4.4 multiplied by the value of R1 and the capacitor. As the duty cycle is always 50%, we double this value, then divide the result into one. In other words:

And as the frequency from the OSC out pin is twice that of Q or Q, the formula for the OSC out frequency is:

However the most useful formula would allow you to work with the values of R and C to use for a desired frequency f:

When calculating your values, remember that you need to work with whole units, such as Farads and Ohms- not microfarads, mega-ohms, etc. This chart of SI prefixes may be useful for conversions.

The only thing to take note of is the tolerance of your resistor and capacitor. If you require a certain, exact frequency try to use some low-tolerance capacitors, or replace the resistor with a trimpot of a value just over your required resistor value. Then you can make adjustments and measure the result with a frequency counter. For example, when using a value of 0.1uF for C and 15 k ohm for R, the theoretical frequency is 151.51 Hz; however in practice this resulted with a frequency of 144.78 Hz.

Don’t forget that the duty cycle is not guaranteed to be 50% from the OSC out pin. This is shown in the following demonstration video. We measure the frequency from all three output pins, then measure the duty cycle from the same pins:

(The auto-ranging on that multimeter is somewhat annoying).

Now for some more more explanation about the 4047. You can activate the oscillations in two ways, via a high signal into pin 5 (pin 4 must then be low) or via a low signal into pin 4 (and pin 5 must be low). Setting pin 9 high will reset the oscillator, so Q is low and Q is high.

The monostable mode is also simple to create and activate. I have not made a video clip of monstable operation, as this would only comprise of staring at an LED. However, here is an example circuit with two buttons added, one to trigger the pulse (or start it), and another to reset the timer (cancel any pulse and start again):

[Quick update – in the schematic below, also connect 4047 pin 14 to +5V]


The following formula is used to calculate the duration of the pulse time:

Where time is in seconds, R is Ohms, and C is Farads. Once again, the OSC output pin also has a modified output – it’s time period will be 1.2RC.

To conclude, the 4047 offers a simple and cheap way to generate a 50% duty cycle  square wave or use as a monostable timer. The cost is low and the part is easy to source. As always, avoid the risk of counterfeit ICs and get yours from a reputable distributor. Living in Australia, mine came from element-14. Thanks to Fairchild Semiconductor for product information from their 4047 data sheet.

Have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, 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.

Posted in 4047, education, learning electronics, lesson, part review, tutorialComments (41)

Tutorial: Arduino and Colour LCD

Learn how to use the colour LCD shield from Sparkfun in chapter twenty-eight 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 19/02/2013

Although there are many colour LCDs on the market, I’ve chosen a relatively simple and popular model to examine in this tutorial – the Sparkfun Color LCD shield:

If you buy one note (shown above) that stacking headers aren’t supplied or fitted to the shield. If you get a header pack from Sparkfun or elsewhere – order PRT-10007 not PRT-11417 as the LCD shield doesn’t have the extra holes for R3 Arduino boards. However if you do have an Arduino R3 – relax … the shield works. While we’re on the subject of pins – this shield uses D3~D5 for the three buttons, and D8, 9, 11 and 13 for the LCD interface. The shield takes 5V and doesn’t require any external power for the backlight. The LCD unit is 128 x 128 pixels, with nine defined colours (red, green, blue, cyan, magenta, yellow, brown, orange, pink) as well as black and white.

So let’s get started. From a software perspective, the first thing to do is download and install the library for the LCD shield. Visit the library page here. Then download the .zip file, extract and copy the resulting folder into your ..\arduino-1.0.x\libraries folder. Then restart the Arduino IDE if it was already open.

At this point let’s check the shield is working before moving forward. Fit it to your Arduino – making sure the shield doesn’t make contact with the USB socket**. Then open the Arduino IDE and upload the TestPattern sketch found in the Examples folder. You should be presented with a nice test pattern as such:

It’s difficult to photograph the LCD – (some of them have very bright backlights), so the image may not be a true reflection of reality. Nevertheless this shield is easy to use and we will prove this in the following examples.

At the start of every sketch, you will need the following lines:

as well as the following in void setup():