Create a clock with Raspberry Pi & Buzz-Boards™

clockTo create this interesting example we used the following components:

Ok, now time to start! First you will need to have your Raspberry Pi runnning. If you still have doubts about how to setup your RPi here is an excellent tutorial.

Notes:

  • In this example we used Adafruit Occidentalis v0.2 instead of Raspbian but if you have Raspbian you will need to enable I²C. To do that follow steps 2-4 to from this tutorial.  
  • I²C is a protocol invented by Phillips and used in our Buzz-Boards™. If you want to know more about I²C here is a good start.

Instructions:

1. Connect the Buzzberry and the Buzz-Led7
2. Then connect the Buzzberry to the Raspberry Pi.
3. Run the command “i2cdetect -y 0” and you will see the address where the Buzz-Led7 was detected. Note: If you use the second revision of the Model B Raspberry Pi use “i2cdetect -y 1” as in this version the primary and secondary I2C channels have been reversed. More information on this here.

4. Copy the following code and save it as <YOUR_NAME>.py (Note: we used Geany for save and compile the code, here is how to use install it and use it).

#------------------------------------------------------------------
# Show time on Buzz-Led7
#------------------------------------------------------------------
import smbus
import time
import datetime

# Access the i2c bus 
bus = smbus.SMBus(0)

# Adress of the device (i2cdetect -y 0)
addr = 0x3b
# Control register (sub address) - www.nxp.com/documents/data_sheet/SAA1064_CNV.pdf
cmd = 0x00
# Value to show on 7-segment led
val = 0x27

# Send value to physical address
bus.write_byte_data(addr,cmd,val)

# Equivalence to numbers on LED
def numToSeg(num):
    retval = 0x00; #default val
    if num==0:
        retval = 0x3F
    elif num==1:
        retval = 0x06
    elif num==2:
        retval = 0x5B
    elif num==3:
        retval = 0x4F
    elif num==4:
        retval = 0x66
    elif num==5:
        retval = 0x6D
    elif num==6:
        retval = 0x7D
    elif num==7:
        retval = 0x07
    elif num==8:
        retval = 0x7F
    elif num==9:
        retval = 0x6F
    return retval

# Obtain Time
now = datetime.datetime.now()
hour_str   = now.strftime("%H")
minute_str = now.strftime("%M")

print "Now:", now
print "Hour: ", hour_str
print "Minute: ", minute_str

h_0     = int(hour_str[0])
h_1     = int(hour_str[1])
m_0     = int(minute_str[0])
m_1     = int(minute_str[1])

# Digit 1
cmd = 0x01
val = numToSeg(h_0)
bus.write_byte_data(addr,cmd,val)

# Digit 2
cmd = 0x02
val = numToSeg(h_1)
bus.write_byte_data(addr,cmd,val)

# Digit 3
cmd = 0x03
val = numToSeg(m_0) 
bus.write_byte_data(addr,cmd,val)

# Digit 4
cmd = 0x04
val = numToSeg(m_1)
bus.write_byte_data(addr,cmd,val)

5. Run it on the console:

python <PATH_OF_YOUR_FILE>/<YOUR_NAME>.py

6. See the result on the Buzz-Led7!