Saturday, February 26, 2011

Kit review – ogi lumen Nixie Tube system

Hello readers

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

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

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

The tubes used in this kit are the Soviet model IN-12A:

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

There are three components to the system, the first being the power supply:

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

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

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

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

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

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

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

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

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

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

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

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

/* Nixie tube demonstration code - function to display an integer
http://tronixstuff.com - John Boxall. February 2011.
Modifed sketch originally created by Lionel Haims, July 25, 2008. Released into the public domain. */
// include the library
#include <Nixie.h>
// note the digital pins of the arduino that are connected to the nixie driver
#define dataPin 2  // data line or SER
#define clockPin 3 // clock pin or SCK
#define latchPin 4 // latch pin or RCK
// note the number of digits (nixie tubes) you have (buy more, you need more!)
#define numDigits 4
int narray[numDigits]; // holds the digits to display
int z=0;
// Create the Nixie object
// pass in the pin numbers in the correct order
Nixie nixie(dataPin, clockPin, latchPin);
void setup()
{
nixie.clear(numDigits); // clear display
}
void nixNum(int z)
// displays integer 'z' on 4-digit nixie display
// keeps leading zero, as blank still flickers somewhat
{
narray[0]=int(z/1000); // thousands value
z=z-(narray[0]*1000);
narray[1]=int(z/100); // hundreds value
z=z-(narray[1]*100);
narray[2]=int(z/10); // tens value
narray[3]=z-(narray[2]*10); // ones value
nixie.writeArray( narray, numDigits);
}
void loop()
{
nixNum(1234);
delay(2000);
for (int q=1234; q<10000; q++)
{
nixNum(q);
delay(100);
}
}

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

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

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

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

Remember, if you have any questions about these modules please contact Ogi Lumen via their website.

Higher resolution images available on flickr.

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

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

Wednesday, February 23, 2011

Various 555 Timer circuits

Hello readers

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

Button de-bouncer

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

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

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

Make some noise

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

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

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

Question – Name the company that first manufactured the 555 IC.

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

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

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

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!

Thursday, February 17, 2011

Tutorial: Arduino and TFT LCD

This is chapter twenty-nine 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 continue with experimenting with colour LCD units. In this article we will get started with a very clear and sharp unit – the 4D Systems 1.44″ TFT serial interface LCD:

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

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

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

Changing the firmware from GFX to SGC

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

  • Visit here, download and open the PmmC Loader application; visit here and download the .pmmc file to your local drive;
  • Connect your Arduino board via USB to the computer; then run the PmmC loader application;
  • Select the appropriate COM: port, load in the .pmmc file, then click Load. The firmware update should take less than sixty seconds;
  • When finished, you will be presented with the following on the computer:

… and the following on your LCD:

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

And we’re back…

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

However, to get up to speed as fast as possible we can use a library with more of the popular functions included. Kudos and thanks to Oscar Gonzalez for writing a very useful library. Download the library from here and install into your ../Arduino-002x/libraries folder, then re-start the Arduino IDE if you had it running. You may be wondering why the library is nameddisplayshield4d - the LCD manufacturer sells this LCD on an Arduino shield. Although that would be great for experimenting, one would need to purchase another standalone LCD if their project moved forward – myself included. So that’s why we’re using the bare LCD board.

To connect the LCD to our Arduino is very simple:

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

In the following examples we will demonstrate the various functions available in the library. As this is chapter 29, (when will this stop?) I will no longer explain the more basic functions or ideas that you should know by now, instead relying on comments within the sketch if it feels necessary.

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

#include <displayshield4d.h> // include the LCD library
DisplayShield4d  lcd;

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

Serial.begin(115200);  // LCD speed is very high
lcd.Init(); // wake up LCD
lcd.Clear(); // clear the LCD, set background to black

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

lcd.setfontmode(OLED_FONT_TRANSPARENT);  // set font background type

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

Whenever a function requires a colour parameter, we use:

lcd.RGB(x,y,z);

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

lcd.drawstringblock(a, b, c, lcd.RGB(255, 255, 255), d, e, "Hello, world");

The parameters required are:

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

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

Example 29.1

/*  Example 29.1 - uLCD-144 text demonstration
http://tronixstuff.com/tutorials > chapter 29  CC by-sa-nc  */
#include <displayshield4d.h> // necessary library
DisplayShield4d  lcd; // create an instance of the LCD
void setup()
{
Serial.begin(115200);  // LCD speed is very high
lcd.Init(); // wake up LCD
lcd.Clear(); // clear the LCD, set background to black
}
void loop()
{
lcd.Clear(); // clear LCD
lcd.setfontmode(OLED_FONT_TRANSPARENT);  // set font background type
for (int a=0; a<128; a+=8)
{
lcd.drawstringblock(0, a, 2 , lcd.RGB(255, 0, 0), 1, 1, "visit me");
}
delay(2000);
lcd.Clear();
for (int a=0; a<128; a+=16)
{
lcd.drawstringblock(0, a, 0, lcd.RGB(0, 255, 0), 2, 2, "0123456789");
}
delay(2000);
lcd.Clear();
for (int a=0; a<128; a+=32)
{
lcd.drawstringblock(0, a, 0, lcd.RGB(0, 0, 255), 4, 4, "Great");
}
delay(2000);
}

And a short video clip of the example in action:

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

Question – How many capacitors are used in a Freetronics KitTen?

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

lcd.putpixel(x,y,lcd.RGB(r,g,b));

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

lcd.line(x1,y1,x2,y2,lcd.RGB(r,g,b));

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

lcd.rectangle(x,y,l,h,z,lcd.RGB(r,g,b));

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

lcd.circle(x,y,r,z,lcd.RGB(r,g,b);

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

lcd.triangle(x1,y1,x2,y2,x3,y3,z,lcd.RGB(r,g,b));

This will draw a triangle with the corners at the coordinate parameters; z again is the solid/wireframe parameter. However you need to order the corners in an anti-clockwise order. This will become evident in the example sketch below.

Example 29.2

In this example we run through the graphical functions described above. By following through the sketch you should gain an idea of how the graphical functions are used, in order to create your own displays.

/*  Example 29.2 - uLCD-144 graphic library demonstration
http://tronixstuff.com/tutorials > chapter 29  CC by-sa-nc  */
int a,b,c,d,e=0;
#include <displayshield4d.h> // necessary library
DisplayShield4d  lcd; // create an instance of the LCDvoid
setup()
{
randomSeed(analogRead(0));
Serial.begin(115200);  // LCD speed is very high
lcd.Init(); // wake up LCD
lcd.Clear(); // clear the LCD, set background to black
}
void loop()
{
lcd.Clear();
for (int z=0; z<2500; z++)
{
a=random(127);
b=random(127);
c=random(255);
d=random(255);
e=random(255);
lcd.putpixel(a,b,lcd.RGB(c,d,e));
}
delay(1000);
lcd.Clear();
for (int z=0; z<64; z++)
{
lcd.line(0,0,127,z*2,lcd.RGB(0,255,0));
}
for (int z=0; z<64; z++)
{
lcd.line(0,0,z*2,127,lcd.RGB(0,0,255));
}
delay(1000);
lcd.Clear();
for (int z=0; z<15; z++)
{
lcd.rectangle(z*10, z*10, 20, 20, 1, lcd.RGB(255,0,0));
delay(250);
lcd.rectangle(z*10, z*10, 20, 20, 0, lcd.RGB(0,0,255));
delay(250);
lcd.rectangle(z*10, z*10, 20, 20, 0, lcd.RGB(0,0,0));
delay(250);
}
delay(1000);
lcd.Clear();
for (int z=0; z<14; z++)
{
lcd.circle(63,63,z*3, 1, lcd.RGB(0,0,255));
delay(250);
lcd.circle(63,63,z*3, 0, lcd.RGB(0,255,0));
delay(250);
lcd.circle(63,63,z*3, 0, lcd.RGB(0,0,0));
delay(250);
}
delay(1000);
lcd.Clear();
for (int z=10; z>-0; --z)
{
lcd.triangle(127,127,64,z*10,0,127,1,lcd.RGB(0,255,0));
delay(250);
lcd.triangle(127,127,64,z*10,0,127,0,lcd.RGB(0,0,255));
delay(250);
lcd.triangle(127,127,64,z*10,0,127,0,lcd.RGB(0,0,0));
delay(250);
}
}

And here is the video of example 29.2 in action … brought to you by Mr Blurrycam:

So there you have it, another useful part and a very nice colour LCD to make use of. Stay tuned for upcoming Arduino tutorials by subscribing to the blog, RSS feed (top-right), twitter 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, February 12, 2011

The world’s smallest oscilloscope??

Hello readers

Today we examine a tiny and fascinating piece of test equipment from Gabotronics – their XMEGA XprotolabSure, that sounds like a lot – and it is. Yet the functionality of the Xprotolab is inversely proportional to its physical size. Try to imagine having an oscilloscope, arbitrary waveform generator, logic analyser and a spectrum analyser – including a display – in a package no larger than 25.4 x 40.6 mm (1″ x 1.6″) in size. Well imagine no more as here it is:

As described above, this tiny marvel of engineering has the following functions:

  • Two analogue oscilloscope channels with a maximum sampling rate of 2 million samples per second;
  • Analogue bandwidth of 320 kHz at 8-bits resolution;
  • Buffer size of 256 samples;
  • Fast fourier-transform;
  • Analog and external digital triggering;
  • Maximum input voltage of +/- 10V;
  • Automatic average and peak-to-peak measurements;
  • Logic analyser with eight channel maximum simultaneous monitoring;
  • Firmware is user upgradable;
  • Can also be used as a development board for the XMEGA microcontroller (extra items required);
  • When powered from a USB cable, the board can supply +/-5V and +3.3V into a solderless breadboard.

The OLED screen is very clear and precise, which considering the size of 0.96″ – very easy to read. One can also set the display mode to invert which changes the display to black on white, bringing back memories of the original Apple Macintosh:

Using the Xprotolab took a little getting used to, however after pressing menu buttons for a few minutes I had it worked out. The more sensible among you will no doubt read the instructions and menu map listed at the website. Having the dual voltmeter function is quite useful, it saved me having to mess about with a couple of multimeters when trying to debug some analogue circuits I’m currently working with.

The display can be as complex or as simple as you choose, for example when working with the oscilloscope you can disable one channel and shift the waveform so it occupies the centre of the screen. Or when working with the logic analyser, you can choose to only select the channels being monitored, instead of filling the screen with unused logic lines.

There are a couple of things to take care with. When inserting the Xprotolab into your breadboard, be careful not to put pressure on the OLED display when pushing down; when removing it from the breadboard, try and do so evenly with the help of an DIP IC puller.

Generally in my reviews there is a video clip of something happening. Unfortunately my camera just isn’t that good, so below is the demonstration clip from the manufacturer:

As you can see the Xprotolab would be quite useful for monitoring various signals whilst prototyping, as you can just drop it into a breadboard. Furthermore, if your required range is measurable the Xprotolab saves you having to look back-and-forth between a prototype and the display from a regular oscilloscope as well.

As the purchase price is relatively cheap (US $35 at time of review) compared against the time and effort of trying to make an OLED display board yourself, one could also plan to build an Xprotolab into a final design – considering a lot of measurement and display work is already done for you it could be a real time-saver. The Xprotolab can run from a 5V supply and only draws a maximum of 60 milliamps. Product support is quite extensive, including source code, schematics, videos, a user forum and more available from the product page.

In conclusion the Xprotolab is genuinely useful, inexpensive and ready to use out of the box. It would make a useful piece of test equipment for a beginner or seasoned professional, and also integrates well into custom projects when required.

Remember, if you have any questions about the Xprotolab,  please contact Gabotronics via their website.

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

Friday, February 11, 2011

Review – CD4047 Astable/Monostable Multivibrator

Hello readers!

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

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

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

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

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

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

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

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

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

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

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

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

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

Question What is the maximum supply voltage for a Fairchild CD4047B?

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

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

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

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

Once again, 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 new Google Group.

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

Sunday, February 6, 2011

Tutorial: Arduino and Colour LCD

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

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 start using a colour LCD with our Arduino for data display and other fun and games. (The monochrome LCD article is here).  Although there are many colour LCDs on the market, the first one we examine is relatively inexpensive and easy to mount and use - the Sparkfun "Color LCD Shield":

From a hardware perspective there isn't much to do - only solder in some header pins (which, again, are not included) to enable use with out Arduino boards. The quickest way to solder them in is to insert the pins into another Arduino board or shield, place the LCD shield on top, check the alignment, and solder away. The shield pins used are 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.

Hint - there is a huge database of shields and their details at http://shieldlist.org

From a software perspective, the first thing to do is download and install the library for the LCD shield. Download the library from here. Extract and copy the resulting folder into your ..\arduino-2x\libraries folder. At this point we have Peter Davenport to thank for this LCD shield design and Arduino library. Considering there are more parameters to consider as against using a monochrome LCD, there is nothing to worry about. 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:

#include "LCD_driver.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include "WProgram.h"
#include "HardwareSerial.h"

as well as the following in void setup():

ioinit();
LCDInit();
LCDContrast(45); // sets LCD contrast (value between 0~63)

The contrast parameter is subjective, however 45 looks good and will be used in the forthcoming demonstrations. We will examine each function with a small example, then use the LCD shield in more complex applications.

Example 28.1 - Text display

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

LCDPutStr("text", y,x, foreground colour, background colour);

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

LCDClear(colour);

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)

For example, to recreate the following display:

... use the following sketch:

/*  Example 28.1 - Colour LCD shield
tronixstuff.com/tutorials > chapter 28 CC by-sa */ // we need all these for the LCD
#include "LCD_driver.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include "WProgram.h"
#include "HardwareSerial.h"
void setup()
{
// following two required for LCD
ioinit();
LCDInit();
LCDContrast(45); // sets LCD contrast (value between 0~63)
}
void loop()
{
LCDClear(BLACK);
LCDPutStr("0123456789012345", 0,2, WHITE, BLACK);
LCDPutStr("0123456789012345", 13,2, WHITE, BLACK);
LCDPutStr("0123456789012345", 26,2, WHITE, BLACK);
LCDPutStr("0123456789012345", 39,2, WHITE, BLACK);
LCDPutStr("0123456789012345", 52,2, WHITE, BLACK);
LCDPutStr("0123456789012345", 65,2, WHITE, BLACK);
LCDPutStr("0123456789012345", 78,2, WHITE, BLACK);
LCDPutStr("0123456789012345", 91,2, WHITE, BLACK);
LCDPutStr("0123456789012345", 104,2, WHITE, BLACK);
delay(30000);
}

Question - how many pixels make up the LCD used in the shield discussed in this article?

In example 28.1 we used the function LCDClear();, 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 LCDClear() 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:

Example 28.2

/*  Example 28.2 - Colour LCD shield
tronixstuff.com/tutorials > chapter 28 CC by-sa */
#include "LCD_driver.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>\
#include "WProgram.h"
#include "HardwareSerial.h"
int del = 1000;
void setup()
{
ioinit();
LCDInit();
LCDContrast(45);
}
void loop()
{
LCDClear(WHITE);
LCDPutStr("White", 39,40, WHITE, BLACK);
delay(del);
LCDClear(BLACK);
LCDPutStr("Black", 39,40, WHITE, BLACK);
delay(del);
LCDClear(YELLOW);
LCDPutStr("Yellow", 39,40, WHITE, BLACK);  delay(del);
LCDClear(PINK);
LCDPutStr("Pink", 39,40, WHITE, BLACK);
delay(del);
LCDClear(MAGENTA);
LCDPutStr("Magenta", 39,40, WHITE, BLACK);
delay(del);
LCDClear(CYAN);
LCDPutStr("Cyan", 39,40, WHITE, BLACK);
delay(del);
LCDClear(BROWN);
LCDPutStr("Brown", 39,40, WHITE, BLACK);
delay(del);
LCDClear(ORANGE);
LCDPutStr("Orange", 39,40, WHITE, BLACK);
delay(del);
LCDClear(BLUE);
LCDPutStr("Blue", 39,40, WHITE, BLACK);
delay(del);
LCDClear(RED);
LCDPutStr("Red", 39,40, WHITE, BLACK);
delay(del);
LCDClear(GREEN);
LCDPutStr("Green", 39,40, WHITE, BLACK);
delay(del);
}

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

[Youtube=http://www.youtube.com/watch?v=C44M59CawvY]

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 160 by 160 pixels. We have four functions to make use of this LCD real estate, so let's see how they work. The first is:

LCDSetPixel(COLOUR, Y, X);

This functions places a pixel (one LCD dot) at location x, y of colour COLOUR. Next is:

LCDSetLine(x0, y0, x1, y1, COLOUR);

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

LCDSetRect(x0, y0, x1, y1, fill, COLOUR);

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:

LCDDrawCircle(x, y, radius, COLOUR, type);

 

X and Y is the location for the centre of the circle, radius and COLOUR are self-explanatory. However type presents some more options - FULLCIRCLE, OPENSOUTH, OPENNORTH, OPENEAST, OPENWEST, OPENNORTHEAST, OPENNORTHWEST, OPENSOUTHEAST, OPENSOUTHWEST. These parameters determine how much of the circle's circumference is drawn. FULLCIRCLE natuarlly generates a whole circle, OPENSOUTH generates the top-half of a circle, OPENNORTH generates the bottom half of a circle, and so on.

We will now use these graphical functions in the following demonstration sketch. For photographic reasons, I will stick with white on black for the colours. The sketch is quite long, so it can be downloaded from the following link - Example 28.3. And here is a short clip of the sketch in action:

[Youtube=http://www.youtube.com/watch?v=QiaxgYoRSpM]

That is all we have time for in this instalment. Now you have an explanation of the functions to drive the screen, only your imagination is holding you back. In a future instalment we will examine some another type of colour display - the OLED. Stay tuned for upcoming Arduino tutorials by subscribing to the blog, RSS feed (top-right), twitter 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!