DIY Digital Clock: Take 2!

What time is it?

Time to make a new clock!

About a year ago, I designed and assembled my own custom made clock. You couldn’t say it was in an enclosure since its guts were spilled out on both sides of a piece of foam core. I felt like, a year later, it was time to redo it and put it into a proper enclosure.

So, what time is it? Time to build us a new clock!

The Guts


I tend to get carried away and too focused to take proper progress pictures. This is literally the first picture I have from the electronics part.

Soldering all of those LEDs and components took a full day. I used hot glue to try to keep multiple wires in place to solder as fast as I could but it didn’t do the best job to hold them in. At time, the glue would fall away from the PCB. Still, it’s better than fiddling with one wire at a time.

The only difference from the prototype build is a lower resistor value for the LED resistors.

Putting Together a Box


Foam core is a favorite in my “lab”. It’s all I use these days because all it takes is a knife to cut and it’s inexpensive and accessible (Dollarama rocks). I built a simple black box with a white cover place. I was hoping with a lower resistor value on the LEDs, they’d be able to shine through the white foam core.


With the soldered parts and the enclosure ready, it was time to put it all together.


I glued a piece of foam core behind the control board to isolate the connections on the back with the display connections. I ended up mounting the two display panels on it’s own piece of foam core anyway so I guess that wasn’t really necessary. The display foam core backing fits tight with no need for pin or glues to hold it in place.


The white foam core was still too think for the LEDs so I ended up going back to a plain white sheet of paper. It’s not noticeably brighter than the original prototype with the paper.  The piece of paper is held up by two strips of foam core on either side.

I didn’t like the look of it at this point but it was the end of the weekend so I left it for now.


I still like how sleek the black foam core looks, even with a few imperfections here and there from a not-so-sharp knife.


After a few days to think about it, I realized simply turning around my diffusing screen pulled the look together.


Time to pull the plug on the prototype and enjoy something new.

Thanks for reading!

Clock Project Journal Entry #2: Get on with it

In the first journal entry for my clock project, I introduced the purpose and general idea of the project. It’s simple, but it’s been dragging on for weeks. The schematics and PCB designs have been tweaked many times since the first draft. I’ve been hesitant to call them complete because of my unfamiliarity with the DS3231 real-time clock, and because it’s my first time making my own component parts in Eagle. After some focused work today, I’ve sent the boards off to be made.

There are a couple of aesthetic aspects to these PCBs that are new for me: Larger size and different color. Both the control board and display board are larger than the 5x5cm (or less) size that I was always aiming for before. The larger boards give me a lot more room to play with when I’m routing the connections. It also lets me breathe a little easier knowing that the text sizes should be large enough to read… I’ve have cases where I made text too small just because I didn’t have space for anything larger. The boards will have black soldermask because I think it will make the LEDs stand out more and will hide the control board a little better. I’ve always gone with blue before.


As I mentioned earlier, this will be my first PCB with custom made parts designed in Eagle. The two parts that I made were for the power switch and the DS3231SN IC. The power switch is a tiny slide switch that I ordered a bunch of a while back. They’ve always been hard to use because of their somewhat odd form factor. The pins are tiny, it has two thick outer support pins, and has a 2mm pitch so it isn’t breadboard-able. I ordered digital calipers just to measure the switch’s pin thickness. Hopefully I got it right. If it turns out to be fine, I’ll probably make another PCB order for some breakouts for these switches.

The DS3231SN’s datasheet links to another document for its land pattern, which shows the spacing and sizes of the pads. The land pattern is clear so I’m confident that I made the part right in Eagle. Time will tell!

Since Eagle limits board sizes and the price for anything larger than 10x10cm would probably be too expensive anyway, I could only fit two digits on a board for the clock’s display. Each segment is made up of two parallel branches with a resistor and two LEDs in series. The resistor I plan to use are 1K 0805 surface-mount resistors. I tested them out in this configuration on a breadboard, thanks to my own 0805 breakouts. I chose the relatively high value of 1K because the brightness seemed to be just right, although it could still feel too bright when the entire display is put together. Time will tell on that as well.

