A Linear Binary Clock

by JohnThinger in Circuits > Clocks

1124 Views, 5 Favorites, 0 Comments

A Linear Binary Clock

A Linear Bnary Clock

There are many good DIY projects about “digital” or “binary” wrist watches or wall/desktop clocks around.

This tutorial shows just some similar versions of that concept with very simple electronic circuits and a very easy-to-make design.

Supplies

ATtiny_Products.png

For making the clock, you will need:

Either:

  • 1x PCB Prototyping Board: 6 x 28 Holes // 20 x 80 mm
  • 1x ATtiny85 (DIP-8 version)
  • 1x 8 Pin DIP Socket
  • 1x USP Programmer or Arduino Uno + Some Jumper Cables
  • 3x Microswitch

Or:

  • 1x (DS1302) RTC Module With Integrated Cell Battery Holder
  • 1x Digispark Mini or Clone (ATtiny 85 USB module either with Micro-B-USB connector or USB-A connector)

In both configurations, you will need additionally:

  • 1x 100 µF Capacitor (optional)
  • 1x 3D Printer and some filament, or a Printing Service, or some Self-made Case
  • Some 0.14…0.25 mm² Cable
  • Some Acrylic Glass (100 x 100 x 2 mm, optional)
  • 4x M2x10 Screw and 4x M2 Nut
  • 12x M3x10 Screw and 12x M3 Nut
  • 17x LEDs From a WS2812B 5V RGB LED Strip With 60 LEDs per Meter
  • 1x DC Barrel Jack Socket 5.5 mm/2.1 mm (for Panel Mount, w/ M7 Nut)
Please Note: You may use LED strips with other dimensions (i.e. 30 LEDs/m or 144 LEDs/m) but in these configurations the proposed design will not fit.

Clock Version a - Programming the ATtiny

The version of the clock that is shown in the introduction video is operating with a plain ATtiny85 microprocessor.

The ATtiny microprocessors can be programmed much like a standard Arduino within the Arduino IDE. You must, however, install the ATtiny board family and select the ATtiny85 as a target. Furthermore, you will need an an ISP (in-system programmer). While there are many cheap ones around, the simplest solution is to use an Arduino Uno for programming. Both steps - the board family installation and the wiring between an Arduino Uno and the ATtiny - are shown in this tutorial. During board selection, please keep an eye on the settings of the internal clock: The integrated clock of the ATtiny microprocessors can be set to different frequencies. The precision of this clock is sufficient for what we are doing here, but the selected frequency must match the sketch that will be transferred to the ATtiny. Thus, the bootloader of the ATtiny must be adapted to the desired frequency, as shown in the link given above. Otherwise, the execution of the code will be much faster or much slower than expected. You will see the effect if you go for the Blink example with non-matching times of bootloader and program.

After completing the aforementioned installation steps, make sure that the libraries Adafruit NeoPixel is installed under Tools → Manage Libraries…. Then do the following:

  • Under Tools → Boards, select the ATtiny 25/45/85.
  • Under Tools → Processor, select ATtiny85.
  • Under Tools → Clock, select the internal clock rate that matches the boot loader (or rewrite the boot loader with the selected clock rate).
  • Select your ISP (i.e. your “real” ISP product or the Arduino Uno acting as ISP).
  • Load the attached .ino file and push the upload button.
  • Wait for the programming process to finish.

The code itself is pretty simple: At the start of the program, the NeoPixel object is initialized. The setup()-Routine initializes the microswitches. The loop then waits until another second is due, after which it lights the single LEDs according to the counted seconds, minutes and hours. (More details on the code are given in Step 3).

Hooray! The ATtiny programming is done! But the result is not that impressive at the moment, as there is no actual circuit yet. For the moment, disconnect your Arduino Uno and the ATtiny from their USB connections (and thus their power supply) and go for the next step.

Clock Version a - Circuit With Three Buttons

Binary_Clock_001_Simple_Solution_With_Microswitches_Steckplatine.jpg
Binary_Clock_V01.png
IMG_4422.jpeg
ATtiny.png
Three_Buttons.jpg

The first version of the clock will only use the internal timers of the ATtiny chip. Hence, it does not know the local time at start-up, and it might drift slightly if running over a longer period. While the drift should not be a big deal, we need a way to set the current time - and that is why the circuit (as shown in the pictures) has three buttons. For a first test, the circuit can be set up on a breadboard. If you are going to solder the elements to a prototype PCB, an 8 pin DIP socket for the ATtiny is deeply recommended as you need to remove the ATtiny each time you want to re-program it with the ISP (Arduino Uno). During soldering, use some wire and/or solder to create the solder tracks as shown in the circuit diagram but on the backside of the board.

The single steps for making the circuit are:

  • Cut a segment of 17 LEDs from the LED strip.
  • If your power supply does not have an integrated capacitor and tends to be unstable, connect a 47…100µF capacitor between 5V and GND as shown in the picture.
  • Connect 5V to one pin of each microswitch.
  • Connect the other pin of the microswitches to pins 5, 6, and 7 (= D0, D1, D2) of the DIP socket which will later be a home for the ATtiny.
  • Connect 5V to pin 8 of the DIP socket.
  • Connect GND to pin 4 of the DIP socket.
  • Connect pin 3 (= D4) of the DIP socket to DIn of the LED strip.
  • Connect 5V to the 5V pin of the LED strip.
  • Connect GND to the GND pin of the LED strip.
  • Connect GND and 5V to the according pins of the barrel jack socket.
Please note: The capacitor is recommended for most microprocessor circuits, but as I have a stabilized power supply and I do not expect much disturbances from the elements in this circuit, it worked very well without this capacitor in my setup.
Please note: In the circuit, the ATtiny is placed upside down (semicircle on the bottom) compared to the pin-out diagram (semicircle on top). Please also note that the pin numbers of the ATtiny are not identical with the logical input and output numbers in the Arduino program. This is why I wrote down both types of enumeration in the pin-out diagram.

Clock Version a - Setting the Time

Clock_LInear_3.jpg

Once you power-on the programmed ATtiny with the connected LED-strip, you should see the clock starting at 00:00:00, i.e. it will start counting the seconds on the last six (red-pink) LEDs. The LED on the far right is the “least significant bit”. After 59 seconds (i.e. 111011 in terms of the switching states of those six LEDs), the six LEDs in the middle (green) should start counting the minutes. The leftmost five (blue) LEDs finally count the hours (European style, i.e. up to 23). You can change the colors per LED within the setPixelColor commands:

  pixels.setPixelColor(i, (0x0000FF + i * 0x101000) * ((hours >> (4 - i)) & 0x01)); 

Each color for the seconds, minutes, and hours are slightly different, where the base color is the first 6-digit hex number (here: 0x0000FF = pure red), and the variation factor is the second hex number (here: 0x101000, so it adds some of the blue and green channels for each hour LED, making them a bit lighter per LED).

Now, you probably don’t always want to wait until midnight for starting the clock… …so that’s where the three buttons come into play:

  • The leftmost button should be connected to input D2. Press and hold it for about a second to switch on/off all the LEDs. That may be useful if you don’t want to display the current time all the time, but you want to maintain the internal time counted by the ATtiny, so the ATtiny keeps running while the LEDs are off.
  • The middle button is connected to D1. If you press it, the displayed time will decrease.
  • The right button is connected to D0. It will increase the displayed time.

That’s it for the most basic configuration. If you do not like the colors, you can easily change them. Just look for the pixels.setPixelColor commands and modify the six-digit hex codes according to your needs.

Did I forget anything? Yes! There are different modes for binary watches/clocks. Most of them do not really show the hours, minutes, and seconds in a real binary way. Instead, they usually display the single digits of the hours, minutes, and seconds in a binary style as described here. Well, I think this is too trivial, so the presented clock encodes the entire hours, minutes, and seconds each in one binary number. If you look at the code, this is named “PURE_BINARY” in the #define right after the include-statement.

If you want to make reading the clock a bit easier (…but not too easy…), you may delete the “#define PURE_BINARY”. Again, you will not get a simplified display corresponding to the single digits, but the minutes and seconds will be displayed using the first LED in each block as “30” (i.e. half an hour/minute), the second as “15” (quarter of an hour/minute) and the remaining four as “0…14” (minutes/seconds). That’s not the real deal, but it makes “classifying” the current time much easier for “untrained” persons. 

Clock Version a - Making a Case

Assembly_Step_01.jpg
Assembly_Step_02.jpg
PA100299 copy.jpg

The clock using a segment of an LED strip is meant to be very basic. Most LED strips already have an adhesive tape on the back, so you can simply glue the strip to any board and use some tape/glue to fix the circuit to it, too. If you want to have a proper "housing", you can 3D-print the attached files, then use the M3 screws and nuts to assemble them, and finally integrate the electronics and stick the LED strips to the H(our), M(inutes), and S(econds) segment as shown above. As all 17 LEDs remain in one strip, no further wiring is necessary.

For the lid of the case, just cut a piece of translucent acrylic plastic/glass (70 x 39 x 2 mm) if you like to display the electronics. 

Clock Version B - Adding a Real Time Clock (RTC)

Binary_Clock_All_Steckplatine_1.jpg
Binary_Clock_V02a.png
Binary_Clock_All_Steckplatine_2.jpg
IMG_4424.jpg

The design shown above has three buttons for adjusting the displayed time, but this adjustment must be done each time the clock is restarted. Integrating a real time clock (RTC) in the circuit "cures" this problem. For sake of simplicity, we add a "ready-made" RTC module. These modules are very common, you will find them easily when looking for “RTC module” in search engines. They include the RTC chip itself, a crystal oscillator (if needed by the RTC chip), and the cell battery buffering the RTC chip when the device is powered off.

Concerning the RTC chip itself, there are three major types:

  • The DS1302 is the oldest and cheapest one. It is somewhat imprecise, meaning it may delay or advance by some seconds per day. It requires an external 32,768 kHz crystal, and comes with a three wire serial interface.
  • The DS1307 is about the same as the 1302, but it offers an I2C interface.
  • The DS3121 is a newer version with much better precision, because it has an integrated temperature compensation.

A more complete comparison can be found here.

There are some newer versions of the RTC chips with user RAM (DS3232, DS3234, DS3235). Their enhanced features are described here, but they are not relevant for this project, so we stay with the DS1302 module / chip and its three wire interface.

The ready-made RTC modules can be used in combination with the ATtiny85 as shown in the attached breadboard and perfboard diagrams. As an alternative, however, I use a Digispark ATtiny board for the second variant of the clock. With these boards you do not need an ISP for programming, and neither you need any soldering skills.

Digispark ATtiny boards come in two different configurations (see first picture in Step 1). One of them has an USB-A connector, the other one features a Micro-USB-B connector. The pin-out and functionality is the same. The advantage of the USB A version is that you do not need any cable for programming. In the circuit diagrams you will see the USB-A version while my other picture shows the Micro-USB board.

Please note: If you do not want to solder anything at all, make sure that both your RTC module and your Digispark board come with already-soldered headers. Furthermore, make sure that your LED strip comes with some soldered connectors. Additionally, you will need some y-jumper cables. You can make them yourself without soldering (as shown here), but the involved crimping process is not much easier than soldering. Alternatively, you can search for "Dupont y cable" or "Dupont splitter" or "jumper y adapter" on the internet, but I admit that these cables are hard to find.
One final tip: If you go for the non soldering approach, use some hot glue for fixing the jumper cables to the headers.

For including the real time clock we need a different piece of code. Please use the attached .ino file and upload it to your board (or the ATtiny).

Please note: For programming the Digispark ATtiny boards (or any of their clones), you must add support for the Digistump board family as explained here. Make sure to select the Digistump → Digispark board under Tools → Board (NOT an ATtiny chip from the ATtiny family!). Make sure that the selected board in the IDE matches the frequency of your device (or renew the bootloader). The boards are usually set to a default frequency of 16.5 MHz, so select this default board if there is not noted differently.
Please note: After installing and selecting this board family in the IDE, there is one more difference to the conventional Arduinos: When you hit the button for uploading a sketch, make sure that the board is not connected to USB. Just wait until compiling is complete, and the Arduino IDE will then ask you to connect the board now after which it will upload the program.

You will notice that there are no buttons anymore, so how will the time be set?

Well, the RTC clock should always store the current time in its internal memory which is buffered by its battery. If the stored time is wrong, we assume that the battery is empty and the RTC chip has consequently lost track. In this case, the system will probably think it is midnight at start (00:00 am). The sketch, however, captures the PC's time during the compilation process, and adds it to the resulting binaries that are uploaded to the ATtiny. When starting the clock, it checks the time being stored in the RTC chip. If that time is "smaller" than the compile time, the compile time will be "applied" and stored back to the RTC. You will find this mechanism in the following lines of code:

RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
...
RtcDateTime now = Rtc.GetDateTime();
if(now < compiled){
Rtc.SetDateTime(compiled);
}

As a result of this simple mechanism, you will need to recompile the code when changing batteries... ...or you add some buttons to your build again. Anyway: The CR203 battery which is typically used with the DSxxxx RTCs is said keep the time for up to 10 years.

The rest of the code stays the same.

As you see from the picture, the non-soldering Digispark solution with the RTC is probably a bit bigger than the soldered board. Hence, you might need a bigger housing. The attached STL file should provide sufficient space..

Outlook

IMG_4425 copy.jpg

This instructable presented two different versions of a binary clock - with and without RTC. The clocks are made from standard LED strips with WS2812B chips that you will find in many local furniture stores and hardware stores.

In the end, I wanted to have a more compact version with a LED ring instead of the LED strip.

That clock will be described in a separate instructable.