Tag Archive | "i2c"

Tutorial – pcDuino GPIO with Arduino IDE


In this tutorial we’ll explain how to use the GPIO pins of the Arduino implementation in the pcDuino v2 and v3. As the v3 is now available you can use it as well, and it’s interchangeable with the v2. Although the pcDuino v2 is Arduino-compatible, there are a few differences that you need to be aware of – in order to make your projects a success and also to avoid any costly mistakes.

pcDuino v2 board

This tutorial builds on the knowledge from the initial review, so if pcDuino v2 is new to you please review this article before moving on. In this instalment we’ll run through the following:

  • ADC (analogue to digital)
  • Digital input and outputs
  • PWM (pulse-width modulation)
  • I2C bus
  • SPI bus

Using ADC pins

Just like an Arduino Uno or compatible, the pcDuino v2 has six ADC pins, in the expected locations:

pcduino v2 ADC pin map

Using the pcDuino v2’s ADC pins is quite straight forward, however you just need to remember a few things about the hardware – that the maximum input voltage on A0 and A1 is 2V – and 3.3V for A2~A5.

Although there is an AREF pin on the board, this function isn’t supported at the time of writing. From the software perspective A0 and A1’s values have a 6-bit resolution and can fall between 0 and 63 (0~2V), otherwise the others have a 12-bit resolution and thus return values between 0 and 4095 (0~3.3V). Using the ADC pins is simple, and demonstrated in the following sketch:

… which results with the following in the console:

pcDuino ADC demo output

Digital outputs

The pcDuino v2’s implementation of digital outputs aren’t anything out of the ordinary – except that you are limited to a maximum voltage of 3.3V instead of the usual 5V. Furthermore you can only source 4mA from each pin. However if you have some 5V-only shields that you must use with your pcDuino v2 – there is a Voltage Translation board that can be used to solve the problem:

pcDuino v2 voltage translation board TBoard

However using 3.3V for new designs shouldn’t be an issue – new sensors, ICs and so on should be 3.3V-compatible. And with the pcDuino v2 you get an extra four digital I/O pins, located next to the SPI grouping as shown below:

pcDuino v2 extra GPIO pins

These are simply addressed as D14~D17. Now back for a quick demonstration with the typical LEDs. As the current sourced from each GPIO pin cannot exceed 4mA, you need to use a resistor to keep things under control. Using the LED wizard, by entering a 3.3V supply, 2.1V forward voltage for our LEDs and a 4mA current – the resistor value to use is 330Ω.

If you’re having a lazy attack and use 560Ω, the current will be around 2.5mA with acceptable results. We’ve done just that with the following demonstration sketch:

… and the results in this video.


Digital inputs

When using the digital pins as inputs, just treat them as normal except they have a maximum input voltage of 3.3V for HIGH. Again – just keep thinking “3.3V”.

Using the I2C data bus

The I2C bus (or “two wire interface”) is a common serial data bus used for interfacing all manner of devices with a microcontroller. You can find a background on the I2C bus and Arduino tutorial here. Just like an Arduino Uno R3, the I2C bus pins are both A4 and A5 (for SCL and SDA) and can also be found up near D13, for example.

The limitations for the pcDuino v2’s version of I2C bus are few – the maximum speed is 200 kHz, it only uses 7-bit addresses and you can’t use the pcDuino in slave mode. However there are 2.2kΩ pullup resistors which can save using them with external circuitry.

We demonstrate the I2C bus by writing data to and reading it from a Microchip 24LC256 EEPROM (which is handy in itself as there isn’t any EEPROM function on the pcDuino v2). This is demonstrated with an Arduino Uno in part two of our I2C tutorials.

Connection is very easy – pins 1 to 4 of the EEPROM are connected to GND, pin 5 to SDA, pin 6 to SCL, pin 7 to GND and pin 8 to 3.3V. Finally a 0.1uF capacitor is placed across 3.3V and GND.

pcduino v2 eeprom

The sketch to read and write values to the EEPROM is simple, and apart from the #include <core.h> for the pcDuino all the other functions operate as normal.

… which results with the following output in the console:

pcduino i2c demonstration

As you now know, using I2C isn’t hard at all. A lot of beginners shy away from it – or run screaming for the nearest library for their part. You don’t need libraries – spend a little time now learning about I2C and you’re set for life.

Using the SPI data bus

Again we have some SPI tutorials for Arduino, so check them out first if the concept is new to you. Writing to an SPI device with the pcDuino v2 isn’t tricky at all, you have the 3.3V hardware limitation and the SPI pins are in the same location (D10~D13) or in a separate group on the board:

pcduino v2 SPI pins

Furthermore the maximum SPI speed is 12 MHz and the pcDuino v2’s  implementation of SPI can only work as a master. However in the sketch there are a few differences to note. To demonstrate this we’ll control a Microchip MCP4162 digital rheostat via SPI to control the brightness of an LED. Here is the circuit:

pcDuino v2 MCP4162 SPI demo circuit

And now for the sketch. Take note of the fourth line in void setup() –  this is used to set the SPI bus speed to 12 MHz. You can also reduce the speed with other multipliers such as 32, 64 and 128 to slow it down even further. The other point to note is the use of SPI.transfer(). With the pcDuino v2 there are two parameters – the first is the data to send to the SPI device, and the second is either

if there is another byte of data following immediately, or

if that is the last byte for that immediate transfer. You can see this use of the paramters within the function setValue() in the demonstration sketch below.

When using the SPI bus, relevant data will appear in the console, for example:

pcduino V2 SPI console output

And finally the demonstration video to show you it really works – you can see the output voltage from the rheostat and the matching LED brightness.

Receiving data from the SPI bus is equally as simple, however at the time of writing we don’t have an SPI device to demonstrate this, so please refer the SPI part of the pcDuino guide. Finally, you can’t use PWM on D10 or D11 when using the SPI bus in your sketch.

Pulse-width modulation

You can simulate analogue output using PWM with a pcDuino v2 – however there are two types of PWM pins available. The first is found on digital pins D3, D9, D10 and D11 – they are simulated PWM – and have a low range of zero to twenty at 5 Hz. There are two hardware PWM pins – D5 and D6, which  run at 520Hz and have the full range of 0~255 available in analogWrite(). Once again – they output 3.3V. Furthermore, you can’t use pinMode() functions or the SPI bus if using D10 and/or D11 for PWM.


Now you should have an understanding of the features and limitations of using GPIO pins with your pcDuino v2 Arduino sketches. Stay tuned as we continue with more pcDuino v2 articles and tutorials in the near future. pcDuino boards and accessories are available from tronixlabs. Full-sized images are on flickr.

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 ADC, arduino, GPIO, I2C, pcDuino, PWM, SPI, tronixlabs, tronixstuff, tutorialComments (5)

Review – adafruit industries Mini 8×8 LED Matrix with I2C backpack


In this review we have a look at the mini 8×8 LED matrix with I2C backpack from adafruit industries. It looked like a small yet versatile display unit for a couple of project ideas, so as part of the evaluation we’ll run through it with you here. As you can see below, it’s quite small with a 20mm square matrix:


The matrix and the controller are seperate which gives you the option of ordering different colours of matrix. Using LED matrices can be a pain, however these units use the Holtek 16K33 controller IC (data sheet) which has an I2C interface – much easier than the usual mess of shift registers and I/O pins:


 Furthermore you can change the I2C address using the solder pads on the PCB, giving you four possible options. And as it’s I2C, you can use it with other microcontrollers with a little detective work. Moving forward, we’ll assemble the display then explain how to use it with an Arduino, and show a few demonstrations.


There really isn’t anything major to do, just solder the matrix to the backpack and some header pins if you need them. adafruit include some however I’m using the 90-degree ones for my own use:


The soldering should take about one minute tops, and then you’re done:


Using the matrix

From a hardware perspective you only have four wires – 5V, GND, SDA and SCL. Yes – it’s a 5V part, so all you Raspberry Pi fans will need a level shifter, which you can get from adafruit as well. Anyhow once you’ve got it connected to your Arduino, a couple of libraries are required – the matrix and GFX libraries. Be sure to install them in your sketchbook/libraries folder and not the usual location. When saving the library files, call the first folder Adafruit_LEDBackpack and the second Adafruit_GFX as they don’t arrive in that format.

Now for a quick demonstration, it’s simply one from the included library. The display is very bright, so I had to reduce the exposure on the camera which makes the background a little dark – but you get the idea:

A pair of those fitted to a dummy or doll would be quite interesting, or make good eyes for a 21st century “Metal Mickey”. Well that’s quite interesting, so how do you in fact display things on the matrix? I’ve deconstructed a few examples to show you how it’s done.

No matter what, you need to include the libraries, define the matrix object in the sketch and then start it with the matching I2C address – for example:

To scroll text across the display, modify the following chunk of code:

First, the setRotation() value is 0~3 and determines which way the text scrolls across the screen. This is useful if you mount the matrix in different positions, as you can still keep the text scrolling in a readable manner. Next, matrix.setTextWrap() – leave this as false,  as true displays each character and then just scrolls it in turn – looking rather odd. Now multiply the number of characters you want to display by 8, and replace the number -96 with negative your value and of course “Hello, world”. Finally follow with rest of the code. There’s a quick demonstration of this code in the sketch and video below:


Now for some graphics. You can define your own images (!) and store them in an array. Each arrays consists of eight bytes, each representing a row of the matrix. You can use binary to help visualise the results, for example:

and then to display that on the matrix, use the following:

… which resulted with:


To control individual pixels, send one or more of the following:

where x and y are the pixel’s coordinates (that fall between zero and seven), followed by:

Here’s a neat example sketch and video of a single pixel “running around the border”:

By this point you should be getting the hang of things now, so we’ll finish up with the last three graphic functions at once. To draw a line between x1, y1 and x2, y2 – use:

To draw a rectangle with corners at x1, y2, x2, y2 – use:

To draw a filled rectangle with corners at x1, y2, x2, y2 – use:

And to draw a circle with axis at x,y and a radius of r pixels – use:

Now we’ll put those functions into the following sketch and video:


If you want to get someone’s attention, you can blink whatever’s on the matrix at various frequencies – and of course turn it off. In the following function, use 0 for off, and 1~3 for different rates:

Finally, you can also adjust the brightness to one of sixteen levels (0~15) using:

That’s enough blinkiness for now. Remember the library is just shielding you from the raw I2C commands, so if you want to create your own functions or use a non-Arduino board – examine the library and the data sheet.


The backpack makes using the matrix an absolute breeze, and the library saves a lot of time and effort – leaving you to get on with creating your ideas into projects. You can get the matrix from adafruit and their distributors.

Full-sized images available on flickr.  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.

[Note - item purchased without notifying the supplier]

Posted in 16K33, adafruit, arduino, holtek, I2C, LED matrix, review, tutorialComments (0)

Tutorial – Arduino and PCF8591 ADC DAC IC

Learn how to use the NXP PCF 8591 8-bit A/D and D/A IC with Arduino in chapter fifty-two of my Arduino Tutorials. The first chapter is here, the complete series is detailed here.

Updated 17/06/2013


Have you ever wanted more analogue input pins on your Arduino project, but not wanted to fork out for a Mega? Or would you like to generate analogue signals? Then check out the subject of our tutorial – the NXP PCF8591 IC. It solves both these problems as it has a single DAC (digital to analogue) converter as well as four ADCs (analogue to digital converters) – all accessible via the I2C bus. If the I2C bus is new to you, please familiarise yourself with the readings here before moving forward.

The PCF8591 is available in DIP form, which makes it easy to experiment with:


You can get them from the usual retailers. Before moving on, download the data sheet. The PCF8591 can operate on both 5V and 3.3V so if you’re using an Arduino Due, Raspberry Pi or other 3.3 V development board you’re fine. Now we’ll first explain the DAC, then the ADCs.

Using the DAC (digital-to-analogue converter)

The DAC on the PCF8591 has a resolution of 8-bits – so it can generate a theoretical signal of between zero volts and the reference voltage (Vref) in 255 steps. For demonstration purposes we’ll use a Vref of 5V, and you can use a lower Vref such as 3.3V or whatever you wish the maximum value to be … however it must be less than the supply voltage. Note that when there is a load on the analogue output (a real-world situation), the maximum output voltage will drop – the data sheet (which you downloaded) shows a 10% drop for a 10kΩ load. Now for our demonstration circuit:


Note the use of 10kΩ pull-up resistors on the I2C bus, and the 10μF capacitor between 5V and GND. The I2C bus address is set by a combination of pins A0~A2, and with them all to GND the address is 0x90. The analogue output can be taken from pin 15 (and there’s a seperate analogue GND on pin 13. Also, connect pin 13 to GND, and circuit GND to Arduino GND.

To control the DAC we need to send two bytes of data. The first is the control byte, which simply activates the DAC and is 1000000 (or 0x40) and the next byte is the value between 0 and 255 (the output level). This is demonstrated in the following sketch:

Did you notice the bit shift of the bus address in the #define statement? Arduino sends 7-bit addresses but the PCF8591 wants an 8-bit, so we shift the byte over by one bit. 

The results of the sketch are shown below, we’ve connected the Vref to 5V and the oscilloscope probe and GND to the analogue output and GND respectively:


If you like curves you can generate sine waves with the sketch below. It uses a lookup table in an array which contains the necessary pre-calculated data points:

And the results:


For the following DSO image dump, we changed the Vref to 3.3V – note the change in the maxima on the sine wave:


Now you can experiment with the DAC to make sound effects, signals or control other analogue circuits.

Using the ADCs (analogue-to-digital converters)

If you’ve used the analogRead() function on your Arduino (way back in Chapter One) then you’re already familiar with an ADC. With out PCF8591 we can read a voltage between zero and the Vref and it will return a value of between zero and 255 which is directly proportional to zero and the Vref. For example, measuring 3.3V should return 168. The resolution (8-bit) of the ADC is lower than the onboard Arduino (10-bit) however the PCF8591 can do something the Arduino’s ADC cannot. But we’ll get to that in a moment.

First, to simply read the values of each ADC pin we send a control byte to tell the PCF8591 which ADC we want to read. For ADCs zero to three the control byte is 0x00, 0x01, ox02 and 0x03 respectively. Then we ask for two bytes of data back from the ADC, and store the second byte for use. Why two bytes? The PCF8591 returns the previously measured value first – then the current byte. (See Figure 8 in the data sheet). Finally, if you’re not using all the ADC pins, connect the unused ones to GND.

The following example sketch simply retrieves values from each ADC pin one at a time, then displays them in the serial monitor:

Upon running the sketch you’ll be presented with the values of each ADC in the serial monitor. Although it was a simple demonstration to show you how to individually read each ADC, it is a cumbersome method of getting more than one byte at a time from a particular ADC.

To do this, change the control byte to request auto-increment, which is done by setting bit 2 of the control byte to 1. So to start from ADC0 we use a new control byte of binary 00000100 or hexadecimal 0x04. Then request five bytes of data (once again we ignore the first byte) which will cause the PCF8591 to return all values in one chain of bytes. This process is demonstrated in the following sketch:

Previously we mentioned that the PCF8591 can do something that the Arduino’s ADC cannot, and this is offer a differential ADC. As opposed to the Arduino’s single-ended (i.e. it returns the difference between the positive signal voltage and GND, the differential ADC accepts two signals (that don’t necessarily have to be referenced to ground), and returns the difference between the two signals. This can be convenient for measuring small changes in voltages for load cells and so on.

Setting up the PCF8591 for differential ADC is a simple matter of changing the control byte. If you turn to page seven of the data sheet, then consider the different types of analogue input programming. Previously we used mode ’00’ for four inputs, however you can select the others which are clearly illustrated, for example:


So to set the control byte for two differential inputs, use binary 00110000 or 0x30. Then it’s a simple matter of requesting the bytes of data and working with them. As you can see there’s also combination single/differential and a complex three-differential input. However we’ll leave them for the time being.


Hopefully you found this of interest, whether adding a DAC to your experiments or learning a bit more about ADCs. We’ll have some more analogue to digital articles coming up soon, so stay tuned. And if you enjoy my tutorials, or want to introduce someone else to the interesting world of Arduino – check out my new book “Arduino Workshop” from No Starch Press.


In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on 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 ADC, arduino, beginnner, dac, differential, education, electronics, I2C, lesson, NXP, PCF8591, tronixstuff, tutorialComments (17)

mbed and the Freescale FRDM-KL25Z development board

In this article we examine the mbed rapid prototyping platform with the Freescale FRDM-KL25Z ARM® Cortex™-M0+ development board.


A while ago we looked at the mbed rapid prototyping environment for microcontrollers with the cloud-based IDE and the NXP LPC1768 development board, and to be honest we left it at that as I wasn’t a fan of cloud-based IDEs. Nevertheless, over the last two or so years the mbed platform has grown and developed well – however without too much news on the hardware side of things. Which was a pity as the matching development boards usually retailed for around $50 … and most likely half the reason why mbed didn’t become as popular as other rapid development platforms.

And now we have another powerful yet inexpensive board to use with mbed  – the Freescale FRDM-KL25Z

It’s a move in the right direction for both mbed and Freescale. It allows educators and interested persons access to a very user-friendly IDE and dirt-cheap development boards.

What is mbed anyway?

mbed is a completely online development environment. That is, in a manner very similar to cloud computing services such as Google Docs or Zoho Office. However there are some pros and cons of this method. The pros include not having to install any software on the PC – as long as you have a web browser and a USB port you should be fine; any new libraries or IDE updates are handled on the server leaving you to not worry about staying up to date; and the online environment can monitor and update your MCU firmware if necessary. However the cons are that you cannot work with your code off-line, and there may be some possible privacy issues. Here’s an example of the environment:


As you can see the IDE is quite straight-forward. All your projects can be found on the left column, the editor in the main window and compiler and other messages in the bottom window. There’s also an online support forum, an official mbed library and user-submitted library database, help files and so on – so there’s plenty of support. Code is written in C/C++ style and doesn’t present any major hurdles. When it comes time to run the code, the online compiler creates a downloadable binary file which is copied over to the hardware via USB.

And what’s a Freedom board?

It’s a very inexpensive development board based on the Freescale ARM® Cortex™-M0+ MKL25Z128VLK4 microcontroller.

Features include  (from the product website):

  • MKL25Z128VLK4 MCU – 48 MHz, 128 KB flash, 16 KB SRAM, USB OTG (FS), 80LQFP
  • Capacitive touch “slider,” MMA8451Q accelerometer, tri-color LED
  • Easy access to MCU I/O
  • Sophisticated OpenSDA debug interface
  • Mass storage device flash programming interface (default) – no tool installation required to evaluate demo apps
  • P&E Multilink interface provides run-control debugging and compatibility with IDE tools
  • Open-source data logging application provides an example for customer, partner and enthusiast development on the OpenSDA circuit

And here it is:


In a lot of literature about the board it’s mentioned as being “Arduino compatible”. This is due to the layout of the GPIO pins – so if you have a 3.3 V-compatible Arduino shield you may be able to use it – but note that the I/O pins can only sink or source 3 mA (from what I can tell) – so be careful with the GPIO . However on a positive side the board has the accelerometer and an RGB LED which are handy for various uses.

Getting started

Now we”ll run through the process of getting a Freedom board working with mbed and creating a first program. You’ll need a computer (any OS) with USB, an Internet connection and a web browser, a USB cable (mini-A to A) and a Freedom board. The procedure is simple:

  1. Order your board from tronixlabs.com
  2. Download and install the USB drivers for Windows or Linux from here.
  3. Visit mbed.org and create a user account. Check your email for the confirmation link and follow the instructions within.
  4. Plug in your Freedom board – using the USB socket labelled “OpenSDA”. It will appear as a disk called “bootloader”
  5. Download this file and copy it onto the “bootloader” drive
  6. Unplug the Freedom board, wait a moment – then plug it back in. It should now appear as a disk called “MBED”, for example :


There will be a file called ‘mbed’ on the mbed drive – double-click this to open it in a web browser. This process activates the board on your mbed account – as shown below:


Now you’re ready to write your code and upload it to the Freedom board. Click “Compiler” at the top-right to enter the IDE.

Creating and uploading code

Now to create a simple program to check all is well. When you entered the IDE in the previous step, it should have presented you with the “Guide to mbed Online Compiler”. Have a read, then click “New” at the top left. Give your program a name and click OK. You will then be presented with a basic “hello world” program that blinks the blue LED in the RGB module. Adjust the delays to your liking then click “Compile” in the toolbar.

If all is well, your web browser will present you with a .bin file that has been downloaded to the default download directory. (If not, see the error messages in the area below the editor pane). Now copy this .bin file to the mbed drive, then press the reset button (between the USB sockets) on the Freedom board. Your blue LED should now be blinking.

Moving forward

You can find some code examples that demonstrate the use of the accelerometer, RGB LED and touch sensor here. Here’s a quick video of the touch sensor in action:

So which pin is what on the Freedom board with respect to the mbed IDE? Review the following map:


All the pins in blue – such as PTxx can be referred to in your code. For example, to pulse PTA13 on and off every second, use:

The pin reference is inserted in the DigitalOut assignment and thus “pulsepin” refers to PTA13. If you don’t have the map handy, just turn the board over for a quick-reference:


Just add “PT” to the pin number. Note that the LEDs are connected to existing GPIO pins: green – PTB19, red – PTB18 and blue – PTB.

Where to from here? 

It’s up to you. Review the Freedom board manual (from here) and the documentation on the mbed website, create new things and possibly share them with others via the mbed environment. For more technical details review the MCU data sheet. And to order your own Freedom board, visit tronixlabs.com


The Freedom board offers a very low cost way to get into microcontrollers and programming. You don’t have to worry about IDE or firmware revisions, installing software on locked-down computers, or losing files. You could teach a classroom full of children embedded programming for around $20 a head (a board and some basic components). Hopefully this short tutorial was of interest. We haven’t explored every minute detail – but you now have the basic understanding to move forward with your own explorations.

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 1 hz, arm cortex, education, FRDM-KL25Z, freedom, freescale, lesson, M0+, mbed, MKL25Z128VLK4, MMA8451Q, opensda, part review, tronixlabs, tronixstuff, tutorialComments (0)

Review: GorillaBuilderz LeoShield


Some of you may be using an Arduino Leonardo board, taking advantage of the newer ATmega32U4 microcontroller for various reasons. And rightly so – there’s the extra analogue I/O, virtual USB and the microUSB socket so you can use your phone charger cable. However with the new microcontroller comes a few changes to the board pinouts – I2C and SPI have moved. So if you have a nice Ethernet shield or something using I2C – you’re basically out of luck… until now. The problem has been solved nicely by the team at GorillaBuilderz have created their LeoShield:


You simply place it on the Leonardo, and then the older legacy shield on top. The LeoShield redirects the I2C pins back to A4 and A5, and also sends the SPI lines back to D11~D13. For example, our Ethernet shield:

The ICSP pins are also extended from the Leonardo to the LeoShield, for example:

however when inserting the LeoShield into your Leonardo, take care lining up all the pins before pushing the shield down. There is also the large prototyping area which has 5V , 3.3V and GND rails across the full width for convenience. The sticker on the rear of the shield is to insulate against any large items that may come in contact from the host board, however you can peel it off to realise the complete prototyping space.


It’s simple and it works – so if you need to use an older Arduino shield with a Leonardo the choice is simple – get yourself a Leoshield.


Disclaimer – The Leoshield was a review product received from GorillaBuilderz.

Thanks for reading tronixstuff.com. I’ve got some new tutorials coming up very soon, and a lot of existing posts are curently being updated – so 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

Posted in arduino, gorillabuilderz, I2C, leonardo, leoshield, product reviewComments (0)

Kit Review – akafugu TWILCD Display Controller Backpacks


Working with LCD displays is always useful, for debugging hardware by showing various data or part of a final design. Furthermore, using them can be rather wasteful of I/O pins, especially when trying to squeeze in other functionality. Plus there’s the external contrast adjustment, general wiring and the time taken to get it working. (Don’t believe me? See here).

However, using the subjects of this kit review – you can convert standard HD44780 LCD modules to use the I2C bus using a small backpack-style board – bringing total I/O down to four wires – 5V/3.3V, GND, SDA and SCL. If you’re using an Arduino – don’t panic if you’re not up on I2C – a software library takes care of the translation leaving you to use the LiquidCrystal functions as normal. Furthermore you can control the brightness and contrast (and colour for RGB modules) – this feature alone is just magic and will make building these features into projects much, much easier.

In this review we examine both of the backpacks available from akafugu. There are two available:

  • the TWILCD: Supports 1×16 and 2×7 connectors. It covers 16×1, 20×1, 16×2, 20×2 and 20×4 displays with and without backlight, and the
  • TWILCD 40×2/40×4/RGB: Supports 1×18 connector (for Newhaven RGB backlit displays), 2×8 connector (used for some 20×4 displays) and 2×9 connector (used for 40×4 displays)
If unsure about your LCD, see the list and explanation here. The LCDs used in this article were supplied with the mono and colour LCD bundles available from akafugu. So let’s see how easy they really are, and put them through their paces.


The backpacks arrive in the usual anti-static bags:

First we’ll examine the TWILCD board:

Very small indeed. There are three distinct areas of interface – including the single horizontal or dual vertical connectors for various LCDs, and I2C bus lines as well as ICSP connectors for the onboard ATTINY4313 microcontroller. The firmware can be updated and is available on the akafugu github repository. If you look at the horizontal row along the top – there are eighteen holes. This allows for displays that have pins ordered 1~16 and also those with 15,16,1~16 order (15 and 16 are for the LCD backlight).

The next step is to solder in the connectors for power and I2C if so desired, and then the LCD to the backpack. Double-check that you have the pin numbering and alignment correct before soldering, for example:

and then you’re finished:

Simple. Now apply power and after a moment the the backpack firmware will display the I2C bus address:

Success! Now let’s repeat this with the TWILCD 40×2/40×4/RGB version. The backpack itself is still quite small:

… and has various pin alignments for different types of LCD module. Note the extra pins allowing use of RGB-backlit modules and 40×4 character modules. Again,  make sure you have the pins lined up against your LCD module before soldering the backpack in:

 Notice how the I2C connector is between the LCD and the backpack – there is enough space for it to sit in there, and also acts as a perfect spacer when soldering the backpack to the display module.  Once finished soldering, apply 5/3.3V and GND to check your display:

Using the TWILCDs

Using the backpacks is very easy. If you aren’t using an Arduino, libraries for AVR-GCC are available. If you are using the Arduino system, it is very simple. Just download and install the library from here. Don’t forget to connect the SDA and SCL connectors to your Arduino. If you’re unsure about LCD and Arduino – see here.

Programming for the TWILCD is dead simple – just use your existing Arduino sketch, but replace


and that’s it. Even creating custom characters. No new functions to learn or tricks to take note of – they just work. Total win. The only new functions you will need are to control the brightness and contrast… to set the brightness, use:

You can also set the brightness level to EEPROM as a default using:

Contrast is equally simple, using:


You can see these in action using the example sketches with the Arduino library, and in the following video:

Now for the TWILCD 40×2/40×4/RGB version. You have one more function to set the colour of the text:

where red, green and blue are values between 0 and 254. Easily done. You can see this in action using the test_RGB example sketch included with the library, and shown in the following video:


The TWILCD backpacks are simple, easy to setup and easy to use. They make using LCD displays a lot easier and faster for rapid prototyping, experimenting or making final products easier to use and program. A well-deserved addition to every experimenter’s toolkit. For more information, visit the akafugu product website. Full-size images available on flickr.

Note – the products used in this article were a promotional consideration from akafugu.jp, however the opinions stated are purely my own.

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.

Translated version in Serbo-Croatian language.

Posted in akafugu, arduino, clocks, I2C, kit review, LCD, part review, rgbComments (0)

Kit Review – akafugu Simpleclock


Finally another kit review! Thanks to akafugu in Japan (the people who brought us the Akafuino-X) we have a new clock kit to assemble – the Simpleclock. But first, what is it?

A clock – yes. You can never have too many clocks. Also, a digital thermometer and an alarm clock. It is based on the Atmel ATmega328 and Arduino IDE, with open-source firmware. The real-time clock uses the DS1307 circuit with battery backup that we know and love. This means you can completely modify the clock or concoct a completely different use for your Simpleclock. Countdown timer? There’s an idea…

Furthemore, the display module is their individual I2C-interface TWI Display. Therefore you have a clock as well as some Arduino-based hardware to experiment with later on. However, let’s assemble it first.


Putting it all together was quite straight-forward. You can follow the detailed instructions at the akafugu site. All the parts required to make a functional clock as advertised are included with the kit:

Here are the brains of the operation – the pre-programmed microcontroller and the DS1307 real-time clock IC: 

You do receive an IC socket for the MCU, but not for the RTC – however this shouldn’t be an issue – just double-check your soldering and have some confidence. The PCBs are nicely laid out with solder-masking and a clear silk-screen:

The PCB on the left in the images above is for the display module – it runs an ATtiny microcontroller than can be worked with separately. Moving forward, you start with the lowest-profile components including the resistors and capacitors:

Take note of the vice – these are great, and light years ahead of the “helping hands” things you see around the traps. This was a Stanley model from element14. The resistors sit in nicely:

The next step is to put a blob of solder on the solder pad which will be beneath the backup battery holder – this forces contact between the negative side of the coin cell battery and the PCB:

Everything else went smoothly – I did have a small worry about the pin spacing for the USB power socket, however a clean tip and a steady hand solved that problem:

The rest of the clock board is much easier – just follow the instructions, take your time and relax. Soon enough you’ll be finished:

However I did have one “oops” moment – I left the PTC in too tall, so it needed to be bent over a little to give way for the display module when inserted:

The next task is to solder the four digit display to the display PCB – nothing new here:

Which leaves you with the standalone display module:

Using the Simpleclock

The firmware for clock use as described in the product page is already loaded in the MCU, so you can use it without needing and programming time or effort. It is powered via a mini-USB cable which you will need to acquire yourself. Frankly the design should have a DC socket and regulator – perhaps for the second revision :) With second thought, it’s better running from USB. When I turn on the computer in the morning the Simpleclock beeps and ‘wakes up’. The menu system is simple and setting the time and alarm is deceptively so. Some thought has been put into the user interface so once assembled, you could always give the clock away as a gift without fear of being asked for help. However mine is staying on top of the monitor for the office PC:

And here it is in action on the bench:

If you get the urge to modify and update the code, it is easily done. As the Simpleclock kit is open source, all the data required is available from Akafugu’s github page. Please read the notes and other documentation before updating your clock. The easiest way to physically upload the new code will be with a 5V FTDI to USB adaptor or cable.


The Simpleclock was easy to assemble and works very well. It would make a fun kit for those learning to solder, as they have something that once completed is a reminder of their success and useful in daily life. Apart from using USB for power instead of a DC socket – it’s a great kit and I would recommend it to anyone interested in clocks, enjoys kit assembly, or as a gift to a young one to introduce them to electronics and microcontrollers.

Note – the Simpleclock kit was a promotional consideration from akafugu.jp, however the opinions stated are purely my own.

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 akafugu, arduino, clocks, ds1307, I2C, kit review, tutorialComments (2)

Project: Clock Three – A pillow clock with LilyPad Arduino

A pillow clock? How? Read on…

Updated 18/03/2013

Time for another instalment in my irregular series of irregular clock projects. In contrast with the minimalism of Clock Two, in this article we describe how to build a different type of clock – using the “lilypad” style of Arduino-compatible board and components designed for use in e-textiles and wearable electronics. As the LilyPad system is new territory for us, the results have been somewhat agricultural. But first we will examine how LilyPad can be implemented, and then move on to the clock itself.

The LilyPad system

By now you should have a grasp of what the whole Arduino system is all about. If not, don’t panic – see my series of tutorials available here. The LilyPad Arduino boards are small versions that are designed to be used with sewable electronics – in order to add circuitry to clothing, haberdashery items, plush toys, backpacks, etc. There are a few versions out there but for the purpose of our exercise we use the Protosnap Lilypad parts which come in one PCB unit for practice, and then can be ‘snapped out’ for individual use. Here is an example in the following video:

The main circular board in the Arduino-type board which contains an ATmega328 microcontroller, some I/O pins, a header for an FTDI-USB converter and a Li-Ion battery charger/connector. As an aside, this package is  good start – as well as the main board you receive the FTDI USB converter, five white LEDs, a buzzer, vibration module, RGB LED, a switch, temperature sensor and light sensor. If you don’t want to invest fully in the LilyPad system until you are confident, there is a smaller E-Sewing kit available with some LEDs, a battery, switch, needle and thread to get started with.

Moving forward – how will the parts be connected? Using thread – conductive thread. For example:

This looks and feels like normal thread, and is used as such. However it is conductive – so it doubles as wire. However the main caveat is the resistance – conductive thread has a much higher resistance than normal hook-up wire. For example, measuring a length of around eleven centimetres has a resistance of around 11Ω:

So don’t go too long with your wire runs otherwise Ohm’s Law will come into play and reduce the available voltage. It is wise to try and minimise the distance between parts otherwise the voltage potential drop may be too much or your digital signals may have issues. Before moving on to the main project it doesn’t hurt to practice sewing a few items together to get the hang of things. For example, run a single LED from a digital output – here I was testing an LED by holding it under the threads:

Be careful with loose live threads – it’s easy to short out a circuit when they unexpectedly touch. Finally for more information about sewing LilyPad circuits, you can watch some talent from Sparkfun in this short lesson video:

And now to the Clock!

It will be assumed that the reader has a working knowledge of Arduino programming and using the DS1307 real-time clock IC. The clock will display the time using four LEDs – one for each digit of the time. Each LED will blink out a value which would normally be represented by the digit of a digital clock (similar to blinky the clock). For example, to display 1456h the following will happen:

  • LED 1 blinks once
  • LED 2 blinks four times
  • LED 3 blinks five times
  • LED 4 blinks six times

If a value of zero is required (for example midnight, or 1000h) the relevant LED will be solidly on for a short duration. The time will be set when uploading the sketch to the LilyPad, as having two or more buttons adds complexity and increases the margin for error. The only other hardware required will be the DS1307 real-time clock IC. Thankfully there is a handy little breakout board available which works nicely. Due to the sensitivity of the I2C bus, the lines from SDA and SCL to the LilyPad will be soldered. Finally for power, we’re using a lithium-ion battery that plugs into the LilyPad. You could also use a separate 3~3.3 V DC power supply and feed this into the power pins of the FTDI header on the LilyPad.

Now to start the hardware assembly. First – the RTC board to the LilyPad. The wiring is as follows:

  • LilyPad + to RTC 5V
  • LilyPad – to RTC GND
  • LilyPad A4 to RTC SDA
  • LilyPad A5 to RTC SCL
Here is an our example with the RTC board soldered in:

At this stage it is a good idea to test the real-time clock. Using this sketch, you can display the time data on the serial monitor as such:

Sewing it together…

Once you have the RTC running the next step is to do some actual sewing. Real men know how to sew, so if you don’t – now is the time to learn. For our example I bought a small cushion cover from Ikea. It is quite dark and strong – which reduces the contrast between the conductive thread and the material, for example:

However some people like to see the wires – so the choice of slip is up to you. Next, plan where you want to place the components. The following will be my rough layout, however the LilyPad and the battery will be sewn inside the cover:

The LilyPad LEDs have the current-limiting resistor on the board, so you can connect them directly to digital outputs. And the anode side is noted by the ‘+':

For our example we connect one LED each to digital pins six, nine, ten and eleven. These are also PWM pins so a variety of lighting effects are available. The cathode/negative side of the LED modules are connected together and then return to the ‘-‘ pad on the LilyPad. The actual process of sewing can be quite fiddly – so take your time and check your work. Always make note to not allow wires (threads) to touch unless necessary. It can help to hold the LilyPad up and let the cloth fall around it to determine the location of the LilyPad on the other side, for example:

As this was a first attempt – a few different methods of sewing the parts to the cloth were demonstrated. This becomes evident when looking on the inside of the slip:

… however the end product looked fair enough:

After sewing in each LED, you could always upload the ‘blink’ sketch and adapt it to the LEDs – a simple way to test your sewing/wiring before moving forward.

The sketch…

As usual with my clock projects the sketch is based around the boilerplate “get time from DS1307″ functions. There is also the function blinkLED which is used to control the LEDs, and the time-to-blinking conversion is done in the function displayTime. For those interested, download and examine the sketch.

The results!

Finally in the video clip below our pillow clock is telling the time – currently 1144h:

So there you have it, the third of many clocks we plan to describe in the future. Once again, this project is just a demonstration – so feel free to modify the sketch or come up with your own ideas.

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, BOB-00099, clocks, DEV-11032, DEV-11262, ds1307, DS3232, etextile, hardware hacking, I2C, Ikea, lilypad, microcontrollers, tronixstuff, tutorialComments (2)

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 (15)

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 (18)

Review – Akafugu TWI 7-Segment Display

Hello Readers

Today we review a 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 their TWI 7-segment display board. It consists of a four digit, seven-segment LED module driven by an Atmel ATtiny microcontroller – and has an I2C (or called TWI for “two-wire interface”) interface. By using I2C you only need power, GND, SDA and CLK lines – which saves on I/O and physical space.


The display arrives appropriately packaged in reusable bags, and the main board is sealed in an anti-static pouch:


The display board arrives partly-assembled. The MCU is presoldered to the board, so all we need to solder are the external connections on each side of the board, and the LED module. It is quite small and of an excellent quality:

The reason for having the power and data lines on both side is that you can then daisy-chain the displays. Speaking of which, the review unit arrived with a common-anode white LED module (data sheet.pdf) – however you can also order it in red or blue. Although they are not included, I soldered in a line of socket pins to allow for changing the LED module later on:

The final product is neat and compact, the view from the rear:

Note the ISP header pin sockets which allow low-level programming of the ATtiny4313 MCU. And the front:

akafugu also sell an optional housing stand, manufactured from transparent acrylic, which turns the display module into a nice little desk stand model:

Using the display module

Now to put the display to use. As it is controlled via I2C/TWI a variety of microcontroller platforms will be able to use the display. For our examples we will be using an Arduino-compatible board. Before moving forward you need to download and install the Arduino library which is available (as well as an avr-gcc library) on Github. Note that the example sketches in the Arduino library are for IDE v1.0.

As the module uses its own microcontroller, you can change the I2C bus address with a simple sketch (which is provided with the library). This is a great idea, which removes any chance of clashing with other bus devices, and allows more modules to be on the same bus. The default address is 0X12h.

When using the module, the following lines need to be in your sketch:

You can change the brightness mid-sketch using disp.setBrightness() with a parameter between zero and 255. To display an integer, use:

To turn on or off the decimal points, use:

To clear the display, use:

You can even display strings of text. Not every character can be displayed, however most can and the effect of scrolling looks good. For some example code:

Now to put the display to work! Using this IDE v1.0 demonstration sketch (download), we have created the following display:

For the curious, the current drawn with all segments on at full brightness is just over  33 milliamps:


When you need to display some numerical or other fitting data with a greater clarity than an LCD, or just love LEDs then you could do very well with this display. The designers have made a quality board and backed it up with documentation and (unlike many much larger, more prominent companies) a mature library to ensure it works first time. Furthermore the use of the I2C/TWI bus removes the problem of wasting digital output pins on your MCU – and the ability to change the bus address is perfect. So give akafugu a go and you will not be disappointed. The display 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.

Posted in arduino, I2C, kit reviewComments (7)

Review – Agilent Infiniivision MSO-X 3024A Mixed Signal Oscilloscope

Hello Readers

In this article we examine the Agilent Technologies Infiniivision MSO-X 3024A Mixed Signal Oscilloscope. Please note that the review unit has the latest version 2.0 firmware (existing owners can upgrade with the free download).

Initial Impressions

Unlike smaller instruments the packaging is plain and non-descript, however the MSO is protected very well for global shipping and arrived in perfect condition. Inclusions will vary depending on the particular model, however all come with a calibration certificate, user guide on CD and a power lead.


Four passive 300MHz probes are included with the MSO-X3024A:


Due to the constant upgrading of the firmware the lack of a printed user manual is no surprise. You can download the manual as well as the service, programming and  educational lab guides from the documents section of the product web page – which make good reading to get a feel for the unit.

Now for a tour around the unit. Coming from a smaller DSO or an analogue model, the first thing that strikes you is the display. 8.5” diagonal with 800×480 resolution:


Unlike cheaper brands the larger screen is not extrapolating data from a smaller image – each pixel is separately used. The front panel is clean and uncluttered. Each button and knob feels solid and responsive, and if pressed and held down, a small help window appears with information about the item pressed. Note that each analogue channel has independent controls for vertical position and V/div sensitivity (the minimum sensitivity is 1mV/division). This saves a lot of time and possible confusion when working on time-sensitive applications.

Around the back we find the cooling van ventilation on the left, the IEC AC power socket on the bottom-right, manufacturing data and so on. The fan is just audible, however the noise from a desktop computer drowns it out. On the far right near the top are separate USB connections for device and host mode, and the external trigger input and output sockets. Apart from the trigger out signal the socket can also be set to give a 5V pulse on a mask test failure or the optional WaveGen sync pulse.


Below this is a space for a Kensington lock cable, and the optional modules – the VGA/LAN adaptor or the GPIB bus module. On the right is my old faithful GW 20 MHz analogue CRO. Finally, there is a compartment on the top of the unit that can hold two probes comfortably, and four at a pinch:


As the unit is can be considered a small computer, it takes time to boot up – just over thirty seconds. (The operating system is Windows CE version 6.0). The user-interface is quite simple considering the capability of the unit. The six soft-keys below the display are used well, and also can call a separate list of options under each button.

When such a list is presented, you can also use the “Push to select” knob on the right hand side of the display to select an option and lock in by pressing the knob in. Below the soft keys from left to right are: BNC output for the optional function generator, digital inputs for logic analyser, USB socket for saving data to a USB drive, probe points for calibration and demonstration use, and four probe sockets. Connections exist that can interface with optional Agilent active probes.


This instrument falls within the range of Agilent’s new Infiniivision 3000-series oscilloscopes. The range begins with the DSO-X3012A with 100MHz bandwidth and two channels, through to the DSO-X3054A with 500 MHz bandwidth and four channels. Furthermore the range is extended with the MSO-X models that include a sixteen channel logic analyser.

Some of you will know there is also the Infiniivision 2000-series, and wonder why one would acquire a 3000-series. There are three excellent reasons for doing so:

  1. Waveform update rate is 50000 per second on a 2000, one million per second on a 3000;
  2. Memory depth on a 2000 is 100 kilopoints; 3000s have 2Mpts standard or 4Mpts optional;
  3. Eight vs. sixteen digital channels when specified as an MSO-X model.

For a full breakdown of specifications please download the Agilent data sheet located here.

Getting Started and general use

The process from cutting open the packaging to measuring a signal is quite simple – just plug it in, connect probes and go – however some probe compensation is required, which is explained quite well in the manual. There are strong tilting bales under the front side which can be used to face the unit upwards. At this point the unit is ready to go – you can start measuring by using the Auto Scale function and let the MSO-X3024A determine the appropriate display settings.

However there is no fun in that – the vertical scale can be manually adjusted between 1 mV and 50V per division, the horizontal between 2 nanoseconds and 50 seconds per division. These values can be selected rapidly or (by pressing the knob in) in a fine method for more precise values. If working with more than one channel, each can be labelled using a pre-set description or select a label from a list. One can also alter the display between X-Y, horizontal and roll modes.

Each channel has separate controls for coupling – DC/AC but no GND, as the earth point is shown on the LCD. Impedance can be 1M or 50 ohm. One can also limit bandwidth to 20MHz to remove high-frequency interference.

Capturing data is very easy, you can save images as .png or .bmp files in grey scale or colour , data in .csv form and so on. You can also assign popular functions to a “Quick Action” button – one press and it is done. For example I use this as a “save bitmap” button to send the screen image to the USB drive. If the optional LAN/VGA module is installed screens can be captured by the host computer via the network. Finally there is a very basic file explorer available to find files on the USB drive as well.

Waveforms can also be stored and used later on as references for other measurements. When reviewed they appear as an orange trace – for example R1:


The horizontal zoom mode activated using keys to the right of the horizontal control is very useful. Agilent call this “Mega Zoom” and it certainly works. Consider the following screen shot – the 32.768kHz square-wave from a Maxim DS1307 real-time clock is being analysed:


The time base is 10uS per division – and using the zoom we can get down to two nanoseconds per division and investigate the ringing on fall of the square-wave. This is great for investigating complex signals over short periods. Awesome.

Capturing infrequent events is made simple by the combination of the one million waveforms per second sampling rate, and the use of infinite display persistence. In the following example a clock with very infrequent glitch is being sampled. By setting persistence to infinite, as soon as the infrequent glitch occurs it can be displayed and held on the screen. For example:



There is a plethora of triggering options available. Standard modes include: edge, edge then edge, pulse-width (customisable), pattern trigger (for logic analyser – you can create your own patter of high, low, or doesn’t matter with comparison operators for duration), hex bus trigger, OR trigger, customisable rise/fall time trigger, nth edge burst trigger which allows  you to nth edge of a burst after an idle time, runt trigger on positive or negative pulse, setup and hold trigger, on video signals (PAL, PAL-M, NTSC, SECAM), and USB packets. Phew. Furthermore, if you have any of the optional decoding and analysis licenses, they include triggering on the matching signal type (see later).

Math modes

Performing math waveforms on analogue channels is done via a seperate Math button, and the operations available are addition, subtraction, multiplication, differentiation, integration, square root and FFT.

Waveform statistics

When the time comes to further analyse your measurement data, there area variety of measurements that can be taken, and they can be displayed individually, such as in the following:


or all in a summary screen:


Or you can manually use the cursors to determine information about any part of a wave form, for example:


Logic Analyser

Everything required is included with the MSO-X3024A for the sixteen channel logic analyser, including a very long dual-head probe cable:


as well as sixteen grabbers and some extension runs:


Setup and use was surprisingly simple, just connect the probe cable head to ground, insert grabbers onto the ends of each channel wire, and connect to the signal pins to analyse. You can have all sixteen channels and the four analogue channels active at once, however when doing so the screen is quite busy. You can adjust the height  for each digital channel. Here we are measuring two analogue and eight digital channels:


As always there are many forms of customisation. Automatic scaling is available the same as analogue measurement. You can set the threshold levels for high and low, and presets exist for TTL, CMOS, ECL and your own custom levels. The cable is very well-built (made in the USA) and the socket on the MSO is a standard, very solid IDC connector. Thanks to the use of the IDC connector you could also make your own probes or extension cable for the analyser. Digital channels can also be combined and displayed as a data bus, with the data values shown in hexadecimal or binary – for example:




Both the 2000- and 3000-series Infiniivision units have a variety of options and upgrades available either at the time of purchase or later on. Agilent have been clever and installed all the software-based options in the unit – when required they are “unlocked” by entering a licence key given after purchase. Trial 14-day licenses are generally available if you want to test an option before purchase. You can also upgrade the bandwidth after purchase – for example if you started with a 100MHz a licence key purchase will upgrade you to 200MHz , or 350 to 500MHz. However if you wish to upgrade a 200MHz to 350/500, this needs to be performed at at Agilent service facility. Surprisingly the logic analyser upgrade that converts a DSO-X to an MSO-X is user-installable. For more information on the upgrade options and procedures please visit here.

Memory Upgrade (DSOX3MEMUP)

A simple yet useful option – it doubles the total memory depth to 4 Mpts interleaved.


This options really opens up the MSO to the world (and is a lot of fun..) – it is inserted into the port at the rear of the unit:


VGA output is very simple – no setup required. Just plug in your monitor or projector and you’re ready to go -for example, with a 22″ LCD monitor:


The educational benefits of the LAN/VGA module are immediately apparent – instead of having twenty classmates huddle around one MSO while the instructor demonstrates the unit, the display can be show on the classroom projector or a large monitor. The MSO display is still fully active while VGA output is used.

LAN connection via Ethernet was also very simple. The MSO can automatically connect to the network if you have a router with DHCP server. Otherwise you can use the Utility>I/O>LAN Settings function to enter various TCP/IP settings and view the MSO’s MAC address.

Once connected you can have complete control of the MSO over your network. Apart from saving screen shots:


There is a “simple” remote control interface that contains all the controls in a standard menu-driven environment:


Or you can have a realistic reproduction of the entire MSO on your screen:


The full remote panel is completely identical – it’s “just like being there”. The ability to monitor your MSO from other areas could be very useful. For example using the mask testing in a QC area and watching the results in an office; or an educator monitoring students’ use of the MSO.

Furthermore you can view various data about the MSO, such as calibration date and temperature drift since calibration, installed options, serial number, etc. remotely via the web interface.


This allows you to connect your MSO to an IEEE-488 communications bus for connection to less contemporary equipment.

Segmented Memory Option (DSOX3SGM)

This options allows you to capture infrequent multiple events over time. For example, you want to locate some 15 mS pulses that occur a few times over the space of an hour. All you need to do is set the triggering to pulse-width, specify the minimum/maximum pulse width to trigger from, then hit Acquire>Segmented, the number of segments to use and you’re off. When the pulses have been captured, you can return and analyse each one as normal. The unit records the start time and elapsed time for each segment, and you can still use zoom, etc., to examine the pulse. For example:


Embedded Serial Triggering and Analysis (DSOX3EMBD)

Debugging I2C and SPI buses are no longer a chore with this option. For example with I2C just probe you SDA and SCK lines, adjust the thresholds in the menu option and you’re set. Apart from displaying the bytes of data below the actual waveform, there is a “Lister” which allows you to scroll back and forth along the captured data along with correlating times. In the following example a Maxim DS1307 RTC IC has been polled:


The Lister details all – in the example we sent a zero to address 0x68, which caused the DS1307 to return the seven bytes of time and date data. This is an extremely useful option and is very useful when working with a range of sensors and other parts that use the I2C bus. The SPI bus analysis operates in exactly the same manner. Adding this option also allows triggering on I2C data as well.

FlexRay Triggering and Analysis (DSOX3FLEX)

The optional FlexRay measurement applications offer integrated FlexRay serial bus triggering, hardware-based decoding and analysis. The FlexRay measurement tools help you more efficiently debug and characterize your FlexRay physical layer network by having the ability to trigger on and time-correlate FlexRay communication with your physical layer signals. So if you are working on the ECU of your Rolls-Royce or new BMW 7-series, you can use an MSO that matches the quality of the vehicle under examination. Here is an example of the FlexRay being monitored in the lister:


RS232/UART Serial Decode and Trigger (COMP/MSOX3000-232)

This option allows RS232, 422, 485 and UART decoding and triggering, as well as the use of the Lister to analyse the data. For example:


Advanced Math (DSOX3ADVMATH)

This option adds more math functions to enhance your waveform analysis, including: divide, base-10 logarithm, natural logarithm and exponential.

CAN/LIN Triggering and Serial Decode (DSOX3AUTO)

Again, allows decoding of automotive CAN and LIN bus signals, and the use of the Lister. For example:



Military Standard 1553 and ARINC429 Standards Serial Triggering and Decoding (DSOX3AERO)

The option exists for decoding and triggering of the above bus types. According to Agilent the Mil-STD 1553 serial bus is primarily used to interconnect avionics equipment in military aircraft and spacecraft(!). This bus is based on tri-level signaling (high, low, & idle) and requires dual-threshold triggering, which the 3000X supports. This bus is also implemented as a redundant multi-lane bus (dual-bus analysis), which is also supported by the 3000X.

The ARINC 429 serial bus is used to interconnect avionics equipment in civilian aircraft (Boeing & Airbus). This bus is also based on tri-level signaling (high, low, & null) and requires dual-threshold triggering, which the 3000X supports. Since ARINC 429 is a point-to-point bus, multi-lane analysis is also required to capture both send and receive data. So if you need this capability – Agilent has you covered.


Video Triggering and Analysis Application (DSOX3VID)

The DSOX3VIDEO option provides triggering on an array of HDTV standards, including:

  • 480p/60, 567p/50, 720p/50, 720p/60
  • 1080i/50, 1080i/60
  • 1080p/24, 1080p/25, 1080p/30, 1080p/50, 1080p/60
  • Generic (custom bi-level and tri-level sync video standards)

The 3000X Series oscilloscope already comes standard with NTSC, PAL, PAL-M, and SECAM support. Example of video analysis:


Audio Serial Triggering and Analysis (DSOX3AUDIO)

And not surprisingly this is an option to allow decoding of and triggering from I2S digital audio data. For example:


Mask Limit Testing (DSOX3MASK)

This is another interesting and useful option, idea for quality testing, benchmarking and so on. First you create a mask by measuring the ideal waveform, and then feed in the signal to be compared with the ideal mask. Mask limit testing can operate at up to 280000 comparisons per second. You can view pass/fail statistics, minimum sigma and so on, for example – a perfect test:


… then a change of frequency for a few cycles:


Furthermore you can specify the number of tests, change source channel, specify action upon errors, etc. Finally you can create and save to USB your own mask file for use later on – which can also be modified on a PC using any text editor software. Or for other monitoring options the external trigger socket on the read of the MSO can be configured to give a 5V pulse on a mask test failure.

If you have the LAN/VGA module you could place the MSO on in a lab or factory situation and monitor the testing over the network using a PC – very handy for QC managers or those who need to move about the workplace and still monitor testing in real time.

20MHz Function Generator/Arbitrary Waveform Generator (DSOX3WAVEGEN)

The “WaveGen” function is a versatile option that offers a highly controllable 20 MHz function generator and arbitrary waveform generator. It offers eleven different types of waveform: sine, square, ramp, pulse, DC, noise, sine cardinal, exponential rise and fall, cardiac and gaussian pulse.

The frequency can be adjusted between 100mHz to 20 MHz in 100 mHz steps; period from 50ns to 10s; full offset, amplitude and symmetry control; as well as logic level preset outputs (such as TTL, CMOS 5V, 3.3V etc.) Finally the WaveGen can be operated independently to normal measurement tasks, which is useful for ideal vs. actual comparisons and so on. Output is from the BNC socket at the bottom-left of the front pane and sync is also availble from the rear BNC socket. The arbitrary waveform generator is very simple to use  – and copied waveforms can be edited or have noise added to them to replicate real-world waveforms.

Power Measurement (DSOX3PWR)

This is a power measurement and analysis option that is integrated into the unit and provides a quick and easy way of analysing the reliability and efficiency of switching power supplies. It also includes a user license for U1881A-003 PC-based power measurement and analysis software that provides even more powerful insight into power supply measurement. With this option you can:

  • Measure switching loss and conduction loss at the switching device (to help improve efficiency)
  • Analyse dI/dt and dV/dt slew rate (for reliable operation)
  • Automate oscilloscope set-up for ripple measurements (to eliminate tedious manual oscilloscope set up)
  • Perform pre- compliance testing to IEC 61000- 3- 2 standards (to reduce compliance testing time)
  • Analyse line power with total harmonic distortion, true power, apparent power, power factor, and crest factor tests (to quickly provide power quality information)
  • Measure output noise (ripple)
  • Analyse modulation using the on- time and off- time information of a Pulse Width Modulation (PWM) signal (to help characterize the active power factor)
  • Measure how well a circuit rejects ripple coming from the input power supply at various frequencies with the Power Supply Rejection Ratio (PSRR) measurement.
For more indepth explanation of this option download and read the well written manual.


Well not a feature as such, but it exists if you know where to find it:


Initial Conclusions

There is no doubt that the Infiniivision 3000-series are a great line of instruments. The waveform sample rate, memory size and bandwidth options are very competitive, and the ability to add various options is convenient and also helps lower the final cost for purchasing departments. (Start with the base model then hit them up for the options over time)

However there are a few things that could use improvement. Although the display is excellent – the right-hand column with “Agilent” at the top is always displayed. This is a waste of LCD space and there should be an option to turn it off, allowing waveforms to be displayed across the entire screen. If a $400 Rigol can do this, so should a $5000+ Agilent. The build unit of the unit is good, no problems are evident however it could be a little more “solid”; and the option of a clear shield for the LCD would be a great idea to protect against forceful and dirty fingers.

Furthermore the ground demonstration terminal suffers from metal fatigue very quickly, it already is somewhat chipped and may need replacing if you used it quite often. Finally, it would have been nice to see Agilent include the a carry bag – already people have asked to borrow the unit and to wander around with it in the box is somewhat awkward.

For those who rely on their test equipment will have the peace of mind that Chinese discount suppliers cannot give you – Agilent support exists and will not ignore you once a sale has been made. It doesn’t take long to find a tale of woe on an Internet forum from someone who imported their own “high-spec” DSO via eBay or direct east-Asian sellers only to find there are no firmware updates, competent English-speaking support or warranty of any kind. Furthermore, the ability to combine many functions in the one piece of equipment saves space, time and reduces your support channel back to one supplier. There is also an iPhone “app” that may be of interest – however as an Android user I haven’t tried it.

The saying “Quality is remembered long after price is forgotten” certainly holds true – and at the end of the day combined with the mix of standard and optional features at various price points – the Agilent Infiniivision MSO-X 3024A rises to the top echelon of test equipment.

 The Agilent Technologies Infiniivision MSO-X 3024A Mixed Signal Oscilloscope used in this review is a promotional consideration received from Agilent and element-14 via their Road Test program.

Agilent Test and Measurement equipment is available from your local element-14Farnell or Newark distributor.

Australian readers please note:  Trio Smartcal are the exclusive Australian Agilent distributors for all states except WA and NT – telephone 1300 853 407.

Measurement Innovation for WA and NT – telephone 08 9437 2550

High-resolution images are available on flickr.

Once again thanks for reading, 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 agilent, DSO, MSOX3024A, oscilloscope, review, test equipment, tutorial

Kit Review – Snootlab DeuLigne LCD Arduino Shield

Hello everyone

Another month and time for another kit review :) Once again we have another kit from the team at Snootlab in France – their DeuLigne LCD Arduino shield. Apart from having a two row, sixteen character backlit LCD there is also a five-way joystick (up, down, left, right and enter) which is useful for data entry and so on.

This LCD shield is different to any others I have seen on the market as it uses the I2C bus for interface with the LCD screen – thereby not using any digital pins at all. The interfacing is taken care of by a Microchip MCP23008 8-bit port expander IC, and Snootlab have written a custom LCD library which makes using the LCD very simple. Furthermore the joystick uses the analog input method, using analogue pin zero. But for now, let’s examine construction.

Please note that the kit assembled in this article is a version 1.0, however the shield is now at version 1.1. Construction is very easy, starting with the visual and easy to follow instructions (download). The authors really have made an effort to write simple, easy to follow instructions. The kit arrives as expected, in a reusable anti-static pouch:

As always everything was included, including stacking headers for Arduino. It’s great to see them included, as some other companies that should know better sometimes don’t. (Do you hear me Sparkfun?)

The PCB is solid and fabricated very nicely – the silk screen is very descriptive, and the PCB is 1.7mm thick. The joystick is surface-mounted and already fitted. Here’s the top:

… and the bottom:

Using a Freetronics EtherTen as a reference,  you can see that the DeuLigne PCB is somewhat larger than the standard Arduino shield:

The first components to solder in are the resistors:

… followed by the transistor and MCP23008. Do not use an IC socket, as this will block the LCD from seating properly…

After fitting the capacitor, contrast trimpot, LCD header pins and stacking sockets the next step is to bolt in the LCD with the standoffs:

The plastic bolts can be trimmed easily, and then glued to the nuts to stay tight. Or you can just melt them together with the barrel of your soldering iron :) Finally you can solder in the LCD data pins and the shield is finished:

The only thing that concerned me was the limited space between LCD pins twelve~sixteen and the stacking header sockets. It may be preferable to solder the stacking sockets last to avoid possibly melting them when soldering the LCD. Otherwise everything was simple and construction took just under twenty minutes.

Now to get the shield working. Download and install the DeuLigne Arduino library, and then you can test your shield with the included examples. The LCD contrast can be adjusted with the trimpot between the joystick and the reset button. Note that this shield is fully Open Hardware compliant, and all the design files and so on are available from the ‘download’ tab of the shield product page.

Initialising the LCD requires the following code before void Setup():

Then in void Setup():

Now you can make use of the various LCD functions, including:

Reading the joystick position is easy, the function

returns an integer to pos representing the position. Right = 0, left = 3, up = 1, down = 2, enter = 4. Automatic text scrolling can be turned on and off with:

Creating custom characters isn’t that difficult. Each character consists of eight rows of five pixels. Create your character inside a byte array, such as:

There is an excellent tool to create these bytes here. Then allocate the custom character to a position number (0~7) using:

Then to display the custom character, just use:

And the resulting character filling the display:

Now for an example sketch to put it all together. Using my modified Freetronics board with a DS1307 real-time clock IC, we have a simple clock that can be set by using the shield’s joystick. For a refresher on the clock please read this tutorial. And for the sketch:

As you can see, the last delay statement is for 400 milliseconds. Due to the extra overhead required by using I2C on top of the LCD library, it slows down the refresh rate a little. Moving forward, a demonstration video:

So there you have it. Another useful, fun and interesting Arduino shield kit to build and enjoy. Although it is no secret I like Snootlab products, it is a just sentiment. The quality of the kit is first rate, and the instructions and support exists from the designers. So if you need an LCD shield, consider this one.

For support, visit the Snootlab website and customer forum in French (use Google Translate). However as noted previously the team at Snootlab converse in excellent English and have been easy to contact via email if you have any questions. Snootlab products including the Snootlab DeuLigne are available directly from their website. High-resolution images available on flickr.

So 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.

[Disclaimer - the products reviewed in this article are promotional considerations made available by Snootlab]

Posted in arduino, DeuLigne, I2C, kit review, LCD, snootlab, tutorialComments (2)

Tutorial: Arduino and multiple thumbwheel switches

This is an addendum to chapter forty of a series originally titled “Getting Started/Moving Forward with Arduino!” by John Boxall – a series of articles on the Arduino universe. The first chapter is here, the complete series is detailed here. Any files from tutorials will be found here.