I’m still trying to decide how I will put the two panels together. I want to have the colon in the middle of them, whether it’s made of LEDs or not doesn’t matter to me. I also don’t have much of a plan for an AM/PM indicator so the project may start off as a 24-hour formatted clock and be changed to a 12-hour clock in the future.

As you can tell, I’m still trying to get things sorted out even after the project milestone of getting the boards made being surpassed. I ordered the components for this project a couple of weeks ago from China so I hope they arrive soon. There are also a few components I’ll purchase locally when the other things start to come in.

Thanks for reading!

Clock Project Journal Entry #1: What is it, and what’s the point?

One of the things my desk is missing is a clock. Yes, I have a computer, watch, and phone that can all tell time, but when I’m in a full-screen game, I don’t want to have to go looking for the time. I’d rather have a clock large enough that I can simply glance at. First world problems, I know, but in any case, I thought that this would make for an interesting electronics project, despite how simple it may sound.

I will be making two custom circuit boards for this project. One will be the control board and the other will be the actual LED clock display. The project will be controlled by at Atmega328p microcontroller and the time will be kept by the DS3231 real-time clock chip. The LEDs will be driven with the help of some 74HC595 shift registers since it should make programming easier as opposed to multiplexing… I always gravitate toward using shift registers, I guess.

One of the things I wanted to make sure of was the LED configuration. As it sits now, each segment will have 4 red LEDs. At first, I tried driving them at their “full” 20mA each (so 80mA per segment) but I felt that it was too bright. Bumping up the current-limiting resistor brought it to a more comfortable brightness. With the higher resistor, the current drawn for the segment was about 4mA, which is low enough for a pin on the shift register to handle directly. With that, I don’t need any transistors, which makes me happy…

I was planning to use a single resistor for the four LEDs on each segment, but it’s bad form and I don’t want to go that route for the whole project. I already feel “guilty” about using shift registers instead of just multiplexing. I will be putting a resistor for each LED. The main reason why I wanted to go with the one resistor per four LEDs is because it saves space without having to go with surface-mount components. I’ll see how the layout goes with the 1/4 watt resistors and hope that I don’t have to go and get some surface-mount resistors. I’d like to use whatever I already have.
ds3231rtc_sch_1Here’s the schematic for the control board. The board layout is done, or at least the first draft of it is. The only thing left to add is a switch to either cut the power to the project or at least turn of the display. I haven’t decided yet. I’m planning on using some mini-slide switches I bought a long time ago but I need to create an Eagle part for it which may take a little time. I’m waiting on some digital calipers from Amazon so that I can measure the pin thickness.

The layout for the display is coming along slowly. There’s only enough space for two digits per board, which is not a bad thing since I could use them for other projects. The problem that does arise from not making them specific for the project is that I have to make a separate circuit board for the colon and AM/PM indicator (I don’t really want a 24-hour formatted clock).

That’s all I have to share for now. I’ll be back with more when more details get finalized. Stay tuned!

PS. I started working on this project about a week or so before Ahmed Mohamed’s clock incident happened. I found that to be a funny coincidence.

No Arduino Uno. No Arduino IDE.

Ditching the Arduino IDE

Some time ago, I started playing around with the Atmega328p microcontroller without the Arduino Uno board. Now it’s time to try doing the same on the software side, even as just an experiment. I’ve been getting started with AtmelStudio which allows you to program Atmel microcontrollers in C. I’m still not quite clear on what to call the Arduino programming language other than C, if not a simpler form of C because the Arduino language takes care of a lot of things for you to make it as easy as it is to program an Arduino.

I learned about microcontroller programming in college. I believe we used a PIC microcontroller for the labs so, while I recognize certain things, there seems to be a little variation in abbreviations. In the labs, the microcontrollers were part of a board my professor designed that had a bunch of peripherals like buttons, switches, LEDs, and an LCD. It was a very thorough course with loads of information to take in. I hope I can remember it all!

Anyways, I’d really like to continue playing around with it and see if I can make a full project with one of my Atmega328p boards programmed using AtmelStudio. I’m taking baby steps to get up to a good speed in AtmelStudio, and I hope that writing small tutorials on the blog will help me firm up my knowledge. If you spot anything that needs correcting, please leave a comment!

