Tutorial – Parallax Ping))) Ultrasonic Sensor

Sense distance with ultrasonic sensors in chapter forty-five 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 05/02/2013

Whilst being a passenger in a vehicle with a ‘reversing sensors’, I became somewhat curious as to how the sensors operated and how we can make use of them. So for this chapter we will investigate an ultrasonic sensor from Parallax called the Ping)))™ Ultrasonic Distance Sensor. It can measure distances between ~2cm and ~3m in length. Here is our example sensor:

(Memories of Number Five …)

Parallax have done a lot of work, the board contains not just the bare sensor hardware but controller circuitry as well:

Which is great as it leaves us with only three pins – 5V, GND and signal. More on those in a moment, but first…

How does it work?

Good question. The unit sends out an ultrasonic (a sound that has a frequency which is higher than can be heard by the human ear) burst of sound from one transducer (the round silver things) and waits for it bounce off an object and return – which is detected by the other transducer. The board will then return to us the period of time taken for this process to take, which we can interpret to determine the distance between the sensor and the object from which the ultrasonic sound bounced from.

The Ping))) only measures a distance when requested – to do this we send a very short HIGH pulse of five microseconds to the signal pin. After a brief moment a pulse will come from the board on the same signal pin. The period of this second pulse is the amount of time the sound took to travel out and back from the sensor – so we divide it by two to calculate the distance. Finally, as the the speed of sound is 340 metres per second, the Arduino sketch can calculate the distance to whatever units required.

It may sound complex, but it is not –  so let’s run through the theory of operation with an example. Using our digital storage oscillscope we have measured the waveforms on the signal pin during a typical measurement. Consider the following example of measuring a distance of 12cm:

You can see the 5uS pulse in the centre and the pulse returned from the sensor board on the right. Now to zoom in on the returned pulse:

Without being too picky the pulse is roughly 720uS (microseconds) long – the duration of ultrasonic sound’s return trip from the sensor board. So we divide this by two to find the time to travel the distance – 360uS. Recall the speed of sound is 340 metres per second – which converts to 29.412 uS per centimetre. So, 360uS divided by 29.412 uS gives 12.239902081… centimetres. Rounded that gives us 12 centimetres. Easy!

Finally, there are some limitations to using the Ping))) sensor. Download the data sheet (pdf) and read pages three to five for information on how to effectively mount the sensor and the sensitivity results from factory resting.

How do we use it with Arduino?

As described previously we first need to send a 5uS pulse, then listen for the return pulse. The following sketch does just that, then converts the data to centimetres and displays the result on the serial monitor. The code has been commented to explain each step.

And the results of some hand-waving in the serial monitor:

So there you have it – you can now measure distance with a degree of accuracy. However that image above isn’t very exciting – instead let’s use a 7-segment display shield to get things up in lights. The shield uses the NXP SAA1064 LED display driver IC (explained quite well here). You can download the demonstration sketch from here. And now for the video:

So there you have it – now the use of the sensor is up to your imagination. Stay tuned using the methods below to see what we get up to with this sensor in the future.

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.

Using an ATtiny as an Arduino

Learn how to use ATtiny45 and ATtiny85 microcontrollers with Arduino in chapter forty-four 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 07/10/2014

Did you know you can use an Atmel ATtiny45 or ATtiny85 microcontroller with Arduino software? Well you do now. The team at the High-Low Tech Group at MIT have published the information and examples on how to do this, and it looked like fun – so the purpose of this article is to document my experience with the ATtiny and Arduino and share the instructions with you in my own words. All credit goes to the interesting people at the MIT HLT Group for their article and of course to Alessandro Saporetti for his work on making all this possible.

Introduction

Before anyone gets too excited – there are a few limitations to doing this…

Limitation one – the ATtiny has “tiny” in the name for a reason:

it’s the one on the left

Therefore we have less I/O pins to play with. Consider the pinout for the ATtiny from the data sheet:

So as you can see we have thee analogue inputs (pins 7, 3 and 2) and two digital outputs with PWM (pins 5 and 6). Pin 4 is GND, and pin 8 is 5V.

Limitation two – memory. The ATtiny45 has 4096 bytes of flash memory available, the -85 has 8192. So you may not be controlling your home-built R2D2 with it.

Limitation three – available Arduino functions. As stated by the HLT article, the following commands are supported:

Other functions may work or become available over time.

Limitation four – You need Arduino IDE v1.0.1 or higher, except for v1.0.2. So v1.0.3 and higher is fine.

So please keep these limitations in mind when planning your ATtiny project.

Getting Started

You can use an existing Arduino-compatible board as a programmer with some external wiring. Before wiring it all up – plug in your Arduino board, load the IDE and upload the ArduinoISP sketch which is in the File>Examples menu. Whenever you want to upload a sketch to your ATtiny, you need to upload the ArduinoISP sketch to your Arduino first. Consider this sketch the “bridge” between the IDE and the ATtiny.

Next, build the circuit as shown below:

Depending on the Arduino board you’re using, you may or may not need the 10uF capacitor between Arduino RST and GND. Follow the schematic above each time you want to program the ATtiny.

Software

From a software perspective, to use the ATtinys you need to add some files to your Arduino IDE. First, download this zip file. Then extract the”attiny” folder and copy it to the “hardware” folder which sits under your main Arduino IDE folder, for example:

Now restart the Arduino IDE. As you’re using the Arduino as a programmer, you need select “Arduino as ISP” – which is found in the Tools>Programmer menu. Next – select the board type using the Tools>Board  menu. Select the appropriate ATtiny that you’re using – with the 1 MHz internal clock option. Now you can enter and upload your ATtiny sketch. When uploading sketches you may see error messages as shown below:

The message is “normal” in this situation, so nothing to worry about.

Creating Arduino sketches for ATtinys

When creating your sketches, note that the pin number allocations are different for ATtinys in the IDE. Note the following pin number allocations:

• digital pin zero is physical pin five (also PWM)
• digital pin one is physical pin six (also PWM)
• analogue input two is physical pin seven
• analogue input three is physical pin two
• analogue input four is physical pin three

For a quick demonstration, load the Blink example sketch – File>Examples>1. Basics>Blink. Change the pin number for the digital output from 13 to 0. For example:

Upload the sketch using the methods described earlier. If you’re using programmer method one, your matching circuit is:

If you’re using programmer method two, this will blink the on-board LED.

Final example

We test the digital outputs with digital and PWM outputs using two LEDs instead of one:

And the sketch:

And a quick demonstration video:

So there you have it – another interesting derivative of the Arduino system. Once again, thanks and credit to Alesssandro Saporetti and the MIT HLT Group for their published information. And if you enjoyed this article, or want to introduce someone else to the interesting world of Arduino – check out my book “Arduino Workshop”.

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.

Tutorial: Arduino and Numeric Keypads – Part Two

Use larger numeric keypads in this addendum to chapter forty-two 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.

Welcome back fellow arduidans!

This is the second part of our numeric keypad tutorial – in which we use the larger keypads with four rows of four buttons. For example:

Again, the keypad looks like a refugee from the 1980s – however it serves a purpose. Notice that there are eight connections at the bottom instead of seven – the extra connection is for the extra column of buttons – A~D. This example again came from Futurlec. For this tutorial you will need the data sheet for the pinouts, so download it from here (.pdf).

Now for our first example – just to check all is well. From a hardware perspective you will need:

• An Arduino Uno or 100% compatible board
• An LCD of some sort. We will be using an I2C-interface model. If you are unsure about LCD usage, please see this tutorial
• If you don’t have an LCD – that’s ok. Our demonstration sketch also sends the key presses to the serial monitor. Just delete the lines referring to Wire, LCD etc.
Connect the keypad to the Arduino in the following manner:
• Keypad row 1 (pin eight) to Arduino digital 5
• Keypad row 2 (pin 1) to Arduino digital 4
• Keypad row 3 (pin 2) to Arduino digital 3
• Keypad row 4 (pin 4) to Arduino digital 2
• Keypad column 1 (pin 3) to Arduino digital 9
• Keypad column 2 (pin 5) to Arduino digital 8
• Keypad column 3 (pin 6) to Arduino digital 7
• Keypad column 4 (pin 7) to Arduino digital 6
Now for the sketch – take note how we have accommodated for the larger numeric keypad:
• the extra column in the array char keys[]
• the extra pin in the array colPins[]
• and the byte COLS = 4.

And our action video:

Now for another example – we will repeat the keypad switch from chapter 42 – but allow the letters into the PIN, and use the LCD instead of LEDs for the status. In the following example, the PIN is 12AD56. Please remember that the functions correctPIN() and incorrectPIN() are example functions for resulting PIN entry – you would replace these with your own requirements, such as turning something on or off:

Now let’s see it in action:

So now you have the ability to use twelve and sixteen-button keypads with your Arduino systems.

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.

Tutorial: Arduino Port Manipulation

Control Arduino I/O pins faster and with less code in chapter forty-three of a series originally titled “Getting Started/Moving Forward with Arduino!” by John Boxall – a series of articles on the Arduino universe.

[Updated 19/01/13]

In this article we are going to revisit the I/O pins, and use what is called “Port Manipulation” to control them in a much faster manner than using digitalWrite()/digitalRead().

Why?

Speed! Using this method allows for much faster I/O control, and we can control or read groups of I/O pins simultaneously, not one at a time;

Memory! Using this method reduces the amount of memory your sketch will use.

Once again I will try and keep things as simple as possible. This article is written for Arduino boards that use the ATmega168 or ATmega328 microcontrollers (used in Arduino Duemilanove/Uno, Freetronics Eleven/EtherTen, etc).

First, we’ll use the I/O as outputs. There are three port registers that we can alter to set the status of the digital and analogue I/O pins. A port register can be thought of  as a special byte variable that we can change which is read by the microcontroller, therefore controlling the state of various I/O ports. We have three port registers to work with:

• D – for digital pins seven to zero (bank D)
• B – for digital pins thirteen to eight (bank B)
• C – for analogue pins five to zero (bank … C!)

Register C can control analogue pins seven to zero if using an Arduino with the TQFP style of ATmega328, such as the Nano or Freetronics EtherTen). For example:

It is very simple to do so. In void setup(), we use

where y is the register type (B/C/D) and xxxxxxxx are eight bits that determine if a pin is to be an input or output. Use 0 for input, and 1 for output. The LSB (least-significant bit [the one on the right!]) is the lowest pin number for that register. Next, to control a bank of pins, use

where y is the register type (B/C/D) and xxxxxxxx are eight status bits – 1 for HIGH, 0 for LOW. This is demonstrated in the following example:

It sets digital pins 7~0 to output in void setup(). Then it alternates turning on and off alternating halves of digital pins 0~7. At the start I mentioned that using port manipulation was a lot faster than using regular Arduino I/O functions. How fast? To test the speed of port manipulation vs. using digitalWrite(), we will use the following circuit:

… and analyse the output at digital pins zero and seven using a digital storage oscilloscope. Our first test sketch turns on and off digital pins 0~7 without any delay between PORTD commands – in other words, as fast as possible. The sketch:

In the image below, digital zero is channel one, and digital seven is channel three:

Wow – check the frequency measurements – 1.1432 MHz! Interesting to note the longer duration of time when the pins are low vs. high.

[Update] Well it turns out that the extra time in LOW includes the time for the Arduino to go back to the top of void loop(). This can be demonstrated in the following sketch. We turn the pins on and off five times instead of once:

And the results from the MSO. You can see the duty cycle is much closer to 50% until the end of the sketch, at which point around 660 nanoseconds is the time used between the end of the last LOW period and the start of the next HIGH:

Next we do it the normal way, using this sketch:

And the results:

That was a lot slower – we’re down to 14.085 kHz, with a much neater square-wave output. Could some CPU time be saved by not using the for loop? We tested once more with the following sketch:

and the results:

A small speed boost, the frequency has increased to 14.983 kHz. Hopefully you can now understand the benefits of using port manipulation. However there are a few things to take note of:

• You can’t control digital pins 0 and 1 (in bank D) and use the serial monitor/port. For example if you set pin zero to output, it can’t receive data!
• Always document your sketch – take pity on others who may need to review it later on and become puzzled about wchich bits are controlling or reading what!
Now to waste some electron flows by blinking LEDs. Using the circuit described earlier, the following sketch will create various effects for someone’s enjoyment:

And here it is in real life:

Now to use the I/O pins as inputs. Again, it is very simple to do so. In void setup(), we use

where y is the register type (B/C/D) and xxxxxxxx are eight bits that determine if a pin is to be an input or output. Use 0 for input. The LSB (least-significant bit [the one on the right!]) is the lowest pin number for that register. Next, to read the status of the pins we simply read the byte:

where y is the register type (B/C/D). So if you were using port B as inputs, and digital pins 8~10 were high, and 11~13 were low, PINB would be equal to B00000111. Really, that’s it!

Now for another demonstration using both inputs and outputs. We will use a push-wheel switch from Chapter 40 on our inputs (digital pins 8~11), and a seven segment LED display for output (on digtal pins 7~0 – segments dp then a~f). The following sketch reads the input from the switch, which returns 0~9 in binary-coded decimal. This value is then used in the function void disp() to retrieve the matching byte from the array “segments”, which contains the appropriate outputs to drive the seven segment LED display unit. Here is the sketch:

And the ubiquitous demonstration video:

By now I hope you have an understanding of using port manipulation for your benefit. With a little effort your sketches can be more efficient in terms of speed and memory space, and also allow nifty simultaneous reading of input pins.

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.

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.

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.

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

Use numeric keypads with Arduino in chapter forty-two 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.

This is part one of two chapters that will examine another useful form of input – the numeric keypad; and some applications that hopefully may be of use.  Here is the example we will be working with:

It seems quite similar to the keypad from a 1980s-era Dick Smith Electronics cordless phone. Turning the keypad over we find seven pins:

Personally I like this type of connection, as it makes prototyping very easy using a breadboard – you just push it in. Looking at the back the pins are numbered seven to one (left to right). My example was from Futurlec of all places. You can also find types that have solder pads. At this point you need to download the data sheet.pdf, as it shows the pinouts for the rows and columns. At first glance trying to establish a way of reading the keypad with the Arduino does seem troublesome – however the basic process is to ‘scan’ each row and then test if a button has been pressed.

If your keypad has more than seven pins or contacts – and the data sheet was not supplied, you will need to manually determine which contacts are for the rows and columns. This can be done using the continuity function of a multimeter (the buzzer). Start by placing one probe on pin 1, the other probe on pin 2, and press the keys one by one. Make a note of when a button completes the circuit, then move onto the next pin. Soon you will know which is which. For example, on the example keypad pins 1 and 5 are for button “1”, 2 and 5 for “4”, etc…

In the interest of keeping things simple and relatively painless we will use the numeric keypad Arduino library. Download the library from here, copy the “Keypad” folder into your ../arduino-002x/libraries folder, then restart the Arduino IDE.

Now for our first example. From a hardware perspective you will need

• An Arduino Uno or 100% compatible board
• An LCD of some sort. We will be using an I2C-interface model. If you are unsure about LCD usage, please see this tutorial
• If you don’t have an LCD – that’s ok. After installing the keypad library, select File>Examples>Keypad>Examples>HelloKeypad in the IDE.
Connect the keypad to the Arduino in the following manner:
• Keypad row 1 to Arduino digital 5
• Keypad row 2 to Arduino digital 4
• Keypad row 3 to Arduino digital 3
• Keypad row 4 to Arduino digital 2
• Keypad column 1 to Arduino digital 8
• Keypad column 2 to Arduino digital 7
• Keypad column 3 to Arduino digital 6
Now for the sketch:

For the non-believers, here it is in action:

As you can see the library really does all the work for us. In the section below the comment “keypad type definition” we have defined how many rows and columns make up the keypad. Furthermore which digital pins connect to the keypad’s row and column pins. If you have a different keypad such as a 16-button version these will need to be modified. Furthermore you can also map out what the buttons will represent in the array “keys”. Then all of these variables are passed to the library in the function Keypad keypad = Keypad() etc.

Reading the buttons pressed is accomplished in void loop()… it reads the keypad by placing the current value into the char variable “key”. The if… statement tests if a button has been pressed. You can reproduce this loop within your own sketch to read values and then move forward to other functions. Let’s do that now in our next example.

