Datasheet

# 128x64 display with hardware I2C:
disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST)
variant for creating the display object! The rest can remain commented out.
Note that above, we initialize RST = None because the OLED Bonnet does not require a reset pin.
Display Initialization
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!
Button Input & Drawing
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).
# 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)
© Adafruit Industries https://learn.adafruit.com/adafruit-128x64-oled-bonnet-for-raspberry-pi Page 10 of 15