The rest of this post will introduce you to the little work I’ve done so far, and may be helpful for anyone else who may be interested in trying it out too.

Hello World!

I made two Hello World programs, with the help of a bunch of guides which I will link to throughout the rest of this post. Both programs blink a bunch of LEDs but using different methods. One uses a delay, while the other uses an interrupt routine.

USBtinyISP with AtmelStudio

AtmelStudio does not work right away with the USBtinyISP, which is what I used to program the Atmega328p. You must add it as an external tool. I followed this guide to add it to AtmelStudio. You’ll need to download WinAVR to complete the guide.

As the guide says, to upload code with the USBtinyISP, you must go to Tools>USBtinyISP (or whatever you named it). Just remember to build your code first before uploading it.


Using a Delay (and Beginner’s Introduction)

As I mentioned, I made two programs that blink LEDs. One uses a delay while the other uses a timer interrupt. Let’s first take a look at the delay version.

Screenshot (3)

The first line defines the clock speed, which is 16MHz. The next line includes io.h header file, which actually just includes the appropriate file for the project’s microcontroller (which you select when you create the project, in this case the Atmega328p) that contains definitions for register addresses and things like that. The third line includes delay.h header file which enables us to use _delay_ms(); to cause the delay.

Now, into the main program! But first, let’s talk about ports.


This is the pinout of the Atmega328p-pu. Some of the pins are labelled PBx, PCx, and PDx, where x is a number. These stand for PORTB, PORTC, and PORTD, which are 8-bit data registers where each bit is a pin. The pins on the uC aren’t exactly laid out as cleanly as an Arduino Uno when looking up and down the rows of pins, but you can always order them in a way that works best for you when you’re actually wiring up your project.

Anyways, back to the code. In the first two lines of code in our main function, we set all of the pins in PORTB and PORT D to outputs. This is equivalent to the pinMode() function of the Arduino which is used to set certain pins as inputs or outputs. DDR stands for Data Direction Register where setting a bit/pin in the DDR to 1 makes it an output and setting it to 0 makes it an input. To make things easier, I put it in hexadecimal format (“0xFF”). You could also write “0b11111111” which is the binary equivalent and is more helpful when pins in a port are a mix of inputs and outputs. The third line in the main function sets all of the bits in PORTD to 1.

Everything in them main function up to this point is like the setup() function in the Arduino IDE. This code only runs once when the uC is powered on. Everything in the while loop will loop forever, like loop() in the Arduino IDE.

We set all of the bits in PORTD to 1 earlier so that we can toggle all of the bits on PORTB and PORTD at the same time and they will alternate. If we didn’t set them before we started the loop, all the bits in both ports would be the same. In another case, we could put in some logic that would toggle or set all of the bits in PORTD to 1 on the first loop, but that’s unnecessary since we could do it this way.

The exclusive OR (abbreviated as XOR, symbolized as ^) operation can be used to toggle bits high and low whenever the line is executed. In this code, the bits in PORTB and PORTD are toggled, and then there is a delay set for 250ms on the last line of the while loop. It loops around and toggles all of the bits again, and so on.

Using an Interrupt

A lot of the core stuff was covered in the previous code section so I’m not going to go into as much detail for any repeating lines in this section. Also, I’m rusty when it comes interrupts especially so don’t quote me on anything. Check out this and this for the information that I used to help me get this working. Also see the Atmega328p datasheet.

This program sets up Timer1 interrupt so that the ISR, or Interrupt Service Routine, will execute every 250ms. Let’s go line by line where we initialize Timer1.

cli(); disables interrupts. This is used so that important code that shouldn’t be interrupted isn’t.

The next two lines set all of the bits in the TCCR1A and TCCR1B, or Timer/Counter Control Registers for Timer1, to 0.

See the large comment block for information on calculating the Output Compare Register (OCR1A) (“Compare Match Register” in the comment block).

The next line enables the Clear Timer on Compare Match mode, which clears the timer once a match is made.

The next two lines are to set the prescaler to 1024, which is a value that was used to calculate the value for the Output Compare Register. The following table, found in the Atmega328p datasheet, shows how to set the bits in the TCCR1B register to set the prescaler.

Screenshot (6)

The next line enables the Output Compare A Match interrupt.

The last line enables interrupts.

There’s nothing in the while loop since all of our code is in the interrupt routine.

The bottom of the code is the Interrupt Service Routine (ISR) which is the code that runs when there is an output compare match with Timer1. In the ISR, we toggle the bits on PORTB and PORTD like we did in the other Hello World example. The ISR code is run every time there is an output compare match, which is set to 250ms.

So, uh, that’s it.

Trying to write this post was difficult. I need some more reading up and experimenting to do. I hope you got something out of this, at least a link to somewhere that’s more helpful.

Thanks for reading!


A look at a cheap USBtinyISP board

On my most recent revisions of my breakout boards for the Atmega328p and Attiny85, I added a 6-pin ISP header. ISP stands for In System Programming, which, as the name suggests, means that the header is used to program the microcontroller as it sits in a circuit, which is especially handy for boards without a way to plug directly into your computer’s USB port or a board with a surface-mount microcontroller.

I’ve never actually used these headers since I was used to using my Arduino Uno to program the microcontroller for both of my breakout boards. To make sure I could add the 6-pin ISP header to the boards correctly, I read up on it from different sources to understand how to make the connections.


On the pinout of the microcontrollers, there are pins labelled SCK, MISO, and MOSI. These are three of the six pins of the 6-pin ISP header. The other three pins on the header are pins we all know well: Reset, Vcc, and Ground. The asterisk on my boards signify the first pin of the ISP header, which should be the MISO pin. The illustration of mine uses the pinout image in the Attiny datasheet where the six pins are underlined. I also drew up a simple diagram of the header pinout.

I received a cheap USBtinyISP board from China which took quite a while to get here. Thankfully it didn’t take much longer to get up and running.
IMG_20150704_125604The board came with a 6-pin ribbon cable and a USB cable. The USB cable is so short that it’s virtually unusable since the cable isn’t long enough to get the board to my desk from my computer. Thankfully, I have a longer cable I can use instead.

The first thing I did was to check the pinout of the cable so I don’t plug it in the wrong way on my boards. The easiest way the figure out the orientation of the header is to find Vcc and Ground with a multimeter, where you should see 5v across. It’s a 50/50 chance… so of course I got it wrong the first time as I saw the voltage reading fluctuate in the mV range.

Once I got the orientation of the connector right, I plugged it into one of my boards. I marked the first pin with a little sticker, as shown in the picture above.

Surprisingly, the Adafruit USBtinyISP drivers works with this board. I opened up Device Manager and updated the drivers with their files. The seller of this board had their own hosted driver files, though some poking around showed it was just the Adafruit drivers anyway.

IMG_20150704_124751First up was my Attiny85 Breakout Board. It’s not meant to fit into these half-sized breadboards but bending the power pins a little bit got it in. (If you bought one of these boards, don’t do this. This is a test unit, after all.)

I was able to upload the blink sketch directly from the Arduino IDE, with the Attiny85 settings and setting the programmer to “USBtinyISP “. The timing of the blink sketch was weird the first time I tried it, which made me realize I must have previously burnt the bootloader to use the 8MHz internal clock instead of the default 1MHz. I decided to try burning the bootloader so it would go back to using the 1Mhz clock. The USBtinyISP was able to do it and the sketch ran perfectly.IMG_20150704_124905Now for the Atmega328p Breakout Board. To upload through the USBtinyISP and the Arduino IDE, I can’t just click Upload like I did with the Attiny85 board. I have to hold shift when I click the Upload button to Upload Using Programmer. This is supposed to upload the sketch to the microcontroller without needing a bootloader. Once I upload a sketch with the USBtinyISP, I can’t upload a sketch if I place it in an Arduino Uno, so I guess that uploading with a programmer erases the bootloader…? To be able to use the microcontroller on an Arduino Uno again, I have to burn the bootloader with the USBtinyISP board. It’s not a big deal, but it’s something I have to remember to do so I don’t get confused why things aren’t working later on.

So with the FTDI and USBtinyISP programming tools at my disposal, I’m very excited to get the next revision of my Atmega328p Breakout Boards as they have headers for both devices. Stay tuned for news on that! Thanks for reading!

Something new for my toolbox: FTDI Basic

IMG_0001smI decided to pick up an FTDI board so that I can explore a new way to program the Atmega328p, specifically to see first-hand that it works so I can implement an FTDI header in the next Atmega328p Breakout Board. The FTDI Basic is a Sparkfun board, though I purchased it from RobotShop because they can ship within Canada.

I believe the one feature that sets it apart from the USBtinyISP (what you use those 6-pin ISP headers with on the Arduino, etc) is that enables you to do serial communication. This makes it a lot better for prototyping since you can debug using the serial monitor.

The original purpose of the Breakout Board was to take over from your Uno once you are finished prototyping… not really to use it to prototype. Technically speaking, there’s nothing wrong with prototyping on the Breakout Board, but it’s not currently breadboard-friendly and it only got a programming header (ISP) in the last revision. It sounds like an excuse, and it is, but to keep the board small while keeping the pins in order, it’s hard to organize the traces in the restricted amount of space to make the board breadboard-friendly. It’s a learning process with each board and revision so I hope I have learned enough to make it happen with the next one!
IMG_0001smAnyways, in short, the FTDI Basic works perfectly. I tested it with this Atmega328p setup on a breadboard. After installing the FTDI drivers, I was able to upload new sketches and print things to the serial monitor.

The one odd thing is that I had the understanding that to upload using the FTDI board, I had to hold shift while clicking Upload in the Arduino IDE, which changes it to “Uploading Using a Programmer”. That didn’t work. After a few searches, it turns out that changing the Programmer in the IDE to “Arduino as ISP” does the trick.

Getting up and running with the FTDI Basic so quickly makes me eager to get it into the next Atmega328p Breakout Board. I’m on the fence about keeping the 6-pin ISP header since you have more functionality from the FTDI chip (serial communication). I’d like to keep both, but if I can’t fit both on the small board, the 6-pin ISP header would be the one to go. Stay tuned!

Adventures with surface mount soldering (and store updates)

IMG_0001Finishing up a soldering session with a pile of PCBs is so satisfying!

Over the past little while, I’ve been working on getting new products in my Tindie store, while learning new things and hitting a few speed bumps along the way.

Adventures in Surface Mount Soldering

When I started assembling the ATmega328p Breakouts that use surface mount components, I was excited to gain some experience working with SMT components. The first time I was exposed to surface mount soldering was back in my first semester of college where we used flux, solder paste, and a toaster oven to assemble some SMT kits. Hand soldering my ATmega boards, I realized quickly that it would be impractical for me to assemble every single one. To date, I’ve sold about half assembled and half as unassembled kits. In my time assembling all of those boards, I’ve picked up a few lessons.

My first lesson is that you’re screwed without flux, at least if you want decent looking joints. My method is to get the component on with any amount of solder, then throw some flux on it and hit it with the iron. It lets the solder flow again and makes a cleaner joint than if you were relying on the flux in the solder.

My second lesson is to use rubbing alcohol to clean up the flux residue, specifically 100% (or as close as you can) alcohol. I accidentally picked up rubbing alcohol that’s only 70% and it’s doing a poor job compared to when I was using something like 95% earlier. Still, with some aggressive wiping, and sometimes even rinsing the board with water, I can still get the boards looking clean.

My final lesson is to never go smaller than the size 0805. The capacitors I’m using on those ATmega328p Breakouts are 0603 and they’re the hardest components to put on. Of course there had to be two of them. In my new NCP1117 voltage regulator boards, I’m using 0805 capacitors and they were a lot easier to put on.

What’s New?

So after all that about surface mount soldering, I decided to go back to the basics with the ATmega328p Breakout Board and reintroduce one with just through-hole components. The ATmega328p Breakout Board BASIC is much like the original one I was using before I ever opened my Tindie store. I hope with less components and only through-hole components, the kit option will be more appealing to people. It’s also easier for me to put together too so I can get more assembled boards up quicker than I ever could with the original, which is now dubbed as the PRO version.

I also put up a couple of SMT breakouts, 0805 and SOT-223.

I’m working on a couple new board designs, and I’m also thinking of putting up some components I don’t need for sale. Stay tuned!