Adafruit 128x64 OLED Bonnet for Raspberry Pi Created by lady ada Last updated on 2018-08-22 04:00:56 PM UTC
Guide Contents Guide Contents Overview Usage Step 1. Dependencies Step 2. Enable i2c Step 3. Verify I2C Device Running Scripts on Boot Library Usage Python library setup Pin Setup Display Setup Display Initialization Button Input & Drawing 8 9 9 10 10 More Demos & Examples Speeding Up the Display Downloads Files Schematic & Fabrication Print © Adafruit Industries 2 3 6 6 7 7 8 8 https://learn.adafruit.
Overview If you'd like a compact display, with buttons and a joystick - we've got what you're looking for. The Adafruit 128x64 OLED Bonnet for Raspberry Pi is the big sister to our mini PiOLED add-on (https://adafru.it/wVd). This version has 128x64 pixels (instead of 128x32) and a much larger screen besides. With the OLED display in the center, we had some space on either side so we added a 5-way joystick and two pushbuttons. Great for when you want to have a control interface for your project.
These displays are small, only about 1.3" diagonal, but very readable due to the high contrast of an OLED display. This screen is made of 128x64 individual white OLED pixels and because the display makes its own light, no backlight is required. This reduces the power required to run the OLED and is why the display has such high contrast; we really like this miniature display for its crispness! © Adafruit Industries https://learn.adafruit.
Please note that this display is too small to act as a primary display for the Pi (e.g. it can't act like or display what would normally be on the HDMI screen). Instead, we recommend using pygame for drawing or writing text. Using the display and controls in python is very easy, we have a library ready-to-go for the SSD1306 OLED chipset and the joystick/buttons are connected to GPIO pins on the Pi. Our example code allows you to draw images, text, whatever you like, using the Python imaging library.
Usage We'll be using Python to control the display. In theory you can use any language you like that gives you access to the computer's I2C ports, but our library is for Python only! This guide assumes you have your Raspberry Pi all set up with an operating system, network connectivity and SSH! Step 1. Dependencies Before using the library you will need to make sure you have a few dependencies installed. Connect to your Pi using SSH (https://adafru.it/vbC) and follow the steps below. Install the RPi.
Step 2. Enable i2c To enable i2c, you can follow our detailed guide on configuring the Pi with I2C support here. (https://adafru.it/dEO) After you've enabled I2C you will need to shutdown with sudo shutdown -h now Once the Pi has halted, plug in the PiOLED. Now you can power the Pi back up, and log back in. Run the following command from a terminal prompt to scan/detect the I2C devices sudo i2cdetect -y 1 You should see the following, indicating that address 0x3c (the OLED display) was found Step 3.
Press buttons to interact with the demo. Press the joystick + buttons at once for an Easter egg! Running Scripts on Boot You can pretty easily make it so this program (or whatever program you end up writing) run every time you boot your Pi. The fastest/easiest way is to put it in /etc/rc.local Run sudo nano /etc/rc.local and add the line sudo python /home/pi/Adafruit_Python_SSD1306/examples/buttons.py & on its own line right before exit 0 Then save and exit.
import RPi.GPIO as GPIO import time import Adafruit_GPIO.SPI as SPI import Adafruit_SSD1306 from PIL import Image from PIL import ImageDraw from PIL import ImageFont First a few modules are imported, including the Adafruit_SSD1306 module which contains the OLED display driver classes. You can also see some of the Python Imaging Library modules like Image, ImageDraw, and ImageFont being imported.
# 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 # 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.
try: while 1: if GPIO.input(U_pin): # button is released draw.polygon([(20, 20), (30, 2), (40, 20)], outline=255, fill=0) else: # button is pressed: draw.polygon([(20, 20), (30, 2), (40, 20)], outline=255, fill=1) if GPIO.input(L_pin): # button is released draw.polygon([(0, 30), (18, 21), (18, 41)], outline=255, fill=0) else: # button is pressed: draw.polygon([(0, 30), (18, 21), (18, 41)], outline=255, fill=1) #Up #Up filled #left #left filled if GPIO.input(R_pin): # button is released draw.
# Raspberry Pi pin configuration: RST = 24 and change it to: # Raspberry Pi pin configuration: RST = None # PiOLED does not require reset pin and make sure that the configuration section where you choose which type of display, looks like this # 128x32 display with hardware I2C: #disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST) # 128x64 display with hardware I2C: disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST) # 128x32 display with hardware SPI: # disp = Adafruit_SSD1306.
reboot to 'set' the change. © Adafruit Industries https://learn.adafruit.
Downloads Files EagleCAD PCB files on GitHub (https://adafru.it/wWC) UG-2864HSWEG01 (https://adafru.it/aJI) Datasheet UG-2864HSWEG01 (https://adafru.it/wWD) User Guide SSD1306 (https://adafru.it/aJK) Datasheet Fritzing objects available in the Adafruit Fritzing Library (https://adafru.it/aP3) Schematic & Fabrication Print Dimensions in mm © Adafruit Industries https://learn.adafruit.
© Adafruit Industries Last Updated: 2018-08-22 04:00:50 PM UTC Page 15 of 15