Numitron clock & thermometer

 by janw
FeaturedContest Winner
SDC12109.JPG
SDC12105.JPG
SDC12110.JPG
SDC12111.JPG
I really like nixie and numitron clocks, but I never worked with them before. So I decided to give it a go. I choose numitrons because of 2 reasons: first of all nixies need a higher voltage than numitrons to work. Nixies need around 170V DC and numitrons only 4,5V so they are safer to work with and don't need a special powersupply.

The timekeeping is done by a ds1307 I2C realtime clock and the temperature is measured with a DS18B20 1wire temperaturesensor.



An Atmega48 is used to proces the data and to drive the segments in the numitrons. I used Bascom to write the code and a MyAvr MK2 Programmer to stuff it into the microcontroller. You can find a free Bascom demo here. The only limitation of the demo version is that you can only compile 4Kbytes of code (but the atmega48 has only 4Kbytes so that will work fine.)

I added this instructable to the microcontroller contest, so give it a vote if you like it.
 
Remove these adsRemove these ads by Signing Up

Step 1: The DS1307 realtime clock

ds1307.jpg
ds1307.png
The timekeeping will be done by a DS1307 IC. This is a handy little IC, because it not only keeps track of time but also of the date and the day of the week.

For this little project we'll only use it to keep track of the time. Therefore it needs a 32.768kHz quartz crystal connected between pins 1 and 2. We can also add a battery with + to pin 3 and - to pin 4. This enables the IC to keep working when the mainpower is switched off. If you don't want to use this feature, you can just connect pin 3 to pin 4 and everything will work fine.

Pin 5 and pin 6 will be used to transfer the data to our microprocessor. They should be connected to the SCL and SDA pins on your microprocessor. These lines need to be pulled high by a 4K7 pullup resistor.


Bascom makes working with I2C devices easy. You only need to know 4 commands:
  1. I2cstart: This commant will startup I2c communications
  2. I2cstop: This command will stop I2c communications
  3. I2crbyte var: This command reads a byte from the device and stores it in 'var' 
  4. I2cwbyte var: This command writes the variable 'var' to the device
Using the write or read command is not enough, we will also have to tell the device whether we want to write to it or read from it. We do this by using the right address. These addresses can be found in the datasheet. The write-address for the DS1307 is D0H and the read-address D1H (the H behind it tell us that these are hexadecimal figures).

The DS1307 sends and wants to receive data in BCD format. This is a variation on binary for diplays where every digit is represented by four bits. More about that here. Luckily converting from BCD to decimal and visa versa is very easy in Bascom.
  • var = Makebcd(var) will convert decimal, hex and binary into BCD
  • var = Makedec(var) will convert hex, binary and BCD into decimal


The data is stored on the IC in register. You can imagine them as those oldfashioned filingcabinets. Each drawer has its number and contains some info:

00H Seconds
01H Minutes
02H Hours
03H Day
04H Date                                               The H tell us that these are hexadecimal figures.
05H Month
06H Year
07H Control
08H to 3FH Ram

If we want to read or store some data we'll first have to tell the device in which drawer we want to be. We can do this by writing the hex code for that drawer to the device. The device then will grant us acces to that drawer. After you write or read something from or to this register the device will automatically jump to the next one. So there is no need to send the location every time

Now lets put this in code:

For this code you will need to dim hours as byte, minutes as byte and seconds as byte.

First, we will set the clock:


Seconds = Makebcd(Seconds)                             We convert our variables into BCD format
Minutes = Makebcd(Minutes)
Hours = Makebcd(Hours)

reset hours.6                                                            We reset bit 6 of the hoursbyte to make sure that
                                                                                    our Clock runs in 24h modus. If bit 6 is 1 then the
                                                                                    clock runs in 12h modus and bit 5 will then 
                                                                                    contain the AM/PM data.


I2cstart
I2cwbyte &HD0                                                         We tell the device that we want to write a byte
2cwbyte &H00                                                           We start at the register for seconds hex 00  
I2cwbyte Seconds                                                    Adding seconds
I2cwbyte Minutes                                                      Adding minutes
I2cwbyte Hours                                                         Adding hours
I2cstop

 Now our clock is set! Lets read from it now.

I2cstart
I2cwbyte &HD0                                                        We tell the device that we want to write a byte.
I2cwbyte &H00                                                         We ask the device to go to the seconds register.
I2cstop
I2cstart                                                                       
I2cwbyte &HD1                                                        We tell the device that we want to read bytes.
I2crbyte Seconds , Ack                                           We read the data and acknowledge that we want 
                                                                                     to read the next byte too.                  

I2crbyte Minutes , Ack
I2crbyte Hours , Nack                                             We don't ackowledge here so the device knows
                                                                                     that we are done reading.

I2cstop

Hours = Hours And &B00111111                        We remove bits 6 and 7 as they contain other
                                                                                    data. If you are in 12h modus, then you need to
                                                                                    remove bit 5 too

Hours = Makedec(Hours)                                      We convert back to decimal format.
Minutes = Makedec(minutes)
Seconds = Makedec(seconds)

Now we know what time it is.

In the next step we will take a closer look at the DS18B20.

PICme says: May 19, 2012. 1:28 PM
Hi Janw,
I have the control board built and sourced the IV-9 Numitrons. There is just one point i hope you can make clear. The Numitrons are numbered IC4 to IC1 in your schematic. How does that equate to the the hours and minutes. For example if the time is 09.24 does ic4=0, ic3=9, ic2=2, ic1=4. This is my first Numitron clock and any help would be greatly appreciated.
janw (author) in reply to PICmeMay 19, 2012. 1:53 PM
The order is correct as you mentioned it.
PICme says: May 16, 2012. 4:47 AM
Hi Janw,
Thank you for your prompt reply i understand the pin connections now.
PICme says: May 15, 2012. 6:28 AM
Hi janw,
I would like to build your excellent clock. Could you confirm the numitron pinots. I understand it is as follows:
(8 pin Socket) pin 1=com
2="b"
3="c"
4="a"
5="f"
6="g"
7="d"
8="e"
Also did you include any option to blank the screen at night. Thanks again for a great project.
janw (author) in reply to PICmeMay 16, 2012. 1:59 AM

Pin Connection:

1 common
2 right hand deciamal point
3 Segment (b)
4 Segment (c)
5 Segment (a)
6 Segment (f)
7 Segment (g)
8 Segment (d)

I did cut pin 2 because I did't use the decimal point, So i ended up with 8 pins instead of 9.

You don't need a blank out option. You can put a powerswitch on the powercord of the device. The battery of the DS1307 will take over the power for the timekeeping and all other functions are switched off. The battery can power a DS1307 for a few years so no worries there.
sgleason1 says: Mar 31, 2012. 8:01 AM
Can you add two more numitrons so it can display a temp with 1 decimal plagce, display the time in seconds and display the date?
janw (author) in reply to sgleason1Mar 31, 2012. 8:04 AM
Yes you can but bear in mind that you will need to speed up the multiplexing.
masterbalby says: Mar 4, 2012. 11:21 AM
I have great difficulty to draw a proper pcb.
Can you send me yours?
thank you in advance
masterbalby says: Feb 24, 2012. 1:57 PM
hello,
why have connected the 13 pin connector JP1 to +5 V while the pin 13 of the second connector is connected to anything.
thank you
janw (author) in reply to masterbalbyFeb 25, 2012. 6:12 AM
When I designed the pcb, I had the intention to add blue LEDs under the tubes for more colour. So a 5V supply was connected to JP1. The LED's never made it to the final design but I forgot to remove the 5V. You can leave it out.
masterbalby in reply to janwFeb 25, 2012. 12:04 PM
thank you very much
astroboy907 says: Feb 17, 2011. 3:00 PM
Hey- what do you think is an ok price for a numitron? Also, how large are your numitrons? Both the total physical size, and an estimated digit hight/width wold be nice- but its up to you. Great clock! I think im gonna build one for my geek lair :)
janw (author) in reply to astroboy907Feb 17, 2011. 11:57 PM
I paid about 25euro for 12 numitrons. So that's around 2euro for one and I think that this is a reasonable price.

The dimentions are:
11 x 8 mm (0.44" x 0.32") for the digit
32 x 10 mm (1.28" x 0.4") total size.


harry potter rules in reply to janwAug 15, 2011. 12:08 PM
did u enter it in the clock contest

u could win!!!!!!!!!!!
janw (author) in reply to harry potter rulesAug 15, 2011. 2:10 PM
I can't as this is an old instructable and I an not a US citizen
harry potter rules in reply to janwAug 20, 2011. 8:59 AM
are you from england
janw (author) in reply to harry potter rulesAug 20, 2011. 10:31 AM
No I am a Belgian who lives in The Netherlands.
astroboy907 in reply to janwFeb 18, 2011. 7:50 AM
k thanks :)
TerryKing says: Jun 1, 2011. 12:38 AM
How-To Information on the DS18B20 Temperature sensor here:
http://arduino-info.wikispaces.com/Brick-Temperature-DS18B20
CThoma031 says: May 11, 2011. 5:07 PM
i love the look and operation of it! If you sold these I would be the first customer.
astroboy907 says: Feb 16, 2011. 8:08 PM
Sweet! Mainly I just like the vintage look of the Numitrons :) Found some on ebay for cheap (2$ each!) so i might buy a few and use them in a project (or replace them for my seven segment displays in my 'ible!)

They would make an awesome desk clock!
F-17 says: Feb 15, 2011. 3:36 PM
Thats Pretty neat, 5*
n-2-stuff says: Feb 13, 2011. 10:34 PM
Awsome. Very nice case....
jeff-o says: Feb 13, 2011. 7:41 PM
I love the case! Very nice indeed.
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!