Tag Archive | "sparkfun"

Tutorial – Arduino and Color LCD

Learn how to use an inexpensive colour LCD shield with your Arduino. This is chapter twenty-eight of our huge Arduino tutorial series.

Updated 03/02/2014

There are many colour LCDs on the market that can be used with an Arduino, and for this tutorial we’re using a relatively simple model available that is available from suppliers such as Linksprite (and previously Sparkfun), based on a small LCD originally used in Nokia 6100 mobile phones:

Arduino Color LCD shield

These are a convenient and inexpensive way of displaying data, or for monitoring variables when debugging a sketch. Before getting started, a small amount of work is required.

From the two examples we have seen, neither of them arrive fitted with stacking headers (or in Sparkfun’s case – not included) or pins, so before doing anything you’ll need to fit your choice of connector. Although the Linksprite shield arrived with stacking headers, we used in-line pins as another shield would never be placed on top:

Arduino Color LCD shield fit headers

Which can easily be soldered to the shield in a few minutes:

Arduino Color LCD shield fitted

 While we’re on the subject of pins - this shield uses D3~D5 for the three buttons, and D8, 9, 11 and 13 for the LCD interface. The shield takes 5V and doesn’t require any external power for the backlight. The LCD module has a resolution of 128 x 128 pixels, with nine defined colours (red, green, blue, cyan, magenta, yellow, brown, orange, pink) as well as black and white.

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

At this point let’s check the shield is working before moving forward. Once fitted to your Arduino, upload the ChronoLCD_Color sketch that’s included with the library, from the IDE Examples menu:

Arduino Color LCD shield example sketch

This will result with a neat analogue clock you can adjust with the buttons on the shield, as shown in this video.

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

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

as well as the following in void setup():

With regards to lcd.init(), try it first without a parameter. If the screen doesn’t work, try EPSON instead. There are two versions of the LCD shield floating about each with a different controller chip. The contrast parameter is subjective, however 63 looks good – but test for yourself.

Now let’s move on to examine each function with a small example, then use the LCD shield in more complex applications.

The LCD can display 8 rows of 16 characters of text. The function to display text is:

where x and y are the coordinates of the top left pixel of the first character in the string. Another necessary function is:

Which clears the screen and sets the background colour to the parameter colour.  Please note – when referring to the X- and Y-axis in this article, they are relative to the LCD in the position shown below. Now for an example – to recreate the following display:

Arduino Color LCD shield text demonstration

… use the following sketch:

In example 28.1 we used the function lcd.clear(), which unsurprisingly cleared the screen and set the background a certain colour.

Let’s have a look at the various background colours in the following example. The lcd.clear()  function is helpful as it can set the entire screen area to a particular colour. As mentioned earlier, there are the predefined colours red, green, blue, cyan, magenta, yellow, brown, orange, pink, as well as black and white. Here they are in the following example:

And now to see it in action. In this demonstration video the colours are more livid in real life, unfortunately the camera does not capture them so well.

 

Now that we have had some experience with the LCD library’s functions, we can move on to drawing some graphical objects. Recall that the screen has a resolution of 128 by 128 pixels. We have four functions to make use of this LCD real estate, so let’s see how they work. The first is:

This function places a pixel (one LCD dot) at location x, y with the colour of colour.

Note – in this (and all the functions that have a colour parameter) you can substitute the colour (e.g. BLACK) for a 12-bit RGB value representing the colour required. Next is:

Which draws a line of colour COLOUR, from position x0, y0 to x1, y1. Our next function is:

This function draws an oblong or square of colour COLOUR with the top-left point at x0, y0 and the bottom right at x1, y1. Fill is set to 0 for an outline, and 1 for a filled oblong. It would be convenient for drawing bar graphs for data representation. And finally, we can also create circles, using:


X and Y is the location for the centre of the circle, radius and COLOUR are self-explanatory. We will now use these graphical functions in the following demonstration sketch:

The results of this sketch are shown in this video. For photographic reasons, I will stick with white on black for the colours.

So now you have an explanation of the functions to drive the screen – and only your imagination is holding you back.

Conclusion

Hopefully this tutorial is of use to you. and you’re no longer wondering “how to use a color LCD with Arduino”. We also have another tutorial using larged ILI9325 modules, which are larged and have a clearer display (they’re TFT LCDs) but can be a little trickier.

And if you enjoyed the tutorial, or want to introduce someone else to the interesting world of Arduino – check out my book “Arduino Workshop” from No Starch Press.

 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, LCD, LCD-09363, Linksprite, SHD_LCD_NOKIA, sparkfun, tronixstuff, tutorialComments (0)

Tutorial: Arduino and the MSGEQ7 Spectrum Analyzer

This is a tutorial on using the MSGEQ7 Spectrum Analyser with Arduino, and chapter forty-eight of a series originally titled “Getting Started/Moving Forward with Arduino!” by John Boxall – A tutorial on the Arduino universe. The first chapter is here, the complete series is detailed here.

Updated 30/01/2013

In this article we’re going to explain how to make simple spectrum analysers with an Arduino-style board. (Analyser? Analyzer? Take your pick).

First of all, what is a spectrum analyser? Good question. Do you remember what  this is?

It’s a mixed graphic equaliser/spectrum analyser deck for a hi-fi system. The display in the middle is the spectrum analyser, and roughly-speaking it shows the strength of  different frequencies in the music being listened to – and looked pretty awesome doing it. We can recreate displays similar to this for entertainment and also as a base for creative lighting effects. By working through this tutorial you’ll have the base knowledge to recreate these yourself.

We’ll be using the MSGEQ7 “seven band graphic equaliser IC” from Mixed Signal Integration. Here’s the MSGEQ7 data sheet (.pdf).  This little IC can accept a single audio source, analyse seven frequency bands of the audio, and output a DC representation of each frequency band. This isn’t super-accurate or calibrated in any way, but it works. You can get the IC separately, for example:


and then build your own circuit around it… or like most things in the Arduino world – get a shield. In this case, a derivative of the original Bliptronics shield by Sparkfun. It’s designed to pass through stereo audio via 3.5mm audio sockets and contains two MSGEQ7s, so we can do a stereo analyser:

As usual Sparkfun have saved a few cents by not including the stackable header sockets, so you’ll need to buy and solder those in yourself. There is also space for three header pins for direct audio input (left, right and common), which are useful – so if you can add those as well.

So now you have a shield that’s ready for use. Before moving forward let’s examine how the MSGEQ7 works for us. As mentioned earlier, it analyses seven frequency bands. These are illustrated in the following graph from the data sheet:

freqresponse

It will return the strengths of the audio at seven points – 63 Hz, 160 Hz, 400 Hz, 1 kHz, 2.5 kHz, 6.25 kHz and 16 kHz – and as you can see there is some overlap between the bands. The strength is returned as a DC voltage – which we can then simply measure with the Arduino’s analogue input and create a display of some sort. At this point audio purists, Sheldonites and RF people might get a little cranky, so once again – this is more for visual indication than any sort of calibration device.

However as an 8-pin IC a different approach is required to get the different levels. The IC will sequentially give out the levels for each band on pin 3- e.g. 63 Hz then 160 Hz then 400 Hz then 1 kHz then 2.5 kHz then 6.25 kHz  then 16 kHz then back to 63 Hz and so on. To start this sequence we first reset the IC by pulsing the RESET pin HIGH then low. This tells the IC to start at the first band. Next, we set the STROBE pin to LOW, take the DC reading from pin 3 with analogue input, store the value in a variable (an array), then set the STROBE pin HIGH. We repeat the strobe-measure sequence six more times to get the rest of the data, then RESET the IC and start all over again. For the visual learners consider the diagram below from the data sheet:

strobing1

To demonstrate this process, consider the function

in the following example sketch:

If you follow through the sketch, you can see that it reads both left- and right-channel values from the two MSGEQ7s on the shield, then stores each value in the arrays left[] and right[]. These values are then sent to the serial monitor for display – for example:

If you have a function generator, connect the output to one of the channels and GND – then adjust the frequency and amplitude to see how the values change. The following video clip is a short demonstration of this – we set the generator to 1 kHz and adjust the amplitude of the signal. To make things easier to read we only measure and display the left channel:


Keep an eye on the fourth column of data – this is the analogRead() value returned by the Arduino when reading the 1khz frequency band. You can also see the affect on the other bands around 1 kHz as we increase and decrease the frequency. However that wasn’t really visually appealing – so now we’ll create a small and large graphical version.

First we’ll use an inexpensive LCD, the I2C model from akafugu reviewed previously. To save repeating myself, also review how to create custom LCD characters from here.

With the LCD with have two rows of sixteen characters. The plan is to use the top row for the levels, the left-channel’s on … the left, and the right on the right. Each character will be a little bar graph for the level. The bottom row can be for a label. We don’t have too many pixels to work with, but it’s a compact example:

lcdfullon

We have eight rows for each character, and the results from an analogueRead() fall between 0 and 1023. So that’s 1024 possible values spread over eight sections. Thus each row of pixels in each character will represent 128 “units of analogue read” or around 0.63 V if the Arduino is running from true 5 V (remember your AREF notes?). The sketch will again read the values from the MSGEQ7, feed them into two arrays – then display the required character in each band space  on the LCD.

Here’s the resulting sketch:

If you’ve been reading through my tutorials there isn’t anything new to worry about. And now for the demo, with sound -

That would look great on the side of a Walkman, however it’s a bit small. Let’s scale it up by using a Freetronics Dot Matrix Display - you may recall these from Clock One. For some background knowledge check the review here.  Don’t forget to use a suitable power supply for the DMD – 5 V at 4 A will do nicely. The DMD contains 16 rows of 32 LEDs. This gives us twice the “resolution” to display each band level if desired. The display style is subjective, so for this example we’ll use a single column of LEDs for each frequency band, with a blank column between each one.

We use a lot of line-drawing statements to display the levels, and clear the DMD after each display. With this and the previous sketches, there could be room for efficiency – however I write these with the beginner in mind. Here’s the sketch:

… and here it is in action:

Conclusion

At this point you have the knowledge to use the MSGEQ7 ICs to create some interesting spectrum analysers for entertainment and visual appeal – now you just choose the type of display enjoy the results.

LEDborder

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 analyser, analyzer, arduino, BLIPTRONICS, com-10468, dev-10306, education, graphic, lesson, MSGEQ7, sparkfun, spectrum, tutorialComments (32)

Kit Review – AVR ISP Shield

Introduction

In the last few weeks I needed to flash some ATmega328P microcontrollers with the Arduino bootloader. There are a few ways of doing this, and one method is to use an AVR ISP shield. It’s a simple kit to assemble and use, so let’s  have look at the process and results.

As the kit is manufactured by Sparkfun, it arrives in typical minimalist fashion:

The kit includes the following items:

That’s it – no URL to instructions or getting started guide or anything. Luckily we have a bit of knowledge behind us to understand what’s going on. The PCB has all the components as SMT including the status LEDs, so the only soldering required is the shield header pins and the six or ten-connector for the programming cable. You receive enough header pins to fit everything except for both six and ten – you can have one or the other, but not both. Having some handy I thought adding my own socket would be a good idea, however the pins are placed too closed to the group of six, nixing that idea:

Assembly

After collecting all my regular soldering tools and firing up the ‘888 it was time to get to work:

The first thing to fit were the shield headers. A simple way to do this is to break off the required lengths:

… then fit them to a matching board:

… then you place the shield on top and solder the pins. After that I used some of my own headers to fit both six and ten-pin ISP headers – it never hurts to do both, one day you might need them and not have soldering equipment at the ready. Finally the zero-insertion force (ZIF) socket goes in last. Push the lever down so it lays flat before soldering. Then you’re finished:

Operation

Now to program some raw microcontrollers. Insert the shield into your board. We used Arduino IDE v1.0.1 without modifying the original instructions from the Arduino team. Now upload the “ArduinoISP” sketch which is in the Examples menu. Once this has been successful the PLS LED will breathe. You then insert the microcontroller into the ZIF socket and gently pull the lever down. The notch on the microcontroller must be on the right-hand side when looking at the shield. Finally – check the voltage! There is a switch at the bottom-left of the shield that allows 5V or 3.3V. This only changes the Vcc so programming a 3.3V microcontroller will still involve 5V via SPI – possibly causing trouble.

Next  you need to select the target board for the microcontroller you’re programming. For example, if it’s going into a Uno – click Uno, even if you’re hosting the shield with an older board such as a Duemilanove. Next, choose the programmer type by selecting Tools > Programmer >  Arduino as ISP. Now for the magic – select Tools > Burn bootloader. The process takes around one minute, during which time the “PROG” LED on the shield will blink and flicker. It turns off once finished, and the IDE also notifies you of this. For the curious, the process is in the video below:

As you hopefully noticed earlier a cable is included which allows in-circuit programming from the shield to your existing project or prototype. However we didn’t have use for it at this time, it will come in handy when doing more advanced work later on.

Conclusion

It’s simple and it works. So if you need to flash a whole tube of raw micros with the Arduino bootloader, this is an option. Full-sized images available on flickr. This kit was purchased without notifying the supplier.

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, avrisp, DEV-11168, kit review, review, tutorialComments (4)

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)

Results – January 2012 Competition

Competition over!

Posted in competitionComments (0)

January 2012 Competition

Competition over.

Posted in competition

Review: Mayhew Labs “Go Between” Arduino Shield

Hello readers

In this article we examine one of those products that are really simple yet can solve some really annoying problems. It is the “Go Between” Arduino shield from Mayhew Labs. What does the GBS do? You use it to solve a common problem that some prolific Arduino users can often face – how do I use two shields that require the same pins?

Using a clever matrix of solder pads, you can change the wiring between the analogue and digital pins. For example, here is the bare shield:

gbsss

Now for an example problem. You have two shields that need access to digital pins 3, 4 and 5 as also analogue pins 4 and 5. We call one shield the “top shield” which will sit above the GBS, and the second shield the “bottom” shield which will sit between the Arduino and the GBS. To solve the problem we will redirect the top shield’s D3~5 to D6~8, and A4~5 to A0~1.

To redirect a pin (for example D3 to D6), we first locate the number along the “top digital pins” horizontal of the matrix (3). Then find the destination “bottom” pin row (6). Finally, bridge that pad on the matrix with solder. Our D3 to D6 conversion is shown with the green dot in the following:

gbsss2

Now for the rest, diverting D4 and D5 to D7 and D8 respectively, as well as analogue pins 4 and 5 to 0 and 1:

gbsss3

The next task is to connect the rest of the non-redirected pins. For example, D13 to D13. We do this by again bridging the matching pads:

gbsss4

Finally the sketch needs to be rewritten to understand that the top shield now uses D6~8 and A0~1. And we’re done!

Try not to use too much solder, as you could accidentally bridge more pads than necessary. And you can always use some solder wick to remove the solder and reuse the shield again (and again…). Now the genius of the shield becomes more apparent.

The only downside to this shield is the PCB design – the days of square corners should be over now:
gbscornersss1

It is a small problem, but one nonetheless. Hopefully this is rectified in the next build run. Otherwise the “Go Between” Shield is a solution to a problem you may have one day, so perhaps keep one tucked away for “just in case”.

While we’re on the subject of Arduino shield pinouts, don’t forget to check out Jon Oxer’s shieldlist.org when researching your next Arduino shield – it is the largest and most comprehensive catalogue of submitted Arduino shields in existence.

[Note - the "Go Between" Shield was purchased by myself personally and reviewed without notifying the manufacturer or retailer]

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, go between, hardware hacking, mayhew labs, product review, reviewComments (0)

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:

After ensuring your printer is connected as described earlier, and has the appropriate power supply and paper – uploading the sketch will result in the following:

Now that the initial burst of printing excitement has passed, let’s look at the sketch and see how it all works. The first part:

configures the virtual serial port and creates an instance for us to refer to when writing to the printer. Next, four variables are defined. These hold parameters used for configuring the printer. As the printer works with these settings there is no need to alter them, however if you are feeling experimental nothing is stopping you. Next we have the function initPrinter(). This sets a lot of parameters for the printer to ready itself for work. We call initPrinter() only once – in void setup(); For now we can be satisfied that it ‘just works’.

Now time for action – void loop(). Writing text to the printer is as simple as:

You can also use .println to advance along to the next line. Generally this is the same as writing to the serial monitor with Serial.println() etc. So nothing new there. Each line of text can be up to thirty-two characters in length.

The next thing to concern ourselves with is sending commands to the printer. You may have noticed the line

This sends the command to advance to the next line (in the old days we would say ‘carriage return and line feed’). There are many commands available to do various things.  At this point you will need to refer to the somewhat amusing user manual.pdf. Open it up and have a look at section 5.2.1 on page ten. Notice how each command has an ASCII, decimal and hexadecimal equivalent? We will use the decimal command values. So to send them, just use:

Easy. If the command has two or more values (for example, to turn the printer offline [page 11] ) – just send each value in a separate statement. For example:

… will put the printer into offline mode. Notice how we used the variable “zero” for 0 – you can’t send a zero by itself. So we assign it to the variable and send that instead. Odd.

For out next example, let’s try out a few more commands:

  • Underlined text (the printer seemed to have issues with thick underlining, however your experience may vary)
  • Bold text
  • Double height and width
Here is the sketch:

And the results:

Frankly bold doesn’t look that bold, so I wouldn’t worry about it too much. However the oversized characters could be very useful, and still print relatively quickly.

Next on our list are barcodes. A normal UPC barcode has 12 digits, and our little printer can generate a variety of barcode types – see page twenty-two of the user manual. For our example we will generate UPC-A type codes and an alphanumeric version. Alphanumeric barcodes need capital letters, the dollar sign, percent sign, or full stop. The data is kept in an array of characters named … barCode[]  and barCode[]2. Consider the functions printBarcode(), printBarcodeThick()  and printBarcodeAlpha() in the following example sketch:

Notice in printBarcodeThick() we make use of the ability to change the vertical size of the barcode – the height in pixels is the third parameter in the group. And here is the result:

So there you have it – another practical piece of hardware previously considered to be out of our reach – is now under our control. Now you should have an understanding of the basics and can approach the other functions in the user guide with confidence. Please keep in mind that the price of this printer really should play a large part in determining suitability for a particular task. It does have issues printing large blocks of pixels, such as the double-width underlining and inverse text. This printer is great but certainly not for commercial nor high-volume use. That is what professional POS printers from Brother, Star, Epson, etc., are for. However for low-volume, personal or hobby use this printer is certainly a deal. As always, now it is up to you and your imagination to put this to use or get up to other shenanigans.

This article would not have been possible without the example sketches provided by Nathan Seidle, the founder and CEO of Sparkfun. If you meet him, shout him a beer.  Please don’t knock off bus tickets or so on. I’m sure there are heavy penalties for doing so if caught.

LEDborder

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, COM-10438, COM-10560, education, lesson, microcontrollers, printer, sparkfun, thermal, tutorialComments (11)

Tutorial: Control AC outlets via SMS

Learn how to control AC outlets via SMS text message. This is chapter thirty-three of a series originally titled “Getting Started/Moving Forward with Arduino!” by John Boxall – A tutorial on the Arduino universe. The first chapter is here, the complete series is detailed here.

Updated 02/03/2013

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

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

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

originaloutletsss

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

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

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

The next step is to crack open the remote control:

originalremotess

… and see what we have to work with:

remotepcbss

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

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

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

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

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

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

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

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

shieldss

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

txsolder1ss

But with time and patience, the wiring was attached:

txsolder2ss

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

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

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

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

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

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

LEDborder

Have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column, or join our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.

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

Tutorial: Arduino and Colour LCD

Learn how to use the colour LCD shield from Sparkfun in chapter twenty-eight of a series originally titled “Getting Started/Moving Forward with Arduino!” by John Boxall – A tutorial on the Arduino universe. The first chapter is here, the complete series is detailed here.

Updated 19/02/2013

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

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

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

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

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

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

as well as the following in void setup():

With regards to lcd.init(), try it first without a parameter. If the screen doesn’t work, try PHILIPS or EPSON instead. There are two versions of the LCD shield floating about each with a different controller chip. The contrast parameter is subjective, however 63 looks good – but test for yourself. Now let’s move on to examine each function with a small example, then use the LCD shield in more complex applications.

The LCD can display 8 rows of 16 characters of text. The function to display text is:

where x and y are the coordinates of the top left pixel of the first character in the string. Another necessary function is:

Which clears the screen and sets the background colour to the parameter colour.  Please note – when referring to the X- and Y-axis in this article, they are relative to the LCD in the position shown below. Now for an example – to recreate the following display:

… use the following sketch:

In example 28.1 we used the function lcd.clear(), which unsurprisingly cleared the screen and set the background a certain colour. Let’s have a look at the various background colours in the following example. The lcd.clear()  function is helpful as it can set the entire screen area to a particular colour. As mentioned earlier, there are the predefined colours red, green, blue, cyan, magenta, yellow, brown, orange, pink, as well as black and white. Here they are in the following example:

And now to see it in action. The colours are more livid in real life, unfortunately the camera does not capture them so well.

Now that we have had some experience with the LCD library’s functions, we can move on to drawing some graphical objects. Recall that the screen has a resolution of 128 by 128 pixels. We have four functions to make use of this LCD real estate, so let’s see how they work. The first is:

This functions places a pixel (one LCD dot) at location x, y with the colour of colour.

Note – in this (and all the functions that have a colour parameter) you can substitute the colour (e.g. BLACK) for a 12-bit RGB value representing the colour required. 

Next is:

Which draws a line of colour COLOUR, from position x0, y0 to x1, y1. Our next function is:

This function draws an oblong or square of colour COLOUR with the top-left point at x0, y0 and the bottom right at x1, y1. Fill is set to 0 for an outline, and 1 for a filled oblong. It would be convenient for drawing bar graphs for data representation. And finally, we can also create circles, using:

X and Y is the location for the centre of the circle, radius and COLOUR are self-explanatory. We will now use these graphical functions in the following demonstration sketch:

You can see Example 28.3  in the following video. (There’s a section in  the video showing semi-circles – however this isn’t possible with the new Arduino v1+ library).  For photographic reasons, I will stick with white on black for the colours.

So now you have an explanation of the functions to drive the screen – and only your imagination is holding you back.  ** Get an Eleven board – it has a microUSB socket so you don’t run the risk of rubbing against shields. For another example of the colour LCD shield in use, check out my version of “Tic-tac-toe“.

LEDborder

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, LCD, LCD-09363, lesson, microcontrollers, tutorialComments (3)

Tutorial: Arduino and GSM Cellular – Part Two

Continue to learn about connecting your Arduino to the cellular network with the SM5100 GSM module shield. This is chapter twenty-seven of a series originally titled “Getting Started/Moving Forward with Arduino!” by John Boxall – A tutorial on the Arduino universe. The first chapter is here, the complete series is detailed here.

Updated 02/03/2013

Assumed understanding for this article is found in part one. If you have not already done so, please read and understand it. In this instalment we continue with bare projects which you can use as a framework for your own creations.

Reach out and control something

First we will discuss how to make something happen by a simple telephone call. And the best thing is that we don’t need the the GSM module to answer the telephone call (thereby saving money) – just let the module ring a few times. How is this possible? Very easily. Recall example 26.1 – we monitored the activity of the GSM module by using our terminal software. In this case what we need to do is have our Arduino examine the text coming in from the serial output of the GSM module, and look for a particular string of characters.

When we telephone the GSM module from another number, the module returns the text as shown in the image below:

term2

We want to look for the text “RING”, as (obviously) this means that the GSM shield has recognised the ring signal from the exchange. Therefore need our Arduino to count the number of rings for the particular telephone call being made to the module. (Memories – Many years ago we would use public telephones to send messages to each other. For example, after arriving at a foreign destination we would call home and let the phone ring five times then hang up – which meant we had arrived safely). Finally, once the GSM shield has received a set number of rings, we want the Arduino to do something.

From a software perspective, we need to examine each character as it is returned from the GSM shield. Once an “R” is received, we examine the next character. If it is an “I”, we examine the next character. If it is an “N”, we examine the next character. If it is a “G”, we know an inbound call is being attempted, and one ring has occurred. We can set the number of rings to wait until out desired function is called. In the following example, when the shield is called, it will call the function doSomething() after three rings.

The function doSomething() controls two LEDs, one red, one green. Every time the GSM module is called for 3 rings, the Arduino alternately turns on or off the LEDs. Using this sketch as an example, you now have the ability to turn basically anything on or off, or call your own particular function. Another example would be to return some type of data, for example you could dial in and have the Arduino send you a text message containing temperature data.

And now for a quick video demonstration. The first call is made, and the LEDs go from red (off) to green (on). A second call is made, and the LEDs go from green (on) to red (off). Although this may seem like an over-simplified example, with your existing Ardiuno knowledge you now have the ability to run any function by calling your GSM shield.

Control Digital I/O via SMS

Now although turning one thing on or off is convenient, how can we send more control information to our GSM module? For example, control four or more digital outputs at once? These sorts of commands can be achieved by the reception and analysis of text messages.

Doing so is similar to the method we used in example 27.1. Once again, we will analyse the characters being sent from the GSM module via its serial out. However, there are two AT commands we need to send to the GSM module before we can receive SMSs, and one afterwards. The first one you already know:

Which sets the SMS mode to text. The second command is:

This command tells the GSM module to immediately send any new SMS data to the serial out. An example of this is shown in the terminal capture below:

smsrxdemo

Two text messages have been received since the module was turned on. You can see how the data is laid out. The blacked out number is the sender of the SMS. The number +61418706700 is the number for my carrier’s SMSC (short message service centre). Then we have the date and time. The next line is the contents of the text message – what we need to examine in our sketch.

The second text message in the example above is how we will structure our control SMS. Our sketch will wait for a # to come from the serial line, then consider the values after a, b, c and d – 0 for off, 1 for on. Finally, we need to send one more command to the GSM module after we have interpreted our SMS:

This deletes all the text messages from the SIM card. As there is a finite amount of storage space on the SIM, it is prudent to delete the incoming message after we have followed the instructions within. But now for our example. We will control four digital outputs, D9~12. For the sake of the exercise we are controlling an LED on each digital output, however you could do anything you like. Although the sketch may seem long and complex, it is not – just follow it through and you will see what is happening:

And now for a video demonstration:

So there you have it – controlling your Arduino digital outputs via a normal telephone or SMS. Now it is up to you and your imagination to find something to control, sensor data to return, or get up to other shenanigans.

If you enjoyed this article, you may find this of interest – controlling AC power outlets via SMS.

LEDborder

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, CEL-00675, CEL-09607, cellphone hacking, cellular, GSM, hardware hacking, lesson, microcontrollers, SM5100, SMS, tutorial

Tutorial – Arduino Uno and SM5100B GSM Cellular

Connect your Arduino Uno or compatible to the cellular network with the SM5100 GSM module shield.

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

If you are looking for tutorials using the SIMCOM SIM900 GSM module, click here, and here if you have an Arduino Mega.

Updated 15/01/2014

Introduction

The purpose of this tutorial is to have your Arduino to communicate over a GSM mobile telephone network using the SM5100B GSM Cellular Shield:

gsmshieldrawss

My goal is to illustrate various methods of interaction between an Arduino and the GSM cellular network using the SM5100B GSM shield from Sparkfun, with which you can then use your existing knowledge to build upon those methods. Doing so isn’t easy – but it isn’t that difficult.

Stop! Please read first:

  • It is assumed that you have a solid understanding of how to program your Arduino. If not, start from chapter zero
  • Sending SMS messages and making phone calls cost real money, so it would be very wise to use a prepaid cellular account or one  that allows a fair amount of calls/SMS
  • The GSM shield only works with “2G” GSM mobile networks operating on the 850, 900 and PCS1800 MHz frequencies. If in doubt, ask your carrier first
  • Australians – you can use any carrier’s SIM card
  • Canadians – this doesn’t work with Sasktel
  • North Americans – check with your cellular carrier first if you can use third-party hardware (i.e. the shield)
  • I cannot offer design advice for your project nor technical support for this article.
  • If you are working on a college/university project and need specific help – talk to your tutors or academic staff. They get paid to help you.
  • Please don’t make an auto-dialler…

AutoDialer_AT5000

Getting started

As mentioned previously, we’re using the Sparkfun GSM shield with the SM5100B module. When you order the shield, don’t forget to order the stacking header pin set as they’re not included with the shield, and you’ll need to solder them on yourself. Power -the GSM shield can often require up to 2A of current in short bursts – especially when turned on, reset, or initiating a call.

However your Arduino board can only supply just under 1A. It is highly recommended that you use an external regulated 5V power supply capable of delivering 2A of current – from an AC adaptor, large battery with power regulator, etc. Otherwise there is a very strong probability of damaging your shield and Arduino.

Ignore this at your own risk

When connecting this supply DO NOT use the DC socket on the Arduino. Instead, connect the 5V (positive) from the supply to the 5V pin on the GSM shield, and the negative to the GND pin.

If you’re looking for a more permanent or easy-to-wire solution, get yourself a DFRobot power shield:

powershield1

This shield sits on top of your GSM shield (which sits on top of your Arduino). Before use you need to set it up:

  1. The only jumpers that should be on the power shield are as shown in the image above;
  2. Connect a power supply of between 9 and 35V DC to the blue terminal block at the bottom-left of the shield;
  3. Connect a voltmeter/multimeter to the other blue terminal block at the top-left and adjust the potentiometer (blue thing between the terminal blocks) until the voltage measured is 5 volts; ignore the LEDs on the shield as they’re not that accurate;
  4. Run a wire from the positive power output to the 5V pin on the shield, and run another one from the negative power output to a GND pin on the shield;
  5. If you have the USB cable connected to your project while operating the GSM shield, remove the USB cable before turning off external power to the project.

Here’s what it looks like once assembled with the antenna:

thelot

Next – use an antenna! The wire hanging from the shield is not an antenna. YOU NEED THE ANTENNA! There are two choices. Either use the smaller one for areas where handheld mobile reception is acceptable, such as this one:

Or if you are in an area of weaker reception, use an external antenna such as that used on a motor vehicle. If you are using the larger vehicle-style aerial, you might find that the plug will not fit to the shield’s connector. For example, consider the following:

smafmess

On the left is the end of the lead from the carphone aerial, the right is the lead from the GSM shield. Problem! The solution is in the centre: an FME male to SMA male adaptor. This one came from element-14, part number 1826209 (it is a Multicomp R23-014-00-002611000).

Furthermore, care needs to be taken with your GSM shield with regards to the aerial lead-module connection, it is very fragile:

solderpointss

And finally, download this document (.pdf). It contains all the AT and ERROR codes that will turn up when you least expect it. Please review it if you are presented with a code you are unsure about.

Wow – all those rules and warnings?

The sections above may sound a little authoritarian, however I want your project to be a success. With the previous iterations of the tutorial people just didn’t follow the instructions – so I hope you do :)

Are you using an Arduino Mega or Leonardo board?

Things are a little different for you. Those boards don’t support SoftwareSerial on digital pins 2 and 3 thus rendering the GSM shield a little trickier to use. Instead, bend back the D2 and D3 pins on the GSM shield as such (click image to enlarge):

Then run jumpers from D2 on the attached shield to D10 and another from D3 to D11. If you’re using the aforementioned power shield it would be on top of the GSM shield however the jumper wires would be the same. Finally in all the sketches, change the line SoftwareSerial cell(2,3);  to SoftwareSerial cell(10,11); . If you have a Leonardo, get a Uno.

Initial check – does it work?

This may sound like a silly question, but considering the cost of the shield and the variables involved, it is a good idea to check if your setup is functioning correctly before moving on. From a hardware perspective for this article, you will need your Arduino board, the GSM shield with activated SIM card and an aerial, and a range of previously used components.

Make sure your SIM card is set to not require a PIN when the phone is turned on. You can check and turn this requirement off with your cellphone. For our initial test, upload the following sketch:

Then connect the GSM shield, aerial, insert the SIM card and apply power. Open the serial monitor box in the Arduino IDE and you should be presented with the following:

ex26p1output

It will take around fifteen to thirty seconds for the text above to appear in full. What you are being presented with is a log of the GSM module’s actions. But what do they all mean?

  • +SIND: 1 means the SIM card has been inserted;
  • the +SIND: 10 line shows the status of the in-module phone book. Nothing to worry about there for us at the moment;
  • +SIND: 11 means the module has registered with the cellular network
  • +SIND: 3 means the module is partially ready to communicate
  • and +SIND: 4 means the module is registered on the network, and ready to communicate

From this point on, we will need to use a different terminal program, as the Arduino IDE’s serial monitor box isn’t made for full two-way communications. You will need a terminal program that can offer full two-way com port/serial communication. For those running MS Windows, an excellent option is available here.

It’s free, however consider donating for the use of it. For other operating systems, people say this works well. So now let’s try it out with the terminal software. Close your Arduino IDE serial monitor box if still open, then run your terminal, set it to look at the same serial port as the Arduino IDE was. Ensure the settings are 9600, 8, N, 1. Then reset your Arduino and the following should appear:

term1

The next step is to tell the GSM module which network frequency(ies) to use. Please download this document (.pdf), and view page 127. There is a range of frequency choices that our module can use. If you don’t know which one to use, contact the telephone company that your SIM card came from. Australia – use option 4. Choose your option, then enter

(where X is the value matching your required frequency) into the terminal software and click SEND. Then press reset on the Arduino and watch the terminal display. You should hopefully be presented with the same text as above, ending with +SIND: 4. If your module returns +SIND: 4, we’re ready to move forward.

If your terminal returned a +SIND: 8 instead of 4, double-check your hardware, power supply, antenna, and the frequency band chosen. If all that checks out call your network provider to see if they’re rejecting the GSM module on their network.

Our next test is to call our shield. So, pick up a phone and call it. Your shield will return data to the terminal window, for example:

term2

As you can see, the module returns what is happening. I let the originating phone “ring” twice, and the module received the caller ID data (sorry, blacked it out). Some telephone subscribers’ accounts don’t send caller ID data, so if you don’t see your number, no problem. “NO CARRIER” occurred when I ended the call. +SIND: 6,1 means the call ended and the SIM is ready.

Have your Arduino “call you”

The document (.pdf) we downloaded earlier contains a list of AT commands – consider this a guide to the language with which we instruct the GSM module to do things. Let’s try out some more commands before completing our initial test. The first one is:

which dials a telephone number xxxxxx. For example, to call (212)-8675309 use

The next one is

which “hangs up” or ends the call. So, let’s reach out and touch someone. In the terminal software, enter your ATDxxxxxxxx command, then hit send. Let your phone ring. Then enter ATH to end the call. If you are experimenting and want to hang up in a hurry, you can also hit reset on the Arduino and it will end the call as well as resetting the system.

So by now you should realise the GSM module is controlled by these AT commands. To use an AT command in a sketch, we use the function

for example, to dial a phone number, we would use

To demonstrate this in a sketch, consider the following simple sketch which dials a telephone number, waits, then hangs up. Replace xxxxxxxx with the number you wish to call.

The sketch in example 26.2 assumes that all is well with regards to the GSM module, that is the SIM card is ok, there is reception, etc. The delay function in void setup() is used to allow time for the module to wake up and get connected to the network. Later on we will read the messages from the GSM module to allow our sketches to deal with errors and so on.

However, you can see how we can simply dial a telephone. You could now have a home alarm system that can call you upon an event happening, etc.

Send an SMS from your Arduino

Another popular function is the SMS or short message service, or text messaging. Before moving forward, download and install Meir Michanie’s SerialGSM Arduino library from here. Sending a text message is incredibly simple – consider the following sketch:

It’s super-simple – just change the phone number to send the text message, and of course the message you want to send. The phone numbers must be in international format, e.g. Australia 0418 123456 is +61418123456 or USA (609) 8675309 is +16098675309.

Reach out and control something

Now let’s discuss how to make something happen by a simple telephone call. And the best thing is that we don’t need the the GSM module to answer the telephone call (thereby saving money) – just let the module ring a few times. How is this possible? Very easily. Recall Example 26.1 above – we monitored the activity of the GSM module by using our terminal software.

In this case what we need to do is have our Arduino examine the text coming in from the serial output of the GSM module, and look for a particular string of characters.

When we telephone the GSM module from another number, the module returns the text as shown in the image below:

We want to look for the text “RING”, as (obviously) this means that the GSM shield has recognised the ring signal from the exchange. Therefore need our Arduino to count the number of rings for the particular telephone call being made to the module. (Memories – Many years ago we would use public telephones to send messages to each other.

For example, after arriving at a foreign destination we would call home and let the phone ring five times then hang up – which meant we had arrived safely). Finally, once the GSM shield has received a set number of rings, we want the Arduino to do something.

From a software perspective, we need to examine each character as it is returned from the GSM shield. Once an “R” is received, we examine the next character. If it is an “I”, we examine the next character. If it is an “N”, we examine the next character. If it is a “G”, we know an inbound call is being attempted, and one ring has occurred.

We can set the number of rings to wait until out desired function is called. In the following example, when the shield is called, it will call the function doSomething() after three rings.

The function doSomething() controls two LEDs, one red, one green. Every time the GSM module is called for 3 rings, the Arduino alternately turns on or off the LEDs. Using this sketch as an example, you now have the ability to turn basically anything on or off, or call your own particular function.

And now for a quick video demonstration. The first call is made, and the LEDs go from red (off) to green (on). A second call is made, and the LEDs go from green (on) to red (off). Although this may seem like an over-simplified example, with your existing Arduino knowledge you now have the ability to run any function by calling your GSM shield:

Control Digital I/O via SMS

Now although turning one thing on or off is convenient, how can we send more control information to our GSM module? For example, control four or more digital outputs at once? These sorts of commands can be achieved by the reception and analysis of text messages.

Doing so is similar to the method we used in example 27.1. Once again, we will analyse the characters being sent from the GSM module via its serial out. However, there are two AT commands we need to send to the GSM module before we can receive SMSs, and one afterwards. The first one you already know:


Which sets the SMS mode to text. The second command is:

This command tells the GSM module to immediately send any new SMS data to the serial out. An example of this is shown in the terminal capture below:

Two text messages have been received since the module was turned on. You can see how the data is laid out. The blacked out number is the sender of the SMS. The number +61418706700 is the number for my carrier’s SMSC (short message service centre). Then we have the date and time. The next line is the contents of the text message – what we need to examine in our sketch.

The second text message in the example above is how we will structure our control SMS. Our sketch will wait for a # to come from the serial line, then consider the values after a, b, c and d – 0 for off, 1 for on. Finally, we need to send one more command to the GSM module after we have interpreted our SMS:

This deletes all the text messages from the SIM card. As there is a finite amount of storage space on the SIM, it is prudent to delete the incoming message after we have followed the instructions within. But now for our example. We will control four digital outputs, D9~12. For the sake of the exercise we are controlling an LED on each digital output, however you could do anything you like.

Although the sketch may seem long and complex, it is not – just follow it through and you will see what is happening:


And now for a video demonstration:

Conclusion

So there you have it – controlling your Arduino digital outputs via a normal telephone or SMS. Now it is up to you and your imagination to find something to control, sensor data to return, or get up to other shenanigans. If you enjoyed this article, you may find this of interest – controlling AC power outlets via SMS.

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

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, CEL-00675, CEL-09607, cellphone hacking, cellular, GSM, lesson, SMS, tronixstuff, tutorialComments (121)

Kit review – Sparkfun Frequency Counter kit

Hello everyone

Today we examine a kit that is simple to construct and an interesting educational tool – the Sparkfun Frequency Counter kit. This is a revised design from a kit originally released by nuxie1 (the same people who brought us the original function generator kit). As a frequency counter, it can effectively measure within the range of 1 to a claimed 6.5 MHz. Unfortunately the update speed and perhaps accuracy is limited by the speed of the microcontroller the kit is based upon – the Atmel ATmega328. Arduino fans will recognise this as the heart of many of their projects.

Interestingly enough the kit itself is a cut-down version of an Arduino Duemilanove-standard board, without the USB and power regulation hardware. The ATmega328 has the Arduino bootloader and the software (“sketch”) is open source (as is the whole kit) and easily modifiable. This means you can tinker away with your frequency counter and also use your kit as a barebones Arduino board with LCD display. More about this later.

This becomes more obvious when looking at the PCB:

pcbss

It was a little disappointing to not find any power regulator or DC socket – you need to provide your own 5V supply. However Sparkfun have been “clever” enough to include a cable with JST plug and socket to allow you to feed the frequency counter from their function generator kit. In other words, buy both. Frankly they might as well just have produced a function generator with frequency counter kit all on one PCB. Anyhow, let’s get building.

The kit comes in a nice reusable stiff red cardboard box. One could probably mount the kit in this box if they felt like it. The components included are just enough to get by. The LCD is a standard 16 x 2 character HD44780-compatible display. (More on these here). It has a black on green colour scheme. You could always substitute your own if you wanted a different colour scheme:

partsss

An IC socket is not included. You will need to install one if you intend to reprogram the microcontroller with another Arduino board.

Assembly was quick and painless. I couldn’t find any actual step-by-step instructions on the internet (Sparkfun could learn a lot from adafruit in this regard) however the component values are printed on the PCB silk-screen; furthermore no mention of LCD connection, but the main PCB can serve as a ‘backpack’ and therefore the pins line up.

To make experimenting with this kit easier I soldered in some header pins to the LCD and matching socket to the main PCB; as well as adding pins for an FTDI cable (5V) to allow reprogramming direct from the Arduino IDE:

lcdsocketss

So there are in fact two ways to reprogram the microcontroller – either pull it out and insert into another Arduino board, or do it in-place with a 5V FTDI cable. Either way should be accessible for most enthusiasts. At this point one can put the screen and LCD together and have a test run. Find a nice smooth 5V DC power source (from an existing Arduino is fine), or perhaps plug it into USB via a 5V FTDI cable – and fire it up:

itworksss

Well, that’s a start. The backlight is on and someone is home. The next step is to get some sort of idea of the measurement range, and compare the accuracy of the completed kit against that of a more professional frequency counter. For this exercise you can observer the kit and my Tek CFC-250 frequency counter measuring the same function generator output:

As you can see the update speed isn’t that lively, and there are some discrepancies as the frequencies move upward into the kHz range. Perhaps this would be an example of the limitations caused by the CPU speed. Next on the to-do list was to make the suggested connection between the function generator kit and the frequency counter. This is quite simple, you can solder the included JST socket into the function generator board, and solder the wires of the lead included with the frequency counter as such:

boardsss

When doing so, be sure to take notice about which PCB hole is connected to which hole, the colours of the wire don’t match the assumed description on the function generator PCB. Furthermore, the voltage applied via the WAVE pin (the frequency source) should not fall outside of 0~+5V.

As mentioned earlier, this kit is basically a minimalist Arduino board, and this gives the user some scope with regards to modification of the software/sketch. Furthermore, the kit has been released under a Creative Commons by-sa  license. So you can download the schematic, Arduino sketch and EAGLE files and create your own versions or updates. If doing so, don’t forget to attribute when necessary.

Overall, this was anther interesting and easy kit to assemble. It is ideal for beginners as there isn’t that much soldering, they end up with something relatively useful, and if you have a standard Arduino Uno or similar board you can upgrade the firmware yourself.

However as a standalone frequency counter, perhaps not the best choice. Think of this kit as an educational tool – involving soldering, Arduino programming and learning how frequency counters work. In this regard, the kit is well suited.

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. Or join our Google Group.

High resolution images are available on flickr.

[Note - The kit was purchased by myself personally and reviewed without notifying the manufacturer or retailer]

Posted in arduino, kit review, KIT-10140Comments (2)

Kit review – Sparkfun Function Generator

Hello readers

[10/09/2011 Update - It would seem that this kit has been discontinued - most likely due to the unavailability of the XR2206 function generator IC - which is a damn shame as it was a great kit. If you are 'feeling lucky' eBay seems to have a flood of them. Purchase at your own risk!]

Time for another kit review (anything to take the heat off from the kid-e-log!). Today we will examine the Sparkfun Function Generator kit. This is based from an original design by Nuxie and has now been given a nice thick red PCB and layout redesign. Although quite a bare-bones kit, it can provide us with the following functions:

  • sine waves
  • triangle waves
  • a 5V square wave with adjustable frequency

There are two frequency ranges to choose from, either 15~4544Hz or 4.1~659.87kHz. Your experience may vary, as these values will vary depending on the individual tolerance of your components.  The coarse and fine adjustment potentiometers do a reasonable job of adjustment, however if you were really specific perhaps a multi-turn pot could be used for the fine adjustment. With the use of a frequency counter one could calibrate this quite well.

The maximum amplitude of the sine and triangle waves is 12V peak to peak, and doing so requires a DC power supply of between 14~22 volts (it could be higher, up to 30 volts – however the included capacitors are only rated for 25V). However if you just need the 5V square-wave, or a lower amplitude, a lesser supply voltage such as 9 volts can be substituted. After running the generator from a 20V supply, the 7812 regulator started to become quite warm – a heatsink would be required for extended use. The main brains of the generator are held by the Exar XR2206 monolithic function generator IC – please see the detailed data sheet for more information.

Now what do you get? Not much, just the bare minimum once more. Everything you need and nothing you don’t …

bagpartsss

Upon turfing out the parts we are presented with:

thepartsss

Not a bad bill of materials – nice to see a DC socket for use with a plug-pack. Considering the XR2206 is somewhat expensive and rare here in the relative antipodes, an IC socket would be nice – however I have learned to just shut up and keep my own range in stock now instead of complaining. Having 5% tolerance resistors took me as a surprise at first, but considering that the kit is not really laboratory-precision equipment the tolerance should be fine. One could always measure the output and make a panel up later on.

Once again, I am impressed with the PCB from Sparkfun. Thick, heavy, a good solder mask and descriptive silk-screen:

pcbss

Which is necessary as there aren’t any instructions with the kit nor much on the Sparkfun website. The original Nuxie site does have a bit of a walk through if you like to read about things before making them. Finally, some resistors and capacitors included are so small, a decent multimeter will be necessary to read them (or at least a good magnifying glass!).

Construction was very simple, starting with the low-profile components such as resistors and capacitors:

resiscapsss

followed by the switches, terminal blocks, IC sockets and the ICs:

icsss

and finally the potentiometers:

potsss

The easiest way to solder in the pots while keeping them in line was to turn the board upside down, resting on the pots. They balance nicely and allow a quick and easy soldering job. At this point the function generator is now ready to go – after the addition of some spacers to elevate it from the bench when in use:

finishedss

Now for the obligatory demonstration video. Once again, the CRO is not in the best condition, but I hope you get the idea…


Although a very simple, barebones-style of kit (in a similar method to the JYETech Capacitance meter) this function generator will quickly knock out some functions in a hurry and at a decent price. A good kit for those who are learning to solder, perhaps a great next step from a TV-B-Gone or Simon kit. And for the more advanced among us, this kit is licensed under Creative Commons attribution+share-alike, and the full Eagle design files are available for download – so perhaps make your own? High resolution images are available on flickr.

[Note - The kit was purchased by myself personally and reviewed without notifying the manufacturer or retailer]

 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 education, kit review, KIT-10015, learning electronics, oscilloscope, test equipment, XR2206Comments (0)

Kit Review – Sparkfun “Simon Game”

Hello everyone

Time for a fun kit review. Aren’t all kit reviews fun? I think so, however sometimes kits can be very practical in use and perhaps not fun – unlike this little monkey. Some of you, including myself, may have childhood memories of the computer game unit from Milton-Bradley called the “Simon”. As demonstrated by the children in this video clip, Simon was a noisy game with four illuminated buttons, your task being to mimic the ever-increasing pattern of flashing buttons and matching sounds:

At first it looks easy, and it is –  however after a few repetitions the length of pattern increases and becomes more complex, forcing you to use your brain and take notice. Some would say it is useful for brain training as well.  This can only be a good thing… which brings me to this kit. The packaging is very good for a change, something you could give as a gift to a non-technical person. That is,  you could give a geek a kit in an anti-static bag, and they would understand, however a beginner may not:

boxss

The contents reveal several pleasant surprises:

partsss1

Finally – a battery-powered kit that actually includes the required power source; and not yum-cha cells, actual Duracells. Nice one Sparkfun. (If you haven’t seen that type of Duracell before, they are “trade-only” versions, generally used to deter theft). The other surprise was the inclusion of an ATmega328-PU microcontroller …

mcuss

… the exact same model as the Arduino Uno and compatible boards. Simon was starting to become more interesting every minute. But more about that later. The final object of interest is a real, live, instruction book. (You can download a copy from here). At this point you can tell this kit is made for beginners (of all ages). There is also a surface-mount component version, which people tell me is great for learning SMD work. Not for me! Good packaging, simple instructions, and a PCB that is solid and well marked out:

pcbrearss

Again, some more interesting things – what looks to be holes that would match up to an FTDI cable, in-circuit programming interface as well as some pinouts for the ATmega328.

[Update - if you're the hacking type, it would pay to mount the IC in a socket, just in case]

However I will move forward and start the soldering. This was quite simple, just follow the guide and all is well. The instructions make a good note when a component is polarised or needs to be inserted in a certain way, very helpful for the beginner:

bottom-solderedss

and the other side was equally as simple:

top-solderedss

On this side you also need to get those AA cell clips installed. The push into their respective holes on the PCB easily, however they can be a trap to solder. Consider the following photo of one of the clips:

batt-clipss

Although the large hole in the PCB is necessary, it has left quite a gap around the wide pin. The inexperienced may end up melting lots of solder and watching it fall through to the other side; to prevent this, place the tip of your soldering iron under the acute side of the pin, and apply solder on the other side. This will force the solder to melt back onto the exposed ring on the PCB and make a good connection, instead of allowing gravity to take over the situation.

After the soldering was finished, the next task is to place the rubber button-mould over the LEDs, and then the black plastic bezel on top. The included screws go through each corner of the bezel, through the white moulding and PCB, and finally break through to the other side – where you can attach the stand-offs. Which leaves us with the final product:

finishedss1

After inserting the AA cells into their new homes, the power was turned on and the unit blinks the LEDs in a sequence until you press a button to start the game. However at this point one of the LEDs did not come on at at all. A quick check with the meter showed it was being fed almost 2.8 volts, but alas – no blinkiness. After a quick desolder/resolder job a green LED from my stock made a replacement. This would have been the only downfall for a beginner, not everyone has boxes of electronics components laying about – nor the high-intensity versions used in this kit.

However life goes on, and Simon still works just as the originals did all those years ago. Here is an example of him in action:


This is something I will need some practice on. Furthermore, the ability to control the sounds is a bonus as well; however if this Simon is aimed for small children, one could be tempted to not install the piezo transducer at all (mini speaker)! So at this stage we have an easy-to-assemble kit that is colourful, noisy and fun – a good start to help introduce another person to our fascinating world of electronics.

But wait – there’s more! Now it is time to revisit those programming holes and see what other secondary uses we can find for Simon. Seeing one of the LEDs isn’t the brightest, I will keep this one for myself, and experiment further. Therefore, the next thing to do to is solder in some header pins to allow connection to an FTDI cable:

simonftdiss

This cable converts the USB interface down to serial line levels suitable for our Simon, in the same way as the FTDI chip does for the Arduino boards (except the Uno). At this point please note you’re on your own, so if you fritz your Simon don’t take it out on me! With hindsight it would be a good idea to use an IC socket for the microcontroller.

Looking at the schematic, we can determine the pins for the LEDs, buttons and so on. The included ATmega328 has the serial bootloader for Arduino programming, so we can have a lot of easily-generated fun with it. However, note that the board does not have an external crystal or oscillator, so timing may not be as accurate as expected.

Disclaimer  - this worked for me, however your experience may vary. Alter your Simon at your own risk!

Anyhow, to use with the Arduino environment, insert the AA cells, plug in your FTDI cable, and select the board type in the environment:

arduinosetupss

Select the second option Arduino Duemilanove or Nano w/ ATmega328. Now you can upload sketches as you would a normal board. The setup functions for the LEDs are:

and for the buttons:

So armed with that knowledge you could create some  custom interactivity with your Simon hardware. If you are unsure about Arduino programming, there is a small tutorial over here that you will find helpful.

Update – New post from Sparkfun about modding your Simon. High resolution images are available on flickr. You can purchase the kit directly from Sparkfun and their resellers. 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. Or join our Google Group.

[Note - The kit was purchased by myself personally and reviewed without notifying the manufacturer or retailer]

Posted in arduino, games, kit review, KIT-10547, KIT-10935, learning electronics, microcontrollers, simonComments (2)

Moving Forward with Arduino – Chapter 19 – GPS part II

Learn more about Arduino and GPS in chapter nineteen of a series originally titled “Getting Started with Arduino!” by John Boxall – A tutorial on the Arduino universe. The first chapter is here, the complete series is detailed here.

Updated 24/01/2013

In this instalment we will continue to examine the use of our GPS system and Arduino through creating two more applications. Some of them may seem simple, but we will build on them later on to make more complex things. To review previous information, the first GPS instalment was chapter seventeen.

“Household official time”

At home we often have various discussions about what the actual time is. At first it sounds silly, but when you have clocks on the microwave, kitchen wall, a wristwatch, mobile phone, clock-radio, and so on – things can get a little out of hand. And my better half has all her clocks ten minutes fast. Insanity may prevail! So let’s make a nice big LED-display reference clock – something that wouldn’t look out of place in a radio or television studio:

Then when people start arguing over the time, you can point at your new clock and smile. From a hardware perspective, we will combine three or four things: our Arduino board, our GPS system, and the MAX7219 display driver. We will need the following items:

  • Arduino Uno or compatible board
  • the GPS shield bundle
  • Maxim MAX7219 display driver IC
  • two four-digit, seven-segment LED displays (common cathode). You could also rig up four separate digits with some patience;
  • one 1 kilo ohm resistor
  • one 10 kilo ohm resistor
  • one single pole, double-throw switch
  • a nice breadboard and some connecting wire
  • a separate 5V power supply – all those LED segments