So this project came about because Wanita at ICStation was kind enough to send me some of their MAX7219 Dot Matrix Module Control Display DIY kits. These little 8×8 red LED matrix modules are super cute, and a steal at only $2.86 each!
I had 4 of the modules, so I took the code from my Pong Clock, stripped it down and created a mini clock. As well as the LED modules I used an Arduino to run code and a DS1307 clock module to keep time. If you want to make one yourself it’s not too hard – read on!
Mini LED Clock Features:
- Basic mode with large digits
- Slide mode where digits roll on and off screen
- Small digits with seconds mode
- Time written in words e.g. “Ten past Twelve”
- Date display
- 12/24 hour option
- Brightness option
- Random clock mode option that changes the display mode every few hours.
- Push button driven menus for setup & display selection.
- 4 x MAX7219 Dot Matrix Module Control Display DIY kits.
- 1 x Arduino Uno or Duemilanove with 32k RAM.
- 1 x DS1307 real time clock module.
- 1 x Arduino prototyping shield
- 1 x breadboard for testing (optional)
- 2 x Push to make buttons such as these.
- 1 x A to B type USB Lead
- 1 x Mains to USB power adapter
You’ll also need some tools:
- Fine tip soldering iron
- Liquid solder flux
- Wire cutters
- Magnifying glass – if you don’t like squinting at tiny components.
And the code itself:
Building the Matrix Kits
The kits use a red LED matrix which plugs into a PCB with onboard MAX controller chip. The chip takes all the hard work out of controlling the LEDs. You simply need a few wires to connect the module to an Arduino, then you can control it using software. The other cool thing is these matrix PCB’s clip together with plastic jumpers, so you can make displays as big as you like. The kits need to be soldered and uses surface mount components. I was a little nervous about building them at first – some of the resistors and capacitors were super tiny!
Surface mount soldering wasn’t as hard as I thought. There are some useful surface mount soldering videos which, whilst not the most exciting thing to watch, really helped me get the hang of it. The secret sauce to it all is liquid solder flux. This makes the solder bond to both the component and the circuit board.
Basically you wet the PCB metal pads with the flux, melt some solder on the iron, then whilst holding the component in place with your finger or tweezers, touch the iron to the joint and the solder flows onto it. It’s actually quite satisfying to do when you get the hang of it. I found using a breadboard was helpful to hold parts in place.
As for what components to solder where, you can work it out pretty easily from the ICStation website. One thing you need to be careful of is making sure you solder the pins that are used to connect different matrix modules together on at 90 degrees to the PCB. I did a few at a bit of an angle by mistake, and it meant the matrix modules didn’t clip together as well, so I had to go back and re do them.
Once each matrix was built, I tested it using the demo program available from the matrix product page on ICStation’s website. I’ve also put this program in the download with my clock code. It’s called “LEDDemoMatrix.pde” and can be found in the matrix_test/LCDemoMatrix folder. To use it, one matrix needs to be connected up as follows:
- Arduino Pin 10 to LOAD
- Arduino Pin 11 to CLK
- Arduino Pin 12 to DIN (Data In)
- Arduino 5v to 5v
- Arduino GND to GND
All being well your matrix should light up in various patterns to show it’s working.
So as I said the clever thing about these modules is that they join together using little jumper connectors, so you can chain them together in a line to make bigger displays. We need all four in a line for our clock, so join them as in the picture below. Make sure all the matrices are facing the same way, so that you connect the DOUT (data out) pin from one to the DIN (data in) pin on the next.
OK let’s take a look at the other bits we need for the clock.
The Arduino microprocessor runs the clock software, plus provides inputs and outputs that we connect the matrix modules, buttons and clock module to. Ensure you get an Arduino with 32k RAM such as the The Arduino Uno. Older Arduino’s with 16k won’t have enough room to store the clock code.
The DS1307 module
The DS1307 module contains a DS1307 chip that keeps time, along with a battery that runs the chip if the main power is disconnected. That way even if you unplug the clock, when you plug it back in the time will still be correct. It only needs 4 wires to work. 5v and GND for power, then SDA and SCL which are used to send clock data via the i2c protocol to the Arduino.
The prototyping board or ‘shield’ plugs into the Arduino making it easy to add other components. It brings the Arduino’s input and output pins onto a circuit board we can solder things to. We’ll use this to mount the DS1307 module, plus to connect the matrix display connections and buttons to.
I can’t really give you detailed instructions for what to solder where on the protoshield, as different boards have different layouts. However it should be pretty easy to figure out when you look at the list of all the pin connections needed further down. Make sure your shield comes with header pins so you can plug it into the Arduino (they’re not shown in the picture above). Some shields also come with additional bits – often a reset button as they mask the one on the Arduino, and sometimes extra LED’s for you to use.
You can use any push to make buttons. For example PCB mountable ones like below are good for soldering to the protoshield, or you could have some other type you connect via wires, say if you wanted to mount them in a case.
For the power supply I used a 500 milliamp USB adapter like this one with an A-B type USB cable into the Arduino’s USB port.
For testing I powered the clock with my Macbook, but be careful, if you have any shorts you could fry your computer’s USB ports!
Connecting it all up
Like I said, I can’t give you detailed instructions on what to solder where on the protoshield as they differ depending on what you buy, but below is a list of all the pins and what they need to connect to. Ideally try it out on a breadboard first to check it works, then move it to the protoshield.
Connecting the LED Matrix modules:
Once your 4 matrix modules are joined together in a line with the black jumper connectors as described earlier, look for the end one with the DIN (Data In) pin free. Connect the pins on that matrix as follows:
- Matrix LOAD to Arduino digital pin 10
- Matrix CLK to Arduino digital pin 11
- Matrix DIN to Arduino digital pin 12
- Matrix 5v to Arduino pin 5v
- Matrix GND to Arduino pin GND
Connecting the DS1307 module:
- SDA to Arduino analog pin 4
- SCL to Arduino analog pin 5
- 5v to Arduino pin 5v
- GND to Arduino pin GND
Connecting the Buttons:
- Button 1 goes between Arduino digital pin 2 and GND
- Button 2 goes between Arduino digital pin 3 and GND
My protoshield came with 2 LEDs and a reset button. I connected the green LED between 5v and GND to show power on. The red LED is connected between Arduino digital pin 13 an GND as the clock sketch flashes this to show it’s running. The reset button was already connected to the Arduino’s reset pins. You can also see the connections for the displays on the left (cable tied to the board), and the button connections top left.
Uploading the Clock Code
The last job is to upload the clock code to the Arduino. First you’ll need to download the Arduino programming software called the Arduino IDE. The current clock code was tested with IDE version 1.6.5. You can download the IDE from the Arduino site: http://arduino.cc/en/Main/Software
Once the IDE is installed download the Mini LED Clock code from my page on GitHub by clicking the “Download Zip” button bottom right. Unzip the file and inside you will see 3 folders:
- libraries – contains extra software code the clock needs to work
- matrix_test – this is the demo program ICStation provide to test the matrix kit is working as explained earlier.
- mini_clockx_x (where x is the version number) – this contains the main clock code.
Next job is to install the libraries. When you installed the Arduino software it should have created a folder somewhere for your sketches (projects) to go in. Inside that folder should be another folder called libraries. Open the libraries folder in the clock download and copy the 4 folders there into the libraries folder in your Arduino projects directory. The 4 libraries are called ‘Button’, ‘FontLEDClock’, ‘LedControl’ and ‘RTClib’.
Now quit and restart the Arduino IDE to make it pick up the new libraries. After restarting, go to the Sketch -> Import Library menu. If the libraries are in the right place you should see the 4 names listed in this menu.
If not, go back and check you have them in the right folder.
Now go to the File menu and open the main clock sketch – it’s in the mini_clock folder and is the file ending in .ino. You should see the code appear in the main window. Pick your Arduino board type in the Tools -> Board menu and hit the Verify (check mark) icon. This tests the code and should compete without errors. If you do get errors here, you’ve most likely not got the 4 libraries in the right place or you’re not using the correct version of the Arduino IDE software – make sure you are using 1.6.5 and not a newer version.
OK, time to upload the code to your Arduino. Plug the Arduino into your computer with the USB cable. Click upload and wait for the code to be uploaded. Watch the TX and RX LED’s on the Arduino flash for signs of data transfer. If you’ve got everything plugged in right the clock should spring to life. Now you can unplug it from your computer and use the USB power adapter. Use the buttons to set the time and then sit back and admire your handiwork.
And if you really, really like the project, here’s my bitcoin address! 1JPdDk4DiKYDsjTYghHatJp1FFQsv6bpEv
I get an error compiling:
- Check the libraries are installed in the correct folder and appear in the menu
- Make sure you have restarted the Arduino IDE after adding the libraries.
- Make sure you are using Arduino software version 1.6.5.
I get an error uploading to the Arduino:
- Check your board type and serial settings are correct in the Tools menu.
- Check your Arduino has 32K RAM or more.
The clock doesn’t change:
- Normally a wiring issue. Check the LED on Pin 13 of the Arduino flashes. If not then the clock chip is not being read. Check your connections to the DS1307.
- You must have a working battery on your DS1307 module for the clock to run.
The displays don’t light up / light up erratically.
- Check your wiring to the first matrix.
- Check all the jumper pins are pushed in on the other matrices.
- Try another power supply.
- Check each matrix with the Demo program as described earlier to make sure they are soldered correctly.
The text on the displays is rotated.
- This is most likely because you don’t have the exact matrix modules from IC Station. Other modules from eBay can be wired up differently, so the LED’s are in a different order. You can usually fix things by tinkering with the function “plot” in the code. Look for the comment “plot a point on the display” and the line starting “void plot”. Switch the x and y in the 2 lines that start ” lc.setLed(address, y, x, true ); and lc.setLed(address, y, x, false);”. This will plot the pixels 90 degrees around.
The text on the displays is garbled or out of order.
- This is most likely because you don’t have the exact matrix modules from IC Station. Other modules from eBay can be wired up differently, so the LED’s are in a different order. You can usually fix things by tinkering with the function “plot” in the code. Look for the comment “plot a point on the display” and the line starting “void plot”. If the text is our of order you can try changing the address=0 to address=3 lines around. These control which display is 0,1,2, and 3. If you swap the numbers around so they go from 3 to 0 this will invert everything. It’s worked for a few people!