Reader small image

You're reading from  Raspberry Pi LED Blueprints

Product typeBook
Published inSep 2015
Publisher
ISBN-139781782175759
Edition1st Edition
Right arrow
Author (1)
Agus Kurniawan
Agus Kurniawan
author image
Agus Kurniawan

Agus Kurniawan is an independent technology consultant, author, and lecturer. He has over 18 years' experience working on various software development projects, including delivering training courses and workshops, and delivering technical writing. He has done a few research activities related to wireless networking, software, and security in multiple universities. Currently, he is pursuing a Ph.D. program in Computer Science in Germany. He has previously written five books for Packt.
Read more about Agus Kurniawan

Right arrow

Building a digital clock using an I2C OLED graphic display


We have already learned how to use an I2C OLED graphic display. The next step is to build a digital clock using this module. In this scenario, we show hours and minutes on an OLED graphic display. If the minute or hour value changes from the current time on Raspberry Pi, we update the values on the OLED graphic display.

In addition, we need a font file to display numbers on the OLED graphic display. Download the FreeSans.ttf file using the following command:

wget https://raw.githubusercontent.com/BLavery/lib_oled96/master/FreeSans.ttf

To open a font file, we need the PIL library. Type the following command to install it:

sudo apt-get install python-imaging

Now we can write our program. Create a file, named ch03_03.py, and write the following complete code:

# ch03_03.py file

from lib_oled96 import ssd1306
from smbus import SMBus
from PIL import ImageFont
import datetime


i2cbus = SMBus(1)
oled = ssd1306(i2cbus)
draw = oled.canvas...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Raspberry Pi LED Blueprints
Published in: Sep 2015Publisher: ISBN-13: 9781782175759

Author (1)

author image
Agus Kurniawan

Agus Kurniawan is an independent technology consultant, author, and lecturer. He has over 18 years' experience working on various software development projects, including delivering training courses and workshops, and delivering technical writing. He has done a few research activities related to wireless networking, software, and security in multiple universities. Currently, he is pursuing a Ph.D. program in Computer Science in Germany. He has previously written five books for Packt.
Read more about Agus Kurniawan