Updated 24/11/2012

This article continues with the push-wheel switches introduced in chapter 40. In the previous article, we learned how to read the value of a single digit using the digital pins of our Arduino. With this instalment we will examine how to read four digits – and not waste all those digital pins in the process. Instead, we will use the Microchip MCP23017 16-bit port expander IC that communicates via the I2C bus. It has sixteen digital input/output pins that we can use to read the status of each switch.

Before moving forward, please note that some assumed knowledge is required for this article – the I2C bus (parts one and two) and the MCP23017.

We first will describe the hardware connections, and then the Arduino sketch. Recall the schematic used for the single switch example:


When the switch was directly connected to the Arduino, we read the status of each pin to determine the value of the switch. We will do this again, on a larger scale using the MCP23017. Consider the pinout diagram:

We have 16 pins, which allows four switches to be connected. The commons for each switch still connect to 5V, and each switch contact still has a 10k pull-down resistor to GND. Then we connect the 1,2,4,8 pins of digit one to GPBA0~3; digit two’s 1,2,4,8 to GPA4~7; digit three’s 1,2,4,8 to GPB0~3 and digit four’s 1,2,4,8 to GPB4~7. For demonstration purposes we are using the Gravitech 7-segment shield as reviewed in the past.

Now how do we read the switches? All those wires may cause you to think it is difficult, but the sketch is quite simple. When we read the value of GPBA and B, one byte is returned for each bank, with the most-significant bit first. Each four bits will match the setting of the switch connected to the matching I/O pins.

For example, if we request the data for both IO banks and the switches are set to 1 2 3 4 – bank A will return 0010 0001 and bank B will return 0100 0011. We use some bitshift operations to separate each four bits into a separate variable – which leaves us with the value of each digit. For example, to separate the value of switch four, we shift the bits from bank B >> 4. This pushes the value of switch three out, and the blank bits on the left become zero. To separate the value for switch three, we use a compound bitwise & – which leaves the value of switch three.

Below is a breakdown of the binary switch values – it shows the raw GPIOA and B byte values, then each digit’s binary value, and decimal value:

So let’s see the demonstration sketch :

And for the non-believers … a video demonstration:

So there you have it. Four digits instead of one, and over the I2C bus conserving Arduino digital I/O pins. Using eight MCP23017s you could read 32 digits at once. Have fun with doing that!


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, I2C, lesson, MCP23017, microcontrollers, push wheel switch, tutorialComments (2)

Tutorial: Maximising your Arduino’s I/O ports with MCP23017

This is chapter forty-one of a series originally titled “Getting Started/Moving Forward with Arduino!” by John Boxall – a series of articles on the Arduino universe. The first chapter is here, the complete series is detailed here.

[Updated 24/02/2014]

In this article we discuss how to use the Microchip MCP23017 16-bit serial expander with I2C serial interface. This 28-pin IC offers sixteen inputs or outputs – and up to eight of the ICs can be used on one I2C bus… offering a maximum of 128 extra I/O ports. A few people may be thinking “Why not just get an Arduino Mega2560?” – a good question. However you may have a distance between the Arduino and the end-point of the I/O pins – so with these ICs you can run just four wires instead of a lot more; save board space with custom designs, and preserve precious digital I/O pins for other uses. Plus I think the I2C bus is underappreciated! So let’s get started…

Here is our subject of the article in DIP form:

At this point you should also download yourself a copy of data sheet – it will be referred to several times, and very useful for reference and further reading. Furthermore if you are not familiar with Arduino and the I2C bus, please familiarise yourself with the I2C tutorials parts one and two. The MCP23017 can be quite simple or complex to understand, so the goal of this article is to try and make it as simple as possible. After reading this you should have the knowledge and confidence to move forward with using a MCP23017.

First, let’s look at the hardware basics of this IC. Consider the pinouts:

The sixteen I/O ports are separated into two ‘ports’ – A (on the right) and B (on the left. Pin 9 connects to 5V, 10 to GND, 11 isn’t used, 12 is the I2C bus clock line (Arduino Uno/Duemilanove analogue pin 5, Mega pin  21), and 13 is the I2C bus data line (Arduino Uno/Duemailnove analogue pin 4, Mega pin 20). External pull-up resistors should be used on the I2C bus – in our examples we use 4.7k ohm values. Pin 14 is unused, and we won’t be looking at interrupts, so ignore pins 19 and 20. Pin 18 is the reset pin, which is normally high – therefore you ground it to reset the IC. So connect it to 5V!

Finally we have the three hardware address pins 15~17. These are used to determine the I2C bus address for the chip. If you connect them all to GND, the address is 0x20. If you have other devices with that address or need to use multiple MCP23017s, see figure 1-2 on page eight of the data sheet. You can alter the address by connecting a combination of pins 15~17 to 5V (1) or GND (0). For example, if you connect 15~17 all to 5V, the control byte becomes 0100111 in binary, or 0x27 in hexadecimal.

Next, here is a basic schematic illustrating how to connect an MCP23017 to a typical Arduino board. It contains the minimum to use the IC, without any sensors or components on the I/O pins:

Now to examine how to use the IC in our sketches.

As you should know by now most I2C devices have several registers that can be addressed. Each address holds one byte of data that determines various options. So before using we need to set whether each port is an input or an output. First, we’ll examine setting them as outputs. So to set port A to outputs, we use:

Then to set port B to outputs, we use:

So now we are in void loop()  or a function of your own creation and want to control some output pins. To control port A, we use:

To control port B, we use:

… replacing ?? with the binary or equivalent hexadecimal or decimal value to send to the register.

To calculate the required number, consider each I/O pin from 7 to 0 matches one bit of a binary number – 1 for on, 0 for off. So you can insert a binary number representing the status of each output pin. Or if binary does your head in, convert it to hexadecimal. Or a decimal number. So for example, you want pins 7 and 1 on. In binary that would be 10000010, in hexadecimal that is 0x82, or 130 decimal. (Using decimals is convenient if you want to display values from an incrementing value or function result).

If you had some LEDs via resistors connected to the outputs, you would have this as a result of sending 0x82:

For example, we want port A to be 11001100 and port B to be 10001000 – so we send the following (note we converted the binary values to decimal):

… with the results as such (port B on the left, port A on the right):

Now let’s put all of this output knowledge into a more detailed example. From a hardware perspective we are using a circuit as described above, with the addition of a 560 ohm resistor followed by an LED thence to ground from on each of the sixteen outputs. Here is the sketch:

And here is the example blinking away:

Although that may have seemed like a simple demonstration, it was created show how the outputs can be used. So now you know how to control the I/O pins set as outputs. Note that you can’t source more than 25 mA of current from each pin, so if switching higher current loads use a transistor and an external power supply and so on.

Now let’s turn the tables and work on using the I/O pins as digital inputs. The MCP23017 I/O pins default to input mode, so we just need to initiate the I2C bus. Then in the void loop() or other function all we do is set the address of the register to read and receive one byte of data.

For our next example, we have our basic sketch as described at the start of this article using four normally-open buttons (once again using the ‘button board‘) which are connected to port B inputs 0~3. Consider the first five lines of void loop() in the following example:

In this example void loop() sends the GPIOB address (0x13) to the IC. Then using Wire.requestFrom() it asks for one byte of data from the IC – the contents of the register at 0x13. This byte is stored in the variable inputs. Finally if inputs is greater than zero (i.e. a button has been pressed) the result is sent to the serial monitor window and displayed in binary. We display it in binary as this represents the state of the inputs 0~7. Here is an example of pressing the buttons 1, 2, 3 then 4 – three times:

And as we are reading eight inputs at once – you can detect multiple keypresses. The following is an example of doing just that:

As you can see pressing all four buttons returned 1111, or the first and third returned 101. Each combination of highs and lows on the inputs is a unique 8-bit number that can also be interpreted in decimal or hexadecimal. And if you wanted to read all sixteen inputs at once, just request and store two bytes of data instead of one.

For our last example – a demonstration of using port A as outputs and port B as inputs. Four LEDs with matching resistors are connected to port A outputs 0~3, with the buttons connected as per example 41.2. Here is the sketch:

By now there shouldn’t be any surprises in the last example – it receives a byte that represents port B, and sends that byte out to port A to turn on the matching outputs and LEDs. For the curious, here it is in action:

So there you have it… another way to massively increase the quantity of digital I/O pins on any Arduino system by using the I2C bus. You can get the MCP23017 from Tronixlabs.


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, I2C, lesson, MCP23017, microcontrollers, tutorial

Review: Gravitech 7-Segment Arduino Shield

Hello Readers

In this article we examine the “7-Segment Arduino Shield” received for review from the team at Gravitech in the United States. This is an Arduino Uno/Duemilanove-type compatible shield that contains four very useful items:

  • Four 7-segment LED numerical displays – driven by the NXP SAA1064 LED display driver IC;
  • A large 10mm RGB LED;
  • A Microchip 24LC128 EEPROM, and
  • A TI TMP75 digital temperature sensor.
Apart from the LED all the other components are controlled via the I2C bus. So as well as being generally useful for experimenting, monitoring temperature and so on, this is an ideal board for Arduino and I2C bus practice. (If you have not done so already, consider reading our I2C tutorial, part one and two). Let’s look at the hardware, then move on to using the features.
As with other Gravitech products, the shield arrives in a reusable static shielding bag:
and here we have it:
The IC at the top-left of the shield is the TMP75 temperature sensor, bottom-left is the 24LC128 EEPROM, and the whopper below the first two digits is the NXP SAA1064. The shield layout is very neat and clean, and the white finish is a pleasant change compared to the usual black or green Arduino shields out there. The PWR LED is a blue colour. The only issues I found were that you cannot use this with a Mega due to the location of the I2C pins, and the component leads were not trimmed at the factory, which caused an issue when the shield was inserted into an Ethernet shield. This is easily solved by clipping the leads yourself:
Here is the shield in operation using the supplied demonstration sketch. The temperature is displayed in Celsius, with the LED changing colour depending on the temperature:

That is all very good, but how do we use the features of the board? Let’s look at each of the aforementioned features individually. First of all, the numeric display. The four seven-segment LED displays are controlled by the NXP SAA1064 LED display driver (data sheet (.pdf)). I have written a separate tutorial on how to use this IC, and it is completely compatible with this shield. So visit the tutorial here and put the numbers to work! Please note the I2C bus address for the SAA1064  is 0x38.

Next we have the RGB LED. Red, green and blue are connected to digital pins 3, 5 and 6 respectively. These are also pulse-width modulation pins, so you can have altering the brightness. Here is a simple demonstration sketch:

And for the curious, here it is in action:

Next, the Microchip 24LC128 EEPROM. It has 128kbit storage space, which translates to 16 kilobytes. The I2C bus address is 0x50. Once again there is a complete explanation of how to use this sort of EEPROM in another tutorial – check it out. But for quick reference the following demonstration sketch writes the numbers 0~255 to memory locations 0~255:

Although there is 16 kilobytes of memory the sketch only writes and reads to the first 255 locations. Each location can store a byte of value between zero and 255. Here is a screen shot of the serial monitor results (click to enlarge):

And now time to work with the Texas Instruments TMP75 temperature sensor (data sheet.pdf). It has a reasonable operating temperature range of between -40 and 125 degrees Celsius – however this would exceed the range in which your Arduino is capable of working, so no leaving the shield on the car dashboard during a hot summer’s day. The I2C bus address for the TMP75 is 0x49. We will deconstruct the Gravitech demonstration sketch to explain how the temperature works.

The TMP75 needs to be initialised before measurement can take place, by sending the following data:

The temperature data is received in two bytes of data, as it spans 12 bits. Thankfully the demonstration sketch has done the work for us. Have a look at the Cal_temp() function, which converts the two raw bytes of data from the TMP75. There is some bitwise arithmetic in there, however if you are not keen on going down to that level, it is easy enough to cut and paste the temperature and numeric display functions.  Here is a quick video of the demonstration sketch in action:


So there you have it – another useful and educational shield for use with your Arduino. If you have any questions or enquiries please direct them to Gravitech via their contact page. Gravitech products including the 7-segment shield are available directly from their website or these distributors.

As always, thank you for reading and I look forward to your comments and so on. Furthermore, don’t be shy in pointing out errors or places that could use improvement. Please subscribe using one of the methods at the top-right of this web page to receive updates on new posts, follow on twitterfacebook, or join our Google Group.

[Disclaimer - the shield reviewed in this article was a  promotional consideration made available by Gravitech]

High resolution photos are available on flickr.

Posted in 24LC128, arduino, gravitech, I2C, LED, microcontrollers, product review, review, SAA1064, TMP75, tutorialComments (0)

Tutorial: Arduino and Thumbwheel switches

This is chapter forty of a series originally titled “Getting Started/Moving Forward with Arduino!” by John Boxall – a series of articles on the Arduino universe. The first chapter is here, the complete series is detailed here. Any files from tutorials will be found here.

[Updated 20/01/13]

In this article we go back to the past via the use of push-wheel/thumbwheel switches with out Arduino systems. Here are some examples sourced from somewhere on eBay:

For the uninitiated, each switch is one vertical segment and they can be connected together to form various sizes. You can use the buttons to select from digits zero through to nine. There are alternatives available that have a wheel you can move with your thumb instead of the increase/decrease buttons. Before the days of fancy user interfaces these switches were quite popular methods for setting numerical data entry. However they are still available today, so let’s see how they work and how we can use them. The switch’s value is made available via binary-coded decimal. Consider the rear of the switch:

We have common on the left, then contacts for 1, 2, 4 and 8. If you apply a small voltage (say 5V) to common, the value of the switch can be measured by adding the values of the contacts that are in the HIGH state. For example, if you select 3 – contacts 1 and 2 will be at the voltage at common. The values between zero and nine can be represented as such:


By now you should realise that it would be easy to read the value of a switch – and you’re right, it is. We can connect 5V to the common,  the outputs to digital input pins of our Arduino boards, then use digitalRead() to determine the value of each output. In the sketch we use some basic mathematics to convert the BCD value to a decimal number. So let’s do that now.

From a hardware perspective, we need to take into account one more thing – the push-wheel switch behaves electrically like four normally-open push buttons. This means we need to use pull-down resistors in order to have a clear difference between high and low states. So the schematic for one switch would be (click image to enlarge):


Now it is a simple matter to connect the outputs labelled 1, 2, 4, and 8 to (for example) digital pins 8, 9, 10 and 11. Connect 5V to the switch ‘C’ point, and GND to … GND. Next, we need to have a sketch that can read the inputs and convert the BCD output to decimal. Consider the following sketch: