Friday, March 30, 2012

Project: Clock Three – A pillow clock

Introduction

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 Arduino sketches used in this article are written for v23 and not v1.0. 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.3V 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 blinkLEDwhich 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. Thanks to Little Bird Electronics for the LilyPad items.

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.

Monday, March 19, 2012

RF Wireless Data with the Seeedstudio RFbee

Introduction

In this article we examine the Seeedstudio RFbee Wireless Data Transceiver nodes. An RFbee is a small wireless data transceiver that can be used as a wireless data bridge in pairs, as well as a node in mesh networking or data broadcasting. Here is an example of an RFbee:

You may have noticed that the RFbee looks similar to the Xbee-style data transceivers – and it is, in physical size and some pinouts, for example:

However this is where the similarity ends. The RFbee is in fact a small Arduino-compatible development board based on the Atmel ATmega168 microprocessor (3.3V at 8MHz – more on this later) and uses a Texas Instruments CC1101low-power sub1-GHz RF transceiver chip for wireless transfer. Turning over an RFbee reveals this and more:

But don’t let all this worry you, the RFbee is very simple to use once connected. As a transceiver the following specifications apply:

  • Data rate – 9600, 19200, 38400 or 115200bps
  • Adjustable transmission power in stages between -30dBm and 10 dBm
  • Operating frequency switchable between 868MHz and 915MHz
  • Data transmission can be point-to-point, or broadcast point-to-many
  • Maximum of 256 RFbees can operate in one mesh network
  • draws only 19.3mA whilst transmitting at full power

The pinout for the RFbee are similar to those of an Xbee for power and data, for example:

There is also the ICSP pins if you need to reprogram the ATmega168 direcly with an AVRISP-type programmer.

Getting Started

Getting started is simple – RFbees ship with firmware which allows them to simply send and receive data at 9600bps with full power. You are going to need two or more RFbees, as they can only communicate with their own kind.However any microcontroller with a UART can be used with RFbees – just connect 3.3V, GND, and the microcontroller’s UART TX and RX to the RFbee and you’re away. For our examples we will be using Arduino-compatible boards. If Arduino is new to you, consider our tutorials first.

If you ever need to update the firmware, or reset the RFbee to factory default after some wayward experimenting – download the firmware which is in the form of an Arduino sketch (RFBee_v1_1.pde) which can be downloaded from the repository. (This has been tested with Arduino v23). In the Arduino IDE, set the board type to “Arduino Pro or Pro Mini (3.3V, 8MHz) w/ATmega168″. From a hardware perspective, the easiest way to update the firmware is via a 3.3V FTDI cable or an UartSBee board, such as:

You will also find a USB interface useful for controlling your RFbee via a PC or configuration (see below). In order to do this,  you will need some basic terminal software. A favourite and simple example is called … “Terminal“. (Please donate to the author for their efforts).

Initial Testing

After connecting your RFbee to a PC, run your terminal software and set it for 9600 bps – 8 – None – no handshaking, and click the check box next to “+CR”. For example (click to enlarge):

Select your COM: port (or click “ReScan” to find it) and then “Connect”. After a moment “OK” should appear in the received text area. Now, get yourself an Arduino or compatible board of some sort that has the LED on D13 (or substitute your own) and upload the following sketch:

// RFbee demonstration sketch
int ledPin = 13; byte incoming=0;
void setup() { Serial.begin(9600); pinMode(ledPin, OUTPUT); }
void blinkLED(int i) { for (int a=0; a
void loop() { if (Serial.available() > 0) { incoming = Serial.read(); switch(incoming) { case 'A': blinkLED(1); break; case 'B': blinkLED(2); break; case 'C': blinkLED(3); break; default: blinkLED(5); } Serial.println("Blinking completed!"); delay(2000); Serial.flush(); } }

Finally, connect the Arduino board to an RFbee in this manner:

  • Arduino D0 to RFbee TX
  • Arduino D1 to RFbee RX
  • Arduino 3.3V to RFbee Vcc
  • Arduino GND to RFbee GND
and the other RFbee to your PC and check it is connected using the terminal software described earlier. Now check the terminal is communicating with the PC-end RFbee, and then send the character ‘A’, ‘B’ or ‘C’. Note that the LED on the Arduino board will blink one, two or three times respectively – or five times if another character is received. It then reports back “Blinking completed!” to the host PC. For example (click to enlarge):

Although that was a very simple demonstration, in doing so you can prove that your RFbees are working and can send and receive serial data. If you need more than basic data transmission, it would be wise to get a pair of RFbees to experiment with before committing to a project, to ensure you are confident they will solve your problem.

More Control

 If you are looking to use your RFbees in a more detailed way than just sending data at 9600 bps at full power, you will need to  control and alter the parameters of your RFbees using the terminal software and simple AT-style commands. If you have not already done so, download and review the RFbee data sheet downloadable from the “Resources” section of this page. You can use the AT commands to easily change the data speed, power output (to reduce current draw), change the frequency, set transmission mode (one way or transceive) and more.

Reading and writing AT commands is simple, however at first you need to switch the RFbee into ‘command mode’ by sending +++ to it. (When sending +++ or AT commands, each must be followed with a carriage return (ASCII 13)). Then you can send commands or read parameter status. To send a command, just send AT then the command then the parameter. For example, to set the data rate (page ten of the data sheet) to 115200 bps, send ATBD3 and the RFbee will respond with OK.

You can again use the terminal software to easily send and receive the commands. To switch the RFbee from command mode back to normal data mode, use ATO0 (that’s AT then the letter O then zero) or power-cycle the RFbee.

RFbee as an Arduino-compatible board with inbuilt wireless

 As mentioned previously the RFbee is based around an Atmel ATmega168 running at 8MHz with the Arduino bootloader. In other words, we have a tiny Arduino-compatible board in there to do our bidding. If you are unfamiliar with the Arduino system please see the tutorials listed here. However there are a couple of limitations to note – you will need an external USB-serial interface (as noted in Getting Started above), and not all the standard Arduino-type pins are available. Please review page four of the data sheet to see which RFbee pins match up to which Arduino pins.

If for some reason you just want to use your RFbee as an Arduino-compatible board, you can do so. However if you upload your own sketch you will lose the wireless capability. To restore your RFbee follow the instructions in Getting Started above.

The firmware that allows data transmission is also an Arduino sketch. So if you need to include RF operation in your sketch, first use a copy of the RFBee_v1_1.pde included in the repository – with all the included files. Then save this somewhere else under a different name, then work your code into the main sketch. To save you the effort you candownload a fresh set of files which are used for our demonstration. But before moving forward, we need to learn about controlling data flow and device addresses…

Controlling data flow

As mentioned previously, each RFbee can have it’s own numerical address which falls between zero and 255. Giving each RFbee an address allows you to select which RFbee to exchange data with when there is more than two in the area. This is ideal for remote control and sensing applications, or to create a group of autonomous robots that can poll each other for status and so on.

To enable this method of communication in a simple form several things need to be done. First, you set the address of each RFbee with the AT command ATMAx (x=address). Then set each RFbee with ATOF2. This causes data transmitted to be formatted in a certain method – you send a byte which is the address of the transmitting RFbee, then another byte which is the address of the intended receipient RFbee, then follow with the data to send. Finally send command ATAC2 – which enables address checking between RFbees. Data is then sent using the command

transmitData(*byte data, byte length, byte sourceAddress, byte destinationAddress)

Where data is … the data to send. You can send a single byte, or an array of bytes. length is the number of bytes you are sending. sourceAddress and destinationAddress are relevant to the RFbees being used – you set these addresses using the ATMAx described earlier in this section.

If you open the file rfbeewireless.pde in the download bundle, scroll to the end of the sketch which contains the following code:

byte testData[4] = {'A','B','C','D'};
void sendTestData() { // send the four bytes of data in the byte testData[] from address 1 to address 2 transmitData(testData,4,1,2); delay(1000); }

This is a simple example of sending data out from the RFbee. The RFbee with this sketch (address 1) sends the array of bytes (testdata[]) to another RFbee with address 2.  You can disable address checking by a receiving RFbee with ATAC0 – then it will receive any data send by other RFbees.

To receive data use the following function:

result=receiveData(rxData, &len, &sourceAddress, &destinationAddress, (byte *)&rssi , &lqi);

The variable result will hold the incoming data, len is the number of bytes to expect, sourceAddress and destinationAddress are the source (transmitting RFbee) and destination addresses (receiving RFbee). rssi and lqi are the signal strength and link quality indicator – see the TI CC1101 datasheet for more information about these. By using more than two RFbees set with addresses you can selectively send and receive data between devices or control them remotely. Finally, please note that RFbees are still capable of sending and receiving data via the TX/RX pins as long as the sketch is not executing the sendTestData() loop.

I hope you found this introduction interesting and useful. The RFbees are an inexpensive and useful alternative to the popular Xbee modules and with the addition of the Arduino-compatible board certainly useful for portable devices, remote sensor applications or other data-gathering exercises.

For more information and product support, visit the Seeedstudio product pages.

RFbees are available from Seeedstudio and their network of distributors.

Disclaimer - RFbee products used in this article are promotional considerations made available by Seeedstudio.

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.

Sunday, March 18, 2012

Simone – The Numerical Memory Game

Introduction

After spending some time with the TM1638 LED display modules, the thoughts wandered to what sort of games they could be used with. The numbers and buttons merged into the thought of a number memory game – similar in theory of the popular “Simon” game by Milton Bradley:

Now back to the future. Instead of having four colours to blink in a certain sequence, our “Simone” game will randomly choose eight digits from one to eight. Then it (she?) will blink them across the module from left to right. At first the game starts with one digit, then two, all the way to eight. After the numbers have been displayed the user needs to key in the matching sequence of digits using the eight buttons below the display.

The purpose of this game is to simply test the user’s short term memory. When the game first starts the user is prompted to select a level, from one being the easiest to eight the most difficult. The greater the level, the less amount of time between the display of the digits to remember. This sounds odd but wait until the video at the end of this article for a demonstration.

Hardware

All you need is a regular Arduino or compatible board of some sort, the TM1638 display module, and if you like beeps a piezo buzzer. I have mounted the buzzer and a header for the display on a protoshield, with the buzzer connected to digital eleven:

Software

The Arduino sketch was written in v23 and is as follows (download):

// simple numerical memory game using TM1638 LED display and Arduino style board // John Boxall CC by-sa-nc tronixstuff.com/projects | March 2012
#include <TM1638.h> // See http://code.google.com/p/tm1638-library/ // define a TM1638 module on data pin 8, clock pin 7 and strobe pin 6 TM1638 module(8, 7, 6);
byte buttons; int level;
void setup() { pinMode(11, OUTPUT); // for piezo buzzer randomSeed(analogRead(0)); // for random number generator preGame(); }
void preGame() { // say Hello and get the level the user wants to play // the level is the number of milliseconds between displaying each number to remember module.setDisplayToString(" HELLO ", 1); for (int z=1; z<5; z++) { piezoBeep(z); } module.setDisplayToString(" LEVEL? ", 0); do // wait for user to select level { buttons=module.getButtons(); } while (buttons==0); switch(buttons) { case 1: level=1000; break; case 2: level=900; break; case 4: level=800; break; case 8: level=700; break; case 16: level=600; break; case 32: level=500; break; case 64: level=400; break; case 128: level=300; break; } module.clearDisplay(); }
void piezoBeep(int type) // used to make beeps { long duration=250000; int freq; switch(type) { case 1: freq = 600; break; case 2: freq = 700; break; case 3: freq = 800; break; case 4: freq = 900; break; case 5: freq = 1000; break; case 6: freq = 1100; break; case 7: freq = 1200; break; case 8: freq = 1300; break; } int period = (1.0 / freq) * 1000000; long elapsed_time = 0; while (elapsed_time < duration) { digitalWrite(11,HIGH); delayMicroseconds(period / 2); digitalWrite(11, LOW); delayMicroseconds(period / 2); elapsed_time += (period); } }
void playGame() { int gameNumbers[9]; // stores numbers to remember int userNumbers[9]; // stores users' presses int count=1; // tracks number of digits per round int z; // for various loops etc. boolean correct=true; delay(1000);  do { for (int z=1; z<9; z++) // get random numbers for game { gameNumbers[z]=random(1,9); } // display numbers to remember for (int i=1; i<=count; i++) { module.setDisplayDigit(gameNumbers[i],(i-1), false); piezoBeep(gameNumbers[i]); delay(level); module.clearDisplay(); } // get user attempts for (z=1; z<=count; z++) { do // wait for user to press button { buttons=module.getButtons(); } while (buttons==0); delay(300); // for debounce switch(buttons) { case 1: userNumbers[z]=1; break; case 2: userNumbers[z]=2; break; case 4: userNumbers[z]=3; break; case 8: userNumbers[z]=4; break; case 16: userNumbers[z]=5; break; case 32: userNumbers[z]=6; break; case 64: userNumbers[z]=7; break; case 128: userNumbers[z]=8; break; } module.setDisplayDigit(userNumbers[z],(z-1), false); delay(200); module.clearDisplay(); } // check for incorrect entries for (int z=1; z<=count; z++) { if (userNumbers[z]!=gameNumbers[z]) { correct=false; } } count++; } while ((correct==true) && (count<9)); delay(1000); if (correct==true) { module.setDisplayToString("YOU WIN ", 0); } if (correct==false) { module.setDisplayToString("YOU LOSE", 0); } delay(1000); module.setDisplayToString("GO AGAIN", 0); delay(1000); module.clearDisplay(); }
void loop() { playGame(); delay(1000); }

The sketch isn’t anything special, and gives the user the framework for perhaps something more involved or customised. Or at least a good distraction from doing some real work. *ahem* However here it is in action:

Conclusion

Although the “Simone” game was quite simple, and a quick knock-up job – I’m sure those of you with more imagination could have some fun with the sketch and so on. It is easy to follow and another interesting use of thedisplay modules – the best $10 I’ve spent for some time.

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.

Saturday, March 10, 2012

Arduino and TM1638 LED Display Modules

Introduction

The purpose of this article is to demonstrate the use of some interesting LED display modules I discovered on the dealextreme website, for example:

They contain eight 7-segment red LED digits, eight red/green LEDs and also eight buttons for user input. The units can also be daisy-chained, allowing up to five at once, and a short cable is included with each module, as well as some short spacers and bolts, such as:

The spaces are just long enough to raise the PCB above a surface, however to mount the boards anywhere useful you would need longer ones. You may also want to remove the IDC sockets if you want to mount the module close to the surface of a panel. This would be a simple desoldering task as they are through-hole sockets:

The board is controlled by a TM1638 IC:

This part seems to be a domestic Chinese product from “Titan Micro Electronics“. After a quick search the TM1638 isn’t available from Digikey, Mouser or the element14 group… so if anyone has a lead on a low-volume, reliable supplier for these – please leave a comment below.

Getting Started

Now to make things happen. Hardware – Connection to an Arduino-compatible board (or other MCU) is quite simple. The pinouts are shown on the rear of the PCB, and match the fitting on the ribbon cable. If you look at the end of the cable as such:

The top-right hole is pin one, with the top-left being pin two, the bottom-right pin nine and bottom-left pin ten. Therefore the pinouts are:

  1. Vcc (5V)
  2. GND
  3. CLK
  4. DIO
  5. STB1
  6. STB2
  7. STB3
  8. STB4
  9. STB5
  10. not connected

For Arduino use, pins 1~4 are the minimum necessary to use one module. Each additional module will require another digital pin connected to STB2, STB3, etc. More on this later. Please note that each module set to full brightness with every LED on consumes 127mA, so it would be wise to use external power with more than one module and other connections with Arduino boards. Software –  download and install the T1638 library from here. Thanks and kudos to rjbatista at gmail dot com for the library.

Initialising modules in the sketch is simple. Include the library with:

#include <TM1638.h>

then use one of the following for each module:

TM1638 module(x, y, z);

x is  the Arduino digital pin connected to the module cable pin 4, y is the Arduino digital pin connected to the module cable pin 3, and z is the strobe pin. So if you had one module with data, clock and strobe connected to pins 8, 7,  and 6 you would use:

TM1638 module(8, 7, 6);

If you had two modules, with module one’s strobe connected to Arduino digital 6, and module two’s strobe connected to digital 5, you would use:

 TM1638 module(8, 7, 6);
TM1638 module(8, 7, 5);

and so on for more modules.  Now to control the display…

The bi-colour LEDs

 Controlling the red/green LEDs is easy. For reference they are numbered zero to seven from left to right. To turn on or off a single LED, use the following:

  module.setLED(TM1638_COLOR_RED, x);  // set LED number x to red   module.setLED(TM1638_COLOR_GREEN, x); // set LED number x to green   module.setLED(TM1638_COLOR_RED+TM1638_COLOR_GREEN, 0); // set LED number x to red and green

Using the method above may be simple it is somewhat inefficient. A better way is to address all of the LEDs in one statement. To do this we send two bytes of data in hexadecimal to the display. The MSB (most significant byte) consists of eight bits, each representing one green LED being on (1) or off (0). The LSB (least significant byte) represents the red LEDs.

An easy way to determine the hexadecimal value to control the LEDs is simple, image you have one row of LEDs – the first eight being green and the second eight being red.  Set each digit to 1 for on and 0 for off. The convert the two binary numbers to hexadecimal and use this function:

module.setLEDs(0xgreenred);

Where green is the hexadecimal number for the green LEDs and red is the hexadecimal number for the red LEDs. For example, to turn on the first three LEDs as red, and the last three as green, the binary representation will be:

00000111 11100000 which in hexadecimal is E007. So we would use:

module.setLEDs(0xE007);

which produces the following:

The 7-segment display

To clear the numeric display (but not the LEDs below), simply use:

module.clearDisplay();

or to turn on every segment AND all the LEDs, use the following

module.setupDisplay(true, 7); // where 7 is intensity (from 0~7)

To display decimal numbers, use the function:

module.setDisplayToDecNumber(a,b,false);

where a is the integer, b is the position for the decimal point (0 for none, 1 for digit 8, 2, for digit 7, 4 for digit 6, 8 for digit 4, etc), and the last parameter (true/false) turns on or off leading zeros. The following sketch demonstrates the use of this function:

#include <TM1638.h>
// define a module on data pin 8, clock pin 9 and strobe pin 7 TM1638 module(8, 9, 7);
unsigned long a=1;
void setup(){}
void loop() { for (a=10000; a<11000; a++) { module.setDisplayToDecNumber(a,4,false); delay(1); } for (a=10000; a<11000; a++) { module.setDisplayToDecNumber(a,0,true); delay(1); } }

and the results:

One of the most interesting features is the ability to scroll text across one or more displays. To do so doesn’t really need an explanation as the included demonstration sketch:

tm_1638_scrolling_modules_example.pde

included with the TM1638 library is easily followed. Just insert your text in the const char string[], ensure that the module(s) are wired according to the module definition at the start of the sketch and you’re set. To see the available characters, visit the function page. Note that the display is only seven-segments, so some characters may not look perfect, but in context will give you a good idea – for example:

Finally, you can also individually address each segment of each digit. Consider the contents of this array:

byte values[] = { 1, 2, 4, 8, 16, 32, 64, 128 };

each element represents digits 1~8. The value of each element determines which segment of the digit turns on. For segments a~f, dp the values are 1,2,4,6,16,32,64,128. So the results of using the array above in the following function:

module.setDisplay(values);

will be:

Naturally you can combine values for each digit to create your own characters, symbols, etcetera. For example, using the following values:

byte values[] = { 99,99,99,99,99,99,99,99 };

we created:

The buttons

The values of the buttons are returned as a byte value from the function:

module.getButtons();

As there are eight buttons, each one represents one bit of a binary number that is returned as a byte. The button on the left returns decimal one, and the right returns 128. It can also return simultaneous presses, so pressing buttons one and eight returns 129. Consider the following sketch, which returns the values of the button presses in decimal form, then displays the value:

#include <TM1638.h>
// define a module on data pin 8, clock pin 9 and strobe pin 7 TM1638 module(8, 9, 7);
byte buttons;
void setup(){}
void loop() { buttons=module.getButtons(); module.setDisplayToDecNumber(buttons,0,false); }

and the results:

These display boards were a random, successful find. When ordering from dealextreme, do so knowing that your order may take several weeks to arrive as they are not the fastest of online retailers; and your order may be coming from mainland China which can slow things down somewhat. Otherwise the modules work well and considering the minimal I/O and code requirements, are a very good deal.

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.

Friday, March 2, 2012

Results – February 2012 Competition

Now that February is over it’s time to announce the lucky winners of our February competition…

Prize One is a brand new Freetronics EtherMega board – the mother of all Arduino-compatible boards. Asreviewed recently, the EtherMega combines the power and versatility of the Arduino Mega2560, a microSD card shield, a full Ethernet shield and power over Ethernet support:

Winner of the first prize is Rosemary H from the United Kingdom.

Prize Two is awesome – and a mystery no more. It is the new Freetronics LeoStick:

From the Freetronics website:

The LeoStick is just like the upcoming Arduino Leonardo, but given the “honey, I shrunk the kids” treatment!
Just pop it into your USB port (no cable required!) and upload straight from the Arduino IDE. We’ve even included on-board RGB LED lights and a speaker in this handy sized board. All the usual Arduino pins are present and each LeoStick comes with low profile header sockets for plugging in modules, shields and wires.

Winner of the second prize is Andrian from Moldova. Congratulations to the winners and thanks to everyone for entering.

For the curious, the questions and answers were:

  1. What frequency crystal would you use with the DS1307 RTC? – 32.768kHz
  2. How many LEDs are on an EtherMega board? Now I have two answers as the question should have been more specific. There are ten LEDs on the actual PCB, plus two more on the ethernet socket. So we accepted ten or twelve for the answer
  3. What are the dimensions (length x width) of an 0805 SMT component in mm? – 2.0 x 1.3 mm
  4. In what year was Ikea founded? – 1943
  5. What nationality is the Hakko company? Japanese
  6. Who came up with the name for the device known as the ‘transistor‘? - John R. Pierce
This month we have collated the entries and discovered the following:
  • 3.5% of entries were from females (up on last month)
  • The most entries were received equally from Australia and the US. Then the next five were the UK, unknown (no address offered), Germany, Poland, and Greece
  • First time entries this month from Moldova, Guam, Pakistan, and Malaysia.
  • Five ‘begging’ entries from the US. Ugh.
Finally, thank you for your competition entries – I really appreciate it. So in that spirit we will have another competition in March – so stay tuned using one of the methods below.

Once again, thanks to Freetronics for the EtherMega and LeoStick prizes!

In the meanwhile, 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.