Using our existing example hardware we can turn something on or off by using the keypad – replicating what can be found in some alarm systems and so on. Our goal with this example is simple – the systems waits for a PIN to be entered. If the PIN is correct, do something. If the PIN is incorrect, do something else. What the actions are can be up to you, but for the example we will turn on or off a digital output. This example is to give you a concept and framework to build you own ideas with.

The hardware is the same as the previous example but without the LCD. Instead, we have a 560 ohm resistor followed by an LED to GND from digital pin ten. Now for the sketch:

And the ubiquitous demonstration video:

This sketch is somewhat more complex. It starts with the usual keypad setting up and so on. We have two arrays, attempt and PIN. PIN holds the number which will successfully activate the switch, and attempt is used to store the key presses entered by the user. Users must press ‘*’ then the PIN then ‘#’ to activate the switch.

The comparison to check for accuracy is in the function checkPIN(). It compares the contents of PIN against attempt. If they match, the function correctPIN() is called. If the entered PIN is incorrect, the function incorrectPIN() is called. We also call the function incorrectPIN() in void setup to keep things locked down in case of a power failure or a system reset.

You can now see that such a complex device can be harnessed very easily, and could have a variety of uses. In part two, we will look at the 16-digit

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.

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.

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 04/12/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 forum – dedicated to the projects and related items on this website.

Posted in arduino, education, I2C, lesson, MCP23017, microcontrollers, tutorial

Review: Gravitech 7-Segment Arduino Shield

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.

High resolution photos are available on flickr.

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:

The function readSwitch()  is the key. It calculates the value of the switch by adding the numerical representation of each switch output and returns the total as its result. For this example we used a numerical display shield that is controlled by the NXP SAA1064. If you don’t have one, that’s ok – the results are also sent to the serial monitor. Now, let’s see it in action:

Ok it doesn’t look like much, but if you need numerical entry it saves a lot of physical space and offers a precise method of entry.

So there you have it. Would you actually use these in a project? For one digit – yes. For four? Probably not – perhaps it would be easier to use a 12-digit keypad. There’s an idea…  But for now I hope you enjoyed reading this as much as I did writing it for you.

Update! See the addendum for using four switches at once to read four-digit numbers here

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.

Tutorial: Gravitech Arduino Nano MP3 Player

[Update: 21/05/2013. Tutorial now out of date, and I don’t have a Nano to test it with the new code. Try this instead. If you have hardware questions or enquiries relating to the Arduino Nano or MP3 board, please direct them to Gravitech via their contact page.

tronixstuff.com Visitor feedback/survey competition

Competition over. Any feedback to john at tronixstuff dot com.

Posted in competition

Kit Review – Snootlab Rotoshield

[Update: 11/12/11 – Added example code and video]

In this article we will examine yet another product from a bundle sent for review by Snootlab, a Toulouse, France-based company that in their own words:

… designs and develops electronic products with an Open Hardware and Open Source approach. We are particularly specialized in the design of new shields for Arduino. The products we create are licensed under CC BY-SA v3.0 (as shown in documents associated with each of our creations). In accordance with the principles of the definition of Open Source Hardware (OSHW), we have signed it the 10th February 2011. We wish to contribute to the development of the ecosystem of “do it yourself” through original designs of products, uses and events.

Furthermore, all of their products are RoHS compliant and as part of the Open Hardware commitment, all the design files are available from the Snootlab website.

The subject of the review is the Snootlab Rotoshield – a motor-driver shield for our Arduino systems. Using a pair of L293 half-bridge motor driver ICs, you can control four DC motors with 256 levels of speed, or two stepper motors. However this is more than just a simple motor-driver shield… The PCB has four bi-colour LEDs, used to indicate the direction of each DC motor; there is a MAX7313 IC which offers another eight PWM output lines; and the board can accept external power up to 18V, or (like other Snootlab shields) draw power from a PC ATX power supply line.

However as this is a kit, let’s follow construction, then explore how the Rotoshield could possibly be used. [You can also purchase the shield fully assembled – but what fun would that be?] Assembly was relatively easy, and you can download instructions and the schematic files in English. As always, the kit arrives in a reusable ESD bag:

There are some SMD components, and thankfully they are pre-soldered to the board. These include the SMD LEDs, some random passives and the MAX7313:

Thankfully the silk-screen is well noted with component numbers and so on:

All the required parts are included, including stackable headers and IC sockets:

It is nice to not see any of the old-style ceramic capacitors. The people at Snootlab share my enthusiasm for quality components. The assembly process is pretty simple, just start with the smaller parts such as capacitors:

… then work outwards with the sockets and terminals:

… then continue on with the larger, bulkier components. My favourite flexible hand was used to hold the electrolytics in place:

… followed with the rest, leaving us with one Rotoshield:

If you want to use the 12V power line from the ATX socket, don’t forget to bridge the PCB pads between R7 and the AREF pin. The next thing to do is download and install the snooter library to allow control of the Rotoshield in your sketches. There are many examples included with the library that you can examine, just select File > Examples > snootor in the Arduino IDE to select an example. Function definitions are available in the readme.txt file included in the library download.

[Update]

After acquiring a tank chassis with two DC motors, it was time to fire up the Rotoshield and get it to work. From a hardware perspective is was quite simple – the two motors were connected to the M1 and M2 terminal blocks, and a 6V battery pack to the external power terminal block on the shield. The Arduino underneath is powered by a separate PP3 9V battery.

In the following sketch I have created four functions – goForward(), goBackward(), rotateLeft() and rotateRight(). The parameter is the amount of time in milliseconds to operate for. The speed of the motore is set using the Mx.setSpeed() function in void Setup(). Although the speed range is from zero to 255, this is PWM so the motors don’t respond that well until around 128. So have just set them to full speed. Here is the demonstration sketch:

… and the resulting video:

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 Rotoshield are available directly from their website. High-resolution images available on flickr.

July 2011 Competition

Competition over!

Tutorial: Arduino and the NXP SAA1064 4-digit LED display driver

Learn how to use the NXP SAA1064 LED display driver IC in chapter thirty-nine of a series originally titled “Getting Started/Moving Forward with Arduino!” by John Boxall – a series of articles on the Arduino universe.

Updated 19/01/2013

In this article we investigate controlling the NXP (formerly Philips) SAA1064 4-digit LED display driver IC with Arduino and the I2C bus interface. If you are not familiar with using the I2C bus, please read my tutorials (parts one and two) before moving on. Although the SAA1064 is not the newest on the market, it is still popular, quite inexpensive and easy to source. Furthermore as it is controlled over the I2C bus – you don’t waste any digital I/O pins on your Arduino, and you can also operate up to four SAA1064s at once (allowing 16 digits!). Finally, it has a constant-current output – keeping all the segments of your LED display at a constant brightness (which is also adjustable).  So let’s get started…

Here is an example of the SAA1064 in SOIC surface mount packaging:

It measures around 15mm in length. For use in a solderless breadboard, I have soldered the IC onto a through-hole adaptor:

The SAA1064 is also available in a regular through-hole DIP package. At this point, please download the data sheet (.pdf) as you will need to refer to it during the article. Next, our LED display examples. We need common-anode displays, and for this article we use two Agilent HDSP521G two-digit modules (data sheet [.pdf]) as shown below:

For the uninitiated – a common anode display has all the segments’ anodes connected together, with the cathodes terminated separately. For example, our LED displays are wired as such:

Notice the anodes for the left digit are pin 14, and the right digit pin 13. A device that is connected to all the cathodes (e.g. our SAA1064) will control the current flow through each element – thereby turning each segment on (and controlling the brightness) or off. Our SAA1064 is known as a current-sink as the current flows through the LED, and then sinks into the IC.

Now, let’s get it connected. There is an excellent demonstration circuit on page twelve of the data sheet that we will follow for our demonstrations:

It looks pretty straight-forward, and it is. The two transistors are standard NPN-type, such as PN2222. The two transistors are used to each turn on or off a pair of digits – as the IC can only drive digits 1+3 or 2+4 together. (When presented in real life the digits are numbered 4-3-2-1). So the pairs are alternatively turned on and off at a rapid rate, which is controlled by the capacitor between pin 2 and GND. The recommended value is 2.7 nF. At the time of writing, I didn’t have that value in stock, so chose a 3.3 nF instead. However due to the tolerance of the ceramic capacitor it was actually measured to be 2.93 nF:

So close enough to 2.7 nF will be OK. The other capacitor shown between pins 12 and 13 is a standard 0.1 uF smoothing capacitor. Pin 1 on the SAA1064 is used to determine the I2C bus address – for our example we have connected it straight to GND (no resistors at all) resulting in an address of 0x70. See the bottom page five of the data sheet for other address options. Power for the circuit can be taken from your Arduino’s 5V pin – and don’t forget to connect the circuit GND to Arduino GND. You will also use 4.7k ohm pull-up resistors on the SDA and SCL lines of the I2C bus.

The last piece of the schematic puzzle is how to connect the cathodes of the LED displays to the SAA1064. Display pins 14 and 13 are the common anodes of the digits.

The cathodes for the left-hand display module:

• LED display pins 4, 16, 15, 3, 2, 1, 18 and 17 connect to SAA1064 pins 22, 21, 20, 19, 18, 17, 16 and 15 respectively (that is, LED pin 4 to IC pin 22, etc.);
• LED display pins 9, 11, 10, 8, 6, 5, 12 and 7 also connect to SAA1064 pins 22, 21, 20, 19, 18, 17, 16 and 15 respectively.
The cathodes for the right-hand display module:
• LED display pins 4, 16, 15, 3, 2, 1, 18 and 17 connect to SAA1064 pins 3, 4, 5, 6, 7, 8, 9 and 10 respectively;
• LED display pins  9, 11, 10, 8, 6, 5, 12 and 7 also connect to SAA1064 pins 3, 4, 5, 6, 7, 8, 9 and 10 respectively.
Once your connections have been made, you could end up with spaghetti junction like this…
Now it is time to consider the Arduino sketch to control out SAA1064. Each write request to the SAA1064 requires several bytes. We either send a control command (to alter some of the SAA1064 parameters such as display brightness) or a display command (actually display numbers). For our example sketches the I2C bus address “0x70 >> 1” is stored in the byte variable saa1064. First of all, let’s look at sending commands, as this is always done first in a sketch to initiate the SAA1064 before sending it data.
As always, we send the address down the I2C bus to awaken the SAA1064 using

Then the next byte is the instruction byte. If we send zero:

… the IC expects the next byte down the bus to be the command byte. And finally our command byte:

The control bits are described on page six of the data sheet. However – for four-digit operation bits 0, 1 and 2 should be 1; bit 3 should be 0; and bits 4~6 determine the amount of current allowed to flow through the LED segments. Note that they are cumulative, so if you set bits 5 and 6 to 1 – 18 mA of current will flow. We will demonstrate this in detail later on.

Next, to send actual numbers to be displayed is slightly different. Note that the digits are numbered (from left to right) 4 3 2 1. Again, we first send the address down the I2C bus to awaken the SAA1064 using

Then the next byte is the instruction byte. If we send 1, the next byte of data will represent digit 1. If that follows with another byte, it will represent digit 2. And so on. So to send data to digit 1, send

Although sending binary helps with the explanation, you can send decimal equivalents. Next, we send a byte for each digit (from right to left). Each bit in the byte represents a single LED element of the digit as well as the decimal point. Note how the elements are labelled (using A~G and DP) in the following image:

The digit bytes describe which digit elements to turn on or off. The bytes are described as such: Bpgfedcba. (p is the decimal point). So if you wanted to display the number 7, you would send B00000111 – as this would turn on elements a, b and c. To add the decimal point with 7 you would send B10000111. You can also send the byte as a decimal number. So to send the digit 7 as a decimal, you would send 7 – as 00000111 in base-10 is 7. To include the decimal point, send 135 – as 100000111 in base-10 is 135. Easy! You can also create other characters such as A~F for hexadecimal. In fact let’s do that now in the following example sketch:

In the function initDisplay() you can see an example of using the instruction then the control byte. In the function clearDisplay() you can see the simplest form of sending digits to the display – we send 0 for each digit to turn off all elements in each digit. The bytes that define the digits 0~9 and A~F are stored in the array digits[]. For example, the digit zero is 63 in decimal, which is B00111111 in binary – which turns on elements a,b,c,d,e and f. Finally, notice the second loop in displayDigits() – 128 is added to each digit value to turn on the decimal point. Before moving on, let’s see it in action:

Our next example revisits the instruction and control byte – we change the brightness of the digits by setting bits 4~6 in the control byte. Each level of brightness is separated into a separate function, and should be self-explanatory. Here is the sketch:

And again, see it in action:

For our final example, there is a function displayInteger(a,b) which can be used to easily display numbers from 0~9999 on the 4-digit display. The parameter a is the number to display, and b is the leading-zero control – zero – off, one – on. The function does some maths on the integet to display and separates the digits for each column, then sends them to the SAA1064 in reverse order. By now you should be able to understand the following sketch:

And the final example in action:

So there you have it – another useful IC that can be used in conjunction with our Arduino systems to make life easier and reduce the required digital output pins.

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.

Kit Review – Snootlab Mémoire SD card/RTC/prototyping shield

In this article we will examine another product from a bundle sent for review by Snootlab, a Toulouse, France-based company that in their own words:

… designs and develops electronic products with an Open Hardware and Open Source approach. We are particularly specialized in the design of new shields for Arduino. The products we create are licensed under CC BY-SA v3.0 (as shown in documents associated with each of our creations). In accordance with the principles of the definition of Open Source Hardware (OSHW), we have signed it the 10th February 2011. We wish to contribute to the development of the ecosystem of “do it yourself” through original designs of products, uses and events.

Furthermore, all of their products are RoHS compliant and as part of the Open Hardware commitment, all the design files are available from the Snootlab website.

The subject of the review is the Snootlab Mémoire – an SD card data logging shield with on-board DS1307 real time clock [and matching backup battery] and prototyping area. It uses the standard SdFat library to write to normal SD memory cards formatted in FAT16 or FAT32. You can download the library from here. The real time clock IC is an easy to use I2C-interface model, and I have documented its use in great detail in this tutorial.

Once again, shield assembly is simple and quite straightforward. You can download an illustrated assembly guide from here, however it is in French. But everything you need to know is laid out on the PCB silk-screen, or the last page of the instructions. The it arrives in a reusable ESD bag:

… and all the required parts are included – including an IC socket and the RTC backup battery:

… the PCB is thick, with a very detailed silk-screen. Furthermore, it arrives with the SD card and 3.3V LDO (underneath) already pre-soldered – a nice touch:

The order of soldering the components is generally a subjective decision, and in this case I started with the resistors:

… and then worked my way out, but not fitting the battery nor IC until last. Intrestingly, the instructions require the crystal to be tacked down with some solder onto the PCB. Frankly I didn’t think it would withstand the temperature, however it did and all is well:

Which leaves us with a fully-assembled Mémoire shield ready for action:

Please note that a memory card is not included with the kit. If you are following along with your own Mémoire, the first thing to do after inserting the battery, IC and shield into your Arduino board and run some tests to ensure all is well. First thing is to test the DS1307 real-time clock IC. You can use the following sketch from chapter seven of my Arduino tutorial series:

If you are unsure about using I2C, please review my tutorial which can be found here. Don’t forget to update the time and date data in void setup(), and also comment out the setDateDS1307() function and upload the sketch a second time. The sketch output will be found on the serial monitor box – such as:

Those of you familiar with the DS1307 RTC IC know that it can generate a nice 1 Hz pulse. To take advantage of this the SQW pin has an access hole on the PCB, beetween R10 and pin 8 of the IC:

For instruction on how to activate the SQW output, please visit the last section of this tutorial.

The next test is the SD card section of the shield. If you have not already done so, download and install the SdFat libary. Then, in the Arduino IDE, select File > Examples > SdFat > SdFatInfo. Insert the formatted (FAT16/32) SD card into the shield, upload the sketch, then open the serial monitor. You should be presented with something like this:

As you can see the sketch has returned various data about the SD card. Finally, let’s log some data. You can deconstruct the excellent example that comes with the SdFat library titled SdFatAnalogLogger (select File > Examples > SdFat > SdFatAnalogLogger). Using the functions:

you can “write” to the SD card in the same way as you would the serial output (that is, the serial monitor).

If you have reached this far without any errors – Congratulations! You’re ready to log. If not, remove the battery, SD card and IC from your shield (you used the IC socket, didn’t you?). Check the polarised components are in correctly, double-check your soldering and then reinsert the IC, shield and battery and try again. If that fails, support is available on the Snootlab website, and there is also a 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. Stay tuned for the final Snootlab product review.

Snootlab products including the Snootlab Mémoire are available directly from their website. High-resolution images available on flickr.

Posted in arduino, ds1307, education, kit review, snootlabComments (0)

Learn to solder with eevblog’s David L. Jones!

How is your soldering? Have you always wanted to improve your soldering skills, or never heated an iron in your life and didn’t know where to start? No matter your level of skill you could do a lot worse than review the following video blogs in this article by David L. Jones.

Who?

[David] shares some of his 20 years experience in the electronics design industry in his unique non-scripted naturally overly enthusiastic and passionate style.
Bullsh!t and political correctness don’t get a look-in.

Dave started out in hobby electronics over 30 years ago and since then has worked in such diverse areas as design engineering, production engineering, test engineering, electro-mechanical engineering, that wacky ISO quality stuff, field service, concept design, underwater acoustics, ceramic sensors, military sonar systems, red tape, endless paperwork trails, environmental testing, embedded firmware and software application design, PCB design (he’s CID certified), power distribution systems, ultra low noise and low power design, high speed digital design, telemetry systems, and too much other stuff he usually doesn’t talk about.

He has been published in various magazines including: Electronic Today International, Electronics Australia, Silicon Chip, Elektor, Everyday Practical Electronics (EPE), Make, and ReNew.

Few people know Dave is also a world renowned expert and author on Internet Dating, a qualified fitness instructor, geocacher, canyoner, and environmentalist.

Regular readers of this website would know that I rarely publish outside material – however the depth and quality of the tutorials make them a must-see for beginners and experienced people alike. Furthermore, if you have the bandwidth they can be viewed in 1080p. And as a fellow Australian I’m proud to support Dave and his efforts. So I hope you can view, enjoy and possibly learn from the following videos:

The first covers the variety of tools you would use:

And the second covers through-hole PCB soldering:

The third covers surface-mount soldering:

Finally, watch the procedure for soldering a tiny SMD IC using the ‘dead bug’ method:

And for something completely different:

If you enjoyed those videos then don’t forget to check out what’s new on Dave’s eevblog website and forum. Videos shown are (C) David L. Jones 2011 and embedded with permission.

Review: The Gravitech Arduino Nano family

In this article we will examine a variety of products received for review from Gravitech in the United States – the company that designed and build the Arduino Nano. We have a Nano and some very interesting additional modules to have a look at.

So let’s start out review with the Arduino Nano. What is a Nano? A very, very small version of our Arduino Duemilanove boards. It contains the same microcontroller (ATmega328) but in SMD form; has all the I/O pins (plus two extra analogue inputs); and still has a USB interface via the FT232 chip. But more on that later. Nanos arrive in reusable ESD packaging which is useful for storage when not in use:

Patriotic Americans should note that the Nano line is made in the USA. Furthermore, here is a video clip of Nanos being made:

For those who were unsure about the size of the Nano, consider the following images:

You can easily see all the pin labels and compare them to your Duemilanove or Uno board. There is also a tiny reset button, the usual LEDs, and the in circuit software programmer pins. So you don’t miss out on anything by going to a Nano. When you flip the board over, the rest of the circuitry is revealed, including the FTDI USB>serial converter IC:

Those of you familiar with Arduino systems should immediately recognise the benefit of the Nano – especially for short-run prototype production. The reduction in size really is quite large. In the following image, I have traced the outline of an Arduino Uno and placed the Nano inside for comparison:

So tiny… the board measures 43.1mm (1.7″) by 17.8mm (0.7″). The pins on this example were pre-soldered – and are spaced at standard 2.54mm (0.1″) intervals – perfect for breadboarding or designing into your own PCB –  however you can purchase a Nano without the pins to suit your own mounting purposes. The Nano meets all the specifications of the standard Arduino Duemilanove-style boards, except naturally the physical dimensions.

Power can be supplied to the Nano via the USB cable; feeding 5V directly into the 5V pin, or 7~12 (20 max, not recommended) into the Vin pin. You can only draw 3.3V at up to 50 mA when the Nano is running on USB power, as the 3.3V is sourced from the FTDI USB>serial IC. And the digital I/O pins still allow a current draw up to 40 mA each. From a software perspective you will not have any problems, as the Nano falls under the same board classification as the (for example) Arduino Duemilanove:

Therefore one could take advantage of all the Arduino fun and games – except for the full-size shields. But as you will read soon, Gravitech have got us covered on that front. If the Arduino system is new to you, why not consider following my series of tutorials? They can be found here. In the meanwhile, to put the size into perspective – here is a short video of a Nano blinking some LEDs!

Now back to business. As the Nano does not use standard Arduino shields, the team at Gravitech have got us covered with a range of equivalent shields to enable all sorts of activities. The first of this is their Ethernet and microSD card add-on module:

and the underside:

Again this is designed for breadboarding, or you could most likely remove the pins if necessary. The microSD socket is connected as expected via the SPI bus, and is fully compatible with the default Arduino SD library. As shown in the following image the Nano can slot directly into the ethernet add-in module:

The Ethernet board requires an external power supply, from 7 to 12 volts DC. The controller chip is the usual Wiznet 5100 model, and therefore the Ethernet board is fully compatible with the default Ethernet Arduino library. We tested it with the example web server sketch provided with the Arduino IDE and it all just worked.

The next add-on module to examine is the 2MOTOR board:

… and the bottom:

Using this module allows control of two DC motors with up to two amps of current each via pulse-width modulation. Furthermore, there is a current feedback circuit for each motor so you measure the motor load and adjust power output – interesting. So a motorised device could sense when it was working too hard and ease back a little (like me on a Saturday). All this is made possible by the use of the common L298 dual full-bridge motor driver IC. This is quite a common motor driver IC and is easy to implement in your sketches. The use of this module and the Nano will help reduce the size of any robotics or motorised project. Stay tuned for use of this board in future articles.

Next in this veritable cornucopia of  add-on modules is the USBHOST board:

turning it over …

Using the Maxim MAX3421E host controller IC you can interface with all sorts of devices via USB, as well as work with the new Android ADK. The module will require an external power supply of between 7 and 12 volts DC, with enough current to deal with the board, a Nano and the USB device under control – one amp should be more than sufficient. I will be honest and note that USB and Arduino is completely new to me, however it is somewhat fascinating and I intend to write more about using this module in the near future. In the meanwhile, many examples can be found here.

For a change of scene there is also a group of Xbee wireless communication modules, starting with the Xbee add-on module:

The Xbee itself is not included, only shown for a size comparison. Turning the module over:

It is nice to see a clearly-labelled silk screen on the PCB. If you are unfamiliar with using the Xbee wireless modules for data communication, you may find my introductory tutorial of interest. Furthermore, all of the Gravitech Nano modules are fully software compatible with my tutorial examples, so getting started will be a breeze. Naturally Gravitech also produce an Xbee USB interface board, to enable PC communication over your wireless modules:

Again, note that the Xbee itself is not included, however they can be supplied by Gravitech. Turning the board over reveals another highly-detailed silk screen:

All of the Gravitech Xbee modules support both series 1.0 and 2.5 Xbees, in both standard and professional variants. The USB module also supports the X-CTU configuration software from Digi.

Finally – leaving possibly the most interesting part until last, we have the MP3 Player add-on board:

and on the B-side:

The MP3 board is designed around the VS1053B MP3 decoder IC. It can also decode Ogg Vorbis, AAC, WMA and MID files. There is a 3.5mm stereo output socket to connect headphones and so on. As expected, the microSD card runs from the SPI pins, however SS is pin 4. Although it may be tempting to use this to make a home-brew MP3 player, other uses could include: recorded voice messages for PA systems such as fire alarm notices, adding sound effects to various projects or amusement machines, or whatever else you can come up with.

Update – We have examined the MP3 board in more detail with a beginner’s tutorial.

The Arduino Nano and related boards really are tiny, fully compatible with their larger brethren, and will prove very useful. Although this article was an introductory review, stay tuned for further projects and articles that will make use of the Nano and other boards. If you have any questions or enquiries please direct them to Gravitech via their contact page. Gravitech products including the Arduino Nano family are available directly from their website or these distributors.

High resolution photos are available on flickr.

Otherwise, have fun, be good to each other – and make something!

Tutorial: Arduino and a Thermal Printer

Use inexpensive thermal printers with Arduino in chapter thirty-eight 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 05/02/2013

In this article we introduce the inexpensive thermal printer that has recently become widely available from Sparkfun and their resellers. The goal of the article is to be as simple as possible so you can get started without any problems or confusion. In the past getting data from our Arduino to a paper form would either have meant logging it to an SD card then using a PC to finish the job, or perhaps viewing said data on an LCD then writing it down. Not any more – with the use of this cheap and simple serial printer. Before we get started, here is a short demonstration video of it in action:

Not bad at all considering the price. Let’s have a look in more detail. Here is the printer and two matching rolls of thermal paper:

… and the inside of the unit:

Loading paper is quite simple, just drop the roll in with the end of the paper facing away from you, pull it out further than the top of the front lip, then close the lid. The paper rolls required need to be 57mm wide and have a diameter of no more than 39mm. For example. There is a piece of white cardboard stuck to the front – this is an economical cover that hides some of the internals. Nothing of interest for us in there. The button next to the LED on the left is for paper advance, and the LED can blink out the printer status.

From a hardware perspective wiring is also very simple. Looking at the base of the printer:

… there are two connections. On the left is DC power, and data on the right. Thankfully the leads are included with the printer and have the plugs already fitted – a great time saver. You may also want to fit your own rubber feet to stop the printer rocking about.

Please note – you need an external power supply with a voltage of between 5 and 9 volts DC that can deliver up to 1.5 amps of current. When idling the printer draws less than 10 milliamps, but when printing it peaks at around 1.47 A. So don’t try and run it from your Arduino board. However the data lines are easy, as the printer has a serial interface we only need to connect printer RX to Arduino digital 3, and printer TX to Arduino digital 2, and GND to … GND! We will use a virtual serial port on pins 2 and 3 as 0 and 1 will be taken for use with the serial monitor window for debugging and possible control purposes.

If you want to quickly test your printer – connect it to the power, drop in some paper, hold down the feed button and turn on the power. It will quickly produce a test print.

Next we need to understand how to control the printer in our sketches. Consider this very simple sketch: