Category: Arduino

Clock using 3.5 Digit Seven Segment Display and no extra hardware

Its been a while since I wrote anything here, but today’s post is how to run a common cathode multi digit seven segment display without extra shift regs or buffers.

I software multiplex the segments and use the INPUT_PULLUP mode of the digital pins to ensure only one digit is written to at a time.

I have actually used an RTC module for the time, but you don’t need one if you keep the power on and add a bit of setting logic :)

All the docs are in the code.

Nunchuck Controlled 3D cube on TV

This is pretty cool – I took the TVout library, the Wiichuck library and wrote a 3D library. Put them all together and got a nunchuck controlled 3D shape on TV. Movement in the nunchuck is detected by the arduino, then the cube is redrawn according to new angle of the controller.

At this point I ran out of memory but it wouldn’t be too hard to set up the shapes in FLASH instead of RAM. The hardware isn’t too complicated, just a few resistors and a pot for the speaker.

Driving a TV and speaker and reading a nunchuck
The circuit - just a few resistors

3d wireframe library header and source

Code to tie everything together

Analogue Clock on an 8×8 LED

OK so this is tiny but it implements the Bresenham line drawing algorithm and draws a clock…

The code is pretty simple.

Its running about 100x faster in this video so I can show how it works.

[[Schematic soon]]

Analogue Clock on an 8x8 LED
Analogue Clock on an 8x8 LED
Analogue Clock on an 8x8 LED
<object width=”425″ height=”344″><param name=”movie” value=”″></param><param name=”allowFullScreen” value=”true”></param><param name=”allowscriptaccess” value=”always”></param><embed src=”″ type=”application/x-shockwave-flash” allowscriptaccess=”always” allowfullscreen=”true” width=”425″ height=”344″></embed></object>

More POV

Got some POV code working….

Problem is sync – not synched at all, so you can see what it says but it has no idea when to start the sequence relative to the user waving it about.

We’ll investigate a switch with a weight on as a synch pulse soon.

Here’s some pictures of the board so far. The LEDs are mounted on some strip board and a length of old CAT5 connects it to a small shield board which plugs into the Arduino. The CAT5 supplies power and the three control lines for the shift reg.

A photo of LED wavy end bit and another of the whole lot

The bit you wave about
Both ends of the cable...

How the code works…

Its really simple… I wrote a C++ application to generate the alphabet. I’ll post that for download.

Then a message is simply an array containing a list of pointers to smaller letter arrays. Each letter array holds a length byte followed by the binary for the letters. Binary is nice because you can tell by looking whether its right.

So the code that really matters is:

int* iMsg[] = {H,E,L,L,O};
int iMsgLen = 5;

void loop()
  // send the next column for the current character

  // wait a moment

  // move to the next column

  // have we run out of columns for this letter?
  if (iCharIndex == iCharLen)
     // start at first column - 1 because 0 is length byte
     iCharIndex = 1;
     // and move to the next letter

  // now see if we have got to the end of the message
  if (iMsgIndex == iMsgLen)
     // start at first letter again
     iMsgIndex = 0;

  // set the length  - this could be in an if statement - but it really doesn't make much difference
  iCharLen = iMsg[iMsgIndex][0];


All the code is in the download area.

Doing the synch things seems like it will be fiddly. Might come back to that after a play with TV output.

Win32 .net application to generate Arduino font source code is her :  Adruino 8 bit font creator for POV

Thermometer and Clock

Schematic view - click for full sized version

So, for our first trick we thought we’d try and conjour up a thermometer, and then we added a clock as well – just for good measure.

Pretty much all the parts came from Cool Components or Maplin. I got a cheap 2 line display on sale which was the starting point, then wondered what we could create to educate…

The LCD interface is through 3 wires and a 4094 shift register. I’ve taken the example 3 wire LCD code from the arduino playground at and modified and extended it a little to provide some positioning functions and improve the number drawing code.

Schematic and Breadboard

The breadboard version


The thermometer functionality comes from TMP102 module which is connected through an I2C bus, implemented with the Wired library. The I2C interface is very easy to use, call


in setup() to initialise it, then its a simple case of reading the latest temperature values. The addressing here assumes that the ADD0 line on the module is pulled to ground:

// Temperature module commands and registers
int  TMP_RD = 0x91;
int  TMP_WR = 0x90; //Assume ADR0 is tied to VCC
int  TEMP_REG = 0x00;
int  TEMP_ADDR = 0b1001000;

int ReadTemperature()
 int  val_h = 0;
 int  val_l = 0;

 Wire.requestFrom(TEMP_ADDR, 2);
 val_h = Wire.receive();
 val_l = Wire.receive();

  //  calc temp in C
 int tempint = ((val_h << 8 ) | val_l) >> 4;      // combine and shift
 float tempflt = float( tempint ) * .0625; // calculate actual temperature per chip doc
 return int(tempflt);

The clock works by using the millis() function  to establish a base time and a corresponding millisecond count – then we can update the display anytime by calculating the time since a known base. If the millis() wraps we adjust the base to the last known good value and go from that. There will be a little bit of creep there but only once every 1193 hours ish…  Clock adjustment is through two switches which pull digital inputs to ground – if they are low we increment the base Hours or Minutes value depending which button is pressed. The internal pull up resistors are used to ensure the inputs don’t float about when the button isn’t pressed, here’s an extract:

// set up input
 digitalWrite(HOURS, HIGH);       // turn on pullup resistor

//Adjust the clock
 boolean    bRet = false;         // was an adjustment made
 if (digitalRead(HOURS) == LOW)   // read the input switch
   if (iBaseH > 23)
     iBaseH = 0;
   bRet = true;

After that all you need to do  is just get data for the temperature or the time and then call the display routines.

The code for the whole thing is here.