Datasheet

The next bit of code will initialize the display library with begin() and clear the display with clear() and display() .
Then it will configure a PIL drawing class to prepare for drawing graphics. Notice that the image buffer is created in 1-
bit mode with the '1' parameter, this is important because the display only supports black and white colors.
We then re-draw a large black rectangle to clear the screen. In theory we don't have to clear the screen again, but its a
good example of how to draw a shape!
Once the display is initialized and a drawing object is prepared, you can draw shapes, text and graphics using PIL's
drawing commands (https://adafru.it/dfH). Here we are loading the default font, which works fine, but there's other
fonts you can load.
Next the code loads a built-in default font and draws a few lines of text. You can also load your own TrueType font and
use it to render fancy text in any style you like
# Initialize library.
disp.begin()
# Clear display.
disp.clear()
disp.display()
# Create blank image for drawing.
# Make sure to create image with mode '1' for 1-bit color.
width = disp.width
height = disp.height
image = Image.new('1', (width, height))
# Get drawing object to draw on image.
draw = ImageDraw.Draw(image)
# Draw a black filled box to clear the image.
draw.rectangle((0,0,width,height), outline=0, fill=0)
# Load default font.
font = ImageFont.load_default()
# Alternatively load a TTF font.
# Some other nice fonts to try: http://www.dafont.com/bitmap.php
#font = ImageFont.truetype('Minecraftia.ttf', 8)
© Adafruit Industries https://learn.adafruit.com/adafruit-pioled-128x32-mini-oled-for-raspberry-pi Page 11 of 15