Friday, December 31, 2010

Kit Review – adafruit industries Ice Tube clock v1.1

Hello readers

Today we examine a kit that perhaps transcends from general electronic fun and games into the world of modern art – the adafruit “Ice Tube” clock.

What is an Ice Tube clock? Before LCDs (liquid-crystal displays) were prevalent another form of display technology was popular – the vacuum-fluorescent display (or VFD). This clock uses a VFD originally manufactured in the former Soviet Union (link for the kids) and Russia. This particular VFD contains a series of seven-segment digits and a dot, which allow the display of time in a bright and retro fashion.

Since this kit was released I had always desired one, however my general parsimonious traits and the wavering exchange rate against the US dollar kept my spending in check. But lately my wallet was hit by a perfect storm: the Australian dollar hit parity with the greenback, adafruit had a discount code and I felt like spending some money – so before the strange feelings passed I ordered a kit post-haste.

Sixteen slow, hot days later the box arrived. I must admit to enjoying a good parcel-opening:

As always, the packaging was excellent and everything arrived as it should have. But what was everything?

Included is the anti-static bag containing the PCB and general components, a bag with the laser-cut acrylic pieces to assemble the housing, another bag with the housing fasteners and the back-up coin cell for the clock, a mains adaptor, and finally another solid cardboard box containing the classic display unit – albeit with the following sensible warning:

And finally the Russian IV-18 display tube:

The tube is a fascinating piece of work, certainly a piece of perfect retro-technology and a welcome addition to my household. Assembling the clock will not be a fast process, and in doing so I recommend reviewing the detailed instructions several times over at the adafruit website. Furthermore, it is a good idea to identify, measure and line up the components ready for use, to save time and confusion along the way. Your experience may vary, however this kit took around three hours for me to construct.

Normally with most kits you can just solder the components in any order, however it is recommended you follow the instructions, as they are well written and allow for testing along the way. For example, after installing the power regulator, you can check the output:

At this stage, you can test your progress with the piezo beeping at power-on:

These mid-construction tests are a good idea as you can hopefully locate any problems before things get out of hand. Another item to be careful with is the PLCC socket for the Maxim MAX6921 VFD driver IC (second from the left):

However with time and patience there is no reason why you would have any problems. Once the main PCB is completed, the next item is the end PCB which connects to the VFD:

At this point it is a good time to have a break and a bit of a stretch, as you need all your patience for soldering in the VFD. Before attempting to do so, try and carefully straighten all the wires from the VFD so they are parallel with each other. Then using the adafruit instructions, make sure you have the tube wires lined up with the correct hole on the PCB:

After I had the leads through the correct holes on the PCB, trimming the leads made things easier:

It is also a good idea to check the gap between the VFD and the PCB is correct, by checking the fit within the housing:

And after much patience, wire pulling with pliers, and light soldering –  the VFD was married to the PCB:

So now the difficult soldering work has been completed and now it was time for another test – the big one… does it all work?

Yes, yes it does. *phew* The low brightness is normal, as that is the default level set by the software. Please note: if you run your VFD without an enclosure that you must be careful of the high voltages on the right-hand side of the PCB and also the VFD PCB. If you test your VFD in this manner, don’t forget to allow ten minutes for the voltage to return to a safe level after removing the power supply. If you have been following the instructions (I hope so!) there is some more soldering to do, after which you can put away your soldering iron.

Now to remove the liner from the acrylic housing pieces and put it all together. Be very careful not to over-tighten the bolts otherwise you will shatter the housing pieces and be cranky. If all is well, you’re finished clock will appear as such:

The clock in use:

And finally, our ubiquitous video demonstration:

VFDs can lose their brightness over the years, and can be difficult to replace – so if you want many, many years of retro-time it would be smart to buy an extra tube from adafruit with your kit, or a modified DeLorean.

Overall, this was an interesting and satisfying kit to assemble. Not for the beginner, but if you have built a few easier kits such as  the “TV-B-Gone” with success, the Ice Tube clock will be within your reach. Furthermore, due to the clear housing, this kit is a good demonstration of your soldering and assembly skills :)

You can purchase the kit directly from adafruit industries. 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]

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

 

Wednesday, December 29, 2010

Tutorial: Arduino and the DS touch screen

This is chapter twenty-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. Please note from November 1, 2010 files from tutorials will be found here.

Welcome back fellow arduidans!

Today we are going to spend some time with a touch screen very similar to the ones found in a Nintendo DS gaming unit. In doing so, we can take advantage of a more interesting and somewhat futuristic way of gathering user input. Please note that in order to use the screen without going completely insane, you will need the matching breakout board, as shown in the following image:

The flimsy flexible PCB runner is inserted into the plastic socket on the breakout board - be careful not to crease the PCB nor damage it as it can be rather easy to do so. (The screen can be easy to break as well...) However don't let that put you off. You will most likely want to solder in some header pins for breadboard use, or sockets to insert wires. For this article it is being used with pins for a breadboard.

Before we start to use the screen, let's have a quick investigation into how they actually work. Instead of me trying to paraphrase something else, there is a very good explanation in the manufacturer's data sheet. So please read the data sheet then return. Theoretically we can consider the X and Y axes to be two potentiometers (variable resistors) that can be read with the analogRead() function. So all we need to do is use two analog inputs, one to read the X-axis value and one for the Y-axis value.

However, as always, life isn't that simple. Although there are only four wires to the screen, the wires' purpose alters depending on whether we are measuring the X- or Y-axis. Which sounds complex but is not. Using the following example, we can see how it all works.

Example 23.1

In this example, we will read the X- and Y-axis values returned from the touch screen and display them on an LCD module. (Or you could easily send the values to the serial monitor window instead). From a hardware perspective, you will need:

Connection of the touch screen to the Arduino board is simple, Arduino analog (yes, analog - more on this later) pins A0 to Y1, A1 to X2, A2 to Y2 and A3 to X1 - as below:

Mounting the rest for demonstration purposes is also a simple job. Hopefully by now you have a test LCD module for easy mounting :)

I have mounted  the touch screen onto the breadboard with some spare header pins, they hold it in nicely for testing purposes. Also notice that the touch screen has been flipped over, the sensitive side is now facing up. Furthermore, don't forget to remove the protective plastic coating from the screen before use.

From a software (sketch) perspective we have to do three things - read the X-axis value, the Y-axis value, then display them on the LCD. As we (should) know from the data sheet, to read the X-axis value, we need to set X1 as 5V, X2 as 0V (that is, GND) and read the value from Y2. As described above, we use the analog pins to do this. (You can use analog pins as input/output lines in a similar method to digital pins - more information here. Pin numbering continues from 13, so analog 0 is considered to be pin 14, and so on). In our sketch (below) we have created a function to do this and then return the X-axis value.

The Y-axis reading is generated in the same method, and is quite self-explanatory. The delay in each function is necessary to allow time for the analog I/O pins to adjust to their new roles as inputs or outputs or analog to digital converters. Here is out sketch:

/*  Example 23.1 - Arduino and touch screen
http://tronixstuff.com/tutorials > Chapter 23
CC by-sa-nc */
#include <LiquidCrystal.h> // we need this library for the LCD commands
LiquidCrystal lcd(12, 11, 5, 4, 2, 3); // your pins may vary int x,y = 0;
void setup()
{
lcd.begin(20,4); // need to specify how many columns and rows are in the LCD unit
lcd.clear();
}
int readX() // returns the value of the touch screen's X-axis
{
int xr=0;
pinMode(14, INPUT);   // A0
pinMode(15, OUTPUT);    // A1
pinMode(16, INPUT);   // A2
pinMode(17, OUTPUT);   // A3
digitalWrite(15, LOW); // set A1 to GND
digitalWrite(17, HIGH);  // set A3 as 5V
delay(5); // short delay is required to give the analog pins time to adjust to their new roles
xr=analogRead(0); //  return xr;
}
int readY() // returns the value of the touch screen's Y-axis
{
int yr=0;
pinMode(14, OUTPUT);   // A0
pinMode(15, INPUT);    // A1
pinMode(16, OUTPUT);   // A2
pinMode(17, INPUT);   // A3
digitalWrite(14, LOW); // set A0 to GND
digitalWrite(16, HIGH);  // set A2 as 5V
delay(5); // short delay is required to give the analog pins time to adjust to their new roles
yr=analogRead(1); //
return yr;
}
void loop()
{
lcd.setCursor(0,0);
lcd.print(" x = ");
x=readX();
lcd.print(x, DEC);
y=readY();
lcd.setCursor(0,1);
lcd.print(" y = ");
lcd.print(y, DEC);
delay (200);
}

Next, let's have a look at this example in action. The numbers on the LCD may be not what you expected...

The accuracy of the screen is not all that great - however first take into account the price of the hardware before being too critical. Note that there are values returned even when the screen is not being pressed, we could perhaps call these "idle values". Later on you will learn tell your sketch to ignore these values if waiting for user input, as they will note that nothing has been pressed. Furthermore, the extremities of the screen will return odd values, so remember to take this into account when designing bezels or mounting hardware for your screen.

Each touch screen will have different values for each X and Y position, and that is why most consumer hardware with touch screens has calibration functions to improve accuracy. We can now use the X and Y values in sketches to determine which part of the screen is being touched, and act on that touch.

In order to program our sketches to understand which part of the screen is being touched, it will help to create a "map" of the possible values available. You can determine the values using the sketch from example 23.1, then use the returned values as a reference for designing the layout of your touch interface. For example, the following is a map of my touch screen:

Example 23.2

For the next example, I would like to have four "zones" on my touch screen, to use as virtual buttons for various things. The first thing to do is draw a numerical "map" of my touch screen, in order to know the minimum and maximum values for both axes for each zone on the screen:

At this point in the article I must admit to breaking the screen. Upon receiving the new one I remeasured the X and Y points for this example and followed the  process for defining the numerical boundaries for each zone is completed by finding average mid-points along the axes and allowing some tolerance for zone boundaries.

Now that the values are known, it is a simple matter of using mathematical comparison and Boolean operators (such as >, <, &&, etc)  in a sketch to determine which zone a touch falls into, and to act accordingly. So for this example, we will monitor the screen and display on the LCD screen which area has been pressed. The hardware is identical to example 23.1, and our touch screen map will be the one above. So now we just have to create the sketch.

After reading the values of the touch screen and storing them into variables x and y, a long if...then...else if loop occurs to determine the location of the touch. Upon determining the zone, the sketch calls a function to display the zone type on the LCD. Or if the screen is returning the idle values, the display is cleared. So have a look for yourself with the example sketch:

/*
Example 23.2 - Arduino and touch screen - four zone demonstration
http://tronixstuff.com/tutorials > Chapter 23 CC by-sa-nc
*/
#include <LiquidCrystal.h> // we need this library for the LCD commands
LiquidCrystal lcd(12, 11, 5, 4, 2, 3); // your pins may vary int x,y = 0;
int d = 500; // used for display delay
void setup()
{
lcd.begin(20,4); // need to specify how many columns and rows are in the LCD unit
lcd.clear();
}
int readX() // returns the value of the touch screen's X-axis
{
int xr=0;
pinMode(14, INPUT);   // A0
pinMode(15, OUTPUT);    // A1
pinMode(16, INPUT);   // A2
pinMode(17, OUTPUT);   // A3
digitalWrite(15, LOW); // set A1 to GND
digitalWrite(17, HIGH);  // set A3 as 5V
delay(5); // short delay is required to give the analog pins time to adjust to their new roles
xr=analogRead(0); //  return xr;
}
int readY() // returns the value of the touch screen's Y-axis
{
int yr=0;
pinMode(14, OUTPUT);   // A0
pinMode(15, INPUT);    // A1
pinMode(16, OUTPUT);   // A2
pinMode(17, INPUT);   // A3
digitalWrite(14, LOW); // set A0 to GND
digitalWrite(16, HIGH);  // set A2 as 5V
delay(5); // short delay is required to give the analog pins time to adjust to their new roles
yr=analogRead(1); //  return yr;
}
// the next four functions just display a zone label on the LCD
void displayA()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("AAAAAAAAAA");
lcd.setCursor(0,1);
lcd.print("AAAAAAAAAA");
delay(d);
}
void displayB()
{
lcd.clear();
lcd.setCursor(10,0);
lcd.print("BBBBBBBBBB");
lcd.setCursor(10,1);
lcd.print("BBBBBBBBBB");
delay(d);
}
void displayC()
{
lcd.clear();
lcd.setCursor(0,2);
lcd.print("CCCCCCCCCC");
lcd.setCursor(0,3);
lcd.print("CCCCCCCCCC");
delay(d);
}
void displayD()
{
lcd.clear();
lcd.setCursor(10,2);
lcd.print("DDDDDDDDDD");
lcd.setCursor(10,3);
lcd.print("DDDDDDDDDD");
delay(d);
}
void loop()
{
// get values from touch screen
x=readX();
y=readY();
// now determine where the touch was located on the screen
if (y>510 && x>520 && x<1000 && y <1000)
{
displayA();
} else
if (y>510 && x<510)
{
displayB();
} else
if (y<500 && x>520)
{
displayC();
} else
if (y<500 && x<510)
{
displayD();
} else
if (x>1000 && y>1000)
{
lcd.clear();
}
}

And see it in operation:

 

So there you have it, I hope you enjoyed reading this as much as I did writing it. Now you should have the ability to use a touch screen in many situations - you just need to decide how to work with the resulting values from the screen and go from there.

If you have any questions about the processes or details in this article, please ask in our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, there is the odd competition or give-away –  and we can all learn something.

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

Tuesday, December 21, 2010

Kit review - Sparkfun Function Generator

Hello readers

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~35 volts. 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 ...

Upon turfing out the parts we are presented with:

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:

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:

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


and finally the potentiometers:


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:

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?

In the next few weeks I plan to rebuild this in conjunction with the matching frequency counter kit, and mount them into a small enclosure which should make a nice piece of equipment to have on the bench or perhaps give away. So stay tuned...

You can purchase the kit directly from Little Bird Electronics. 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]

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

 

Thursday, December 16, 2010

Project - The "Kid-e-log"

Hello readers

Recently I was listening to a friend who has three teenage children, of whom needed to arrive home before their parent. Unfortunately the parent needs to work all day and arrives home in the evening, and they lamented not being able to check when the children had arrived home.

After a few hours it occurred to me that a simple time clock would solve her problem - each child could check-in upon arriving home, and the parent could review the check-in times later on. And thus the kid-e-log was born.

The name is the result of a competition at the tronixstuff Google Group. If you have not already, why not join and you can take part in future give-aways? Anyhow, moving forward...

From a hardware perspective, it would be quite simple. An LCD screen, RFID reader and some tags, and a real time clock IC such as a Maxim DS1307 - all running from the ubiquitous Arduino board. After some contemplation it occured to me that smart kids might try to mess up the hardware by pulling the power, so it also uses an EEPROM to store time data which is impervious to power loss, and the kid-e-log will not have any user buttons. After initial programming for time and RFID key data, any changes will need to be effected by the programmer (i.e. me).

Before jumping ahead and making something, we discussed exactly what the function would be. Each child would have an RFID tag, and when it is read the hardware will save the arrival time in memory, and display it on the LCD. The time data will be reset automatically at 0400h or by reading an RFID card belonging to the parent. There will not be any buttons, and the hardware must be power-failure resistant - therefore EEPROM memory is needed for time data and a backup battery for the real-time clock.

From a hardware perspective, the requirements are quite simple:

  • An Arduino-style board of some sort (we used the Freetronics TwentyTen)
  • Maxim DS1307 real-time clock IC (I will use the TwentyTen/DS1307 combo from here)
  • Microchip 24LC256 EEPROM
  • Usual 16 character, 2 line LCD with HD44780-compatible interface (will use this for the prototype)
  • 125kHz RFID reader with serial output, and four RFID tags (don't get the Weigand version!)
  • Two 4.7 kilo ohm resistors (for I2C bus with EEPROM)
  • Two 0.1 uF ceramic capacitors (for power smoothing on the breadboard)
  • solderless breadboard for prototyping
  • a nine volt DC power adaptor, rated for no less than 300 milliamps
  • And for the final product, a nice enclosure. More on that later...

The DS1307 and the EEPROM are both using the I2C bus, and the RFID reader (more information) uses Arduino digital pin zero (serial input).  The LCD is pretty straight forward as well, as described in more detail here. If this project seems complex, it is just the sum of some knowledge from my variousArduino tutorials.

Here is the schematic for the prototype hardware:


From a software (sketch) perspective, the design is easily broken up into distinct functions which makes programming quite easy. The sketch is a basic loop, which follows as such:

  • check to see if a tag is read by the RFID reader - if so, branch to the the reading function (which compares the read tag against those on file, and records the time matching the tag to the EEPROM)
  • display real time, date and check-in data on the LCD - another function
  • delay for a moment to stop the LCD flickering from fast updating
  • check if the time is 4am, and if so call a function to reset the check-in times

From each of those four main instructions, functions are called to handle various tasks. For example the displayData() funtion is used to read the DS1307 real time clock, and display the time and date on the top line of the LCD. Then it reads the contents of the EEPROM, and displays the check in time for each RFID tag - or a line if they have not checked in yet.

The data stored in the EEPROM is held in following order

  • tag 1 status (0 for not checked in, 1 for checked in)
  • tag 1 check-in hour
  • tag 1 check-in minute

and repeats for tag two and three. Reading the RFID tags is simple, we reuse code from example 15.3 in our RFID tutorial sketches. You will notice in the sketch that the RFID cards' serial data are stored in individual arrays. You will need to read your RFID cards first with another sketch in order to learn their values. Example 15.1 from the RFID tutorial will do nicely. The rest of the sketch should be quite easy to follow, however if you have any questions please ask.

You can download the sketch from our file repository here. If you have problems, let me know.

Next for the hardware. Here is our prototype, ready for action:

And now for a short video clip of the prototype kid-e-log in operation:


Notice how removing the power does not affect the real time nor the stored check-in data. Almost child-proof. The final task was to reassemble the prototype in order to fit into a nice enclosure. Unfortunately by this stage the person concerned had moved away, so I had no need to finish this project. However I had already purchased this nice enclosure:

It was just large enough to accept the TwentyTen, and protoshield with the EEPROM and RFID reader circuitry, and the LCD module. It is custom-designed with mounts for Arduino boards and the LCD - a perfect fit. However the use of it can wait for another day. So an important note to self - even if designing things for a friend - get a deposit!

Such is life. I hope you enjoyed reading about this small project and perhaps gained some use for it of your own or sparked some other ideas in your imagination that you can turn into reality. If you would like to discuss it further, please do so in our Google Group. If you are having trouble sourcing the required parts, let me know via john (at) tronixstuff.com.

Otherwise, have fun, be good to each other and stay safe!

Monday, December 6, 2010

Tutorial: Arduino and the AREF pin

This is chapter twenty-two of a series originally titled “Getting Started/Moving Forward with Arduino!” by John Boxall– A tutorial on the Arduino universe.

The first chapter is here, the complete series is detailed here. Please note from November 1, 2010 files from tutorials will be found here.

Welcome back fellow arduidans!

Today we are going to spend some time with the AREF pin - what it is, how it works and why you may want to use it.

First of all, here it is on our boards:

Uno/TwentyTen AREF

Mega AREF

[Please read whole article before working with your hardware]

In chapter one of this series we used the analogRead() function to measure a voltage that fell between zero and five volts DC. In doing so, we used one of the six analog input pins. Each of these are connected to ADC (analog to digital conversion) pins in the Arduino's microcontroller. And the analogRead() function returned a value that fell between 0 and 1023, relative to the input voltage.

But why is the result a value between 0~1023? This is due to the resolution of the ADC. The resolution (for this article) is the degree to which something can be represented numerically. The higher the resolution, the greater accuracy with which something can be represented. We call the 5V our reference voltage.

We measure resolution in the terms of the number of bits of resolution. For example, a 1-bit resolution would only allow two (two to the power of one) values - zero and one. A 2-bit resolution would allow four (two to the power of two) values - zero, one, two and three. If we tried to measure  a five volt range with a two-bit resolution, and the measured voltage was four volts, our ADC would return a value of 3 - as four volts falls between 3.75 and 5V.

It is easier to imagine this with the following image:

So with our example ADC with 2-bit resolution, it can only represent the voltage with four possible resulting values. If the input voltage falls between 0 and 1.25, the ADC returns 0; if the voltage falls between 1.25 and 2.5, the ADC returns a value of 1. And so on.

With our Arduino's ADC range of 0~1023 - we have 1024 possible values - or 2 to the power of 10. So our Arduinos have an ADC with a 10-bit resolution. Not too shabby at all. If you divide 5 (volts) by 1024, the quotient is 0.00488 - so each step of the ADC represents 4.88 millivolts.

However - not all Arduino boards are created equally. Your default reference voltage of 5V is for Arduino Duemilanoves, UnosMegas, Freetronics TwentyTens and others that have an MCU that is designed to run from 5V. If your Arduino board is designed for 3.3V, such as an Arduino Pro Mini-3.3 - your default reference voltage is 3.3V. So as always, check your board's data sheet.

What if we want to measure voltages between 0 and 2, or 0 and 4.6? How would the ADC know what is 100% of our voltage range?

And therein lies the reason for the AREF pin! AREF means Analogue REFerence. It allows us to feed the Arduino a reference voltage from an external power supply. For example, if we want to measure voltages with a maximum range of 3.3V, we would feed a nice smooth 3.3V into the AREF pin - perhaps from a voltage regulator IC. Then the each step of the ADC would represent 3.22 millivolts.

Interestingly enough, our Arduino boards already have some internal reference voltages to make use of. Boards with an ATmega328 microcontroller also have a 1.1V internal reference voltage. If you have a Mega (!), you also have available reference voltages of 1.1 and 2.56V.

So how do we tell our Arduinos to use AREF? Simple. Use the function analogReference(type); in the following ways:

For Duemilanove and compatibles with ATmega328 microcontrollers:

  • analogReference(INTERNAL); - selects the internal 1.1V reference voltage
  • analogReference(EXTERNAL); - selects the voltage on the AREF pin (that must be between zero and five volts DC)
  • And to return to the internal 5V reference voltage - use analogReference(DEFAULT);

If you have a Mega:

  • analogReference(INTERNAL1V1); - selects the internal 1.1V reference voltage
  • analogReference(INTERNAL2V56); - selects the internal 2.56V reference voltage
  • analogReference(EXTERNAL); - selects the voltage on the AREF pin (that must be between zero and five volts DC)
  • And to return to the internal 5V reference voltage - use analogReference(DEFAULT)

Note you must call analogReference() before using analogRead(); otherwise you will short the internal reference voltage to the AREF pin - possibly damaging your board. If unsure about your particular board, ask the supplier or perhaps in our Google Group.

Now that we understand the Arduino functions, let's look at some ways to make a reference voltage. The most inexpensive method would be using resistors as a voltage divider. For example, to halve a voltage, use two identical resistors as such:

For a thorough explanation on dividing voltage with resistors, please read this article. Try and use resistors with a low tolerance, such as 1%, otherwise your reference voltage may not be accurate enough. However this method is very cheap.

A more accurate method of generating a reference voltage is with a zener diode. Zener diodes are available in various breakdown voltages, and can be used very easily. Here is an example of using a 3.6V zener diode to generate a 3.6V reference voltage:

For more information about zener (and other diodes) please read this article. Finally, you could also use a linear voltage regulator as mentioned earlier. Physically this would be the easiest and most accurate solution, however regulators are not available in such a wide range nor work with such low voltages (i.e. below 5V).

Finally, when developing your sketch with your new AREF voltage for analogRead();, don't forget to take into account the mathematics of the operation. For example, if you have a reference voltage of 5V, divide it by 1024 to arrive at a value of 4.88 millivolts per analogRead() unit. Or as in the following example, if you have a reference voltage of 1.8V, dividing it by 1024 gives you 1.75 millivolts per analogRead() unit:\

/*
Example 22.1  Measuring range of analogRead() using a 1.8V AREF voltage   tronixstuff.com/tutorials  CC by-sa-nc
*/
int analoginput = 0; // our analog pin int analogamount = 0; // stores incoming value float percentage = 0; // used to store our percentage value float voltage =0; // used to store voltage value
void setup() {
Serial.begin(9600);
analogReference(EXTERNAL); // use AREF for reference voltage
}
void loop() {
delay(200);
analogamount=analogRead(analoginput);
percentage=(analogamount/1024)*100;
voltage=analogamount*1.75; // in millivolts
Serial.print("Percentage of AREF: ");
Serial.println(percentage,2);
Serial.print("voltage on analog input (mV): ");
Serial.println(voltage,2);
}

So if necessary, you can now reduce your voltage range for analog inputs and measure them effectively.

Well once more that is all we have time for in this instalment. Stay tuned for upcoming Arduino tutorials by subscribing to the blog, RSS feed (top-right) or joining our Google Group.

If you have any questions about the processes or details in this article, please ask in our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, there is the odd competition or give-away –  and we can all learn something.

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

Saturday, November 6, 2010

November 2010 – why so quiet?

Hello readers and visitors

November will be somewhat quieter than usual, I am relocating interstate which as you can imagine involves lots of boring, non-electronic work. So things will be a little quiet around here until the start of December. However your emails and questions will still be answered whenever possible. Follow me on twitter, or head over to my site tronixstuff.com - then subscribe (see the column to the right) to be notified when things are back to normal. 2011 will be much more interesting – I will have more work space, a house to modify, and even some products to offer. So stay tuned!

Wednesday, November 3, 2010

Kit Review – adafruit industries mintyboost v3

Hello readers

Today we are going introduce another useful kit from adafruit industries – their mintyboost kit. The purpose of this kit is to provide a powered USB socket suitable for charging a variety of devices, powered from a pair of AA cells. The mintyboost is quite a simple, yet clever design – the latest version is based around the Linear Technology LT1302 DC/DC step-up converter that we examined a few months ago - and can provide a full 5 volts DC at 500 milliamps, enough to charge the latest round of USB-chargable gadgets, including those iPhones that I keep hearing about. And unlike an iPhone, the mintyboost kit is licensed under a Creative Commons v2.5 attribution license.

But enough reading, time to make it. As always, instructions are provided online – are easy to follow and very clear. The kit will arrive in a nice reusable anti-static bag:

Which contains everything you need except for AA cells and a housing:

Where or how you contain your mintyboost is a subjective decision, and will probably vary wildly. The original design brief was to have it fit inside a tin that Altoidsconfectionary is sold in, however those are not available around my area. But I found a suitable replacement. The PCB is very small, and designed to fit snugly inside the aforementioned tin:

Very small – less than 38 x 20 mm in dimension. However with some care and caution, you can solder the components without using a vice or “helping hands”. Though if you have access to these, use them as it will make life a lot easier. Before we move on, please note that my 49.9k ohm resistors, ceramic capacitors and the inductor are a different size to those included with the kit. This is my second mintyboost, and to save money I bought the PCB only and used my own parts to make this one.

If size is an issue for you, it is a good idea to buy the entire kit, as you will have resistors that fit flush with the PCB, unlike mine :)

However, construction moved along smoothly, by following the instructions, double-checking my work and not rushing things. There is some clever designing going on here, I have never seen a resistor underneath an IC socket before!

But when PCB real estate is at a premium, you need think outside of the box. After this stage there was just the electrolytic capacitors and battery holder to install. One that has been done, you can insert some fresh AA cells and check the output voltage on the USB lines:

Looking good, however it could have been a bit higher if the AA cells were freshly charged. But the second USB voltage was spot on:

Success! It always feels good to make a kit and have it work the first time. The last soldering was to take care of fitting the USB socket, and then it was finished:

Now to take it for a test run. I have two USB-charging items to test it with, my HTC Desire:

The LED to the right of the htc logo indicates the power is in, and the battery indicator on the left of the clock indicates charging. Excellent. The phone battery is 1400 mAh – I most likely won’t get a full recharge from the two AA cells, but enough to get me through an extra night and half a day. The mintyboost is a perfect backup-charging solution to leave in your backpack or other daily case. And now for something from Apple, an iPod of about four years old (it still holds a charge, so I’m not falling for the “buy a new iPod every twelve months” mantra):

Again, perfect. Apple equipment can be quite finicky about the voltages being fed to them, and will not work if there is a slight difference to what the device expects to be fed. As you can see the team at adafruit have solved this problem nicely. There is also much discussion about various devices and so on in their support forums.

Now for the decision with regards to housing my mintyboost. The Altoids tins are not an option, and I’m not cannibalising my mathematical instruments storage tin. But I knew I kept this tin for a reason from last February:

Plenty of room for the PCB, the charging cable, emergency snack cash and even more AA cells if necessary. And where else could I have put the socket, but here:

:) I have named it the bunnyboost:

… who can safely live in the bottom of my backpack, ready to keep things powered at a moments’ notice. Excellent!

As you can see, the mintyboost is a simple, yet very practical kit. It would also make a great gift for someone as well, as USB-charging devices are becoming much more popular these days. If you are looking to buy a kit, those of you in the Australasian market can get one from Little Bird Electronics, or globally available from adafruit industries.

Once again, thank you for reading and I look forward to your comments and so on. Please subscribe using one of the methods at the top-right of this web page to receive updates on new posts, and if you have any questions – why not join our Google Group? It’s free and we’re all there to learn and help each other.

High resolution photos are available on flickr.

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