Book Image

Raspberry Pi LED Blueprints

By : Agus Kurniawan
Book Image

Raspberry Pi LED Blueprints

By: Agus Kurniawan

Overview of this book

Table of Contents (14 chapters)
Raspberry Pi LED Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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...