Adafruit PiOLED - 128x32 Mini OLED for Raspberry Pi Created by lady ada Last updated on 2018-08-22 04:00:40 PM UTC
Guide Contents Guide Contents Overview Usage Step 1. Dependencies Step 2. Enable i2c Step 3. Verify I2C Device Running Stats on Boot Library Usage More Demos & Examples Speeding Up the Display Downloads Files Schematic & Fabrication Print © Adafruit Industries https://learn.adafruit.
Overview If you're looking for the most compact lil' display for a Raspberry Pi (https://adafru.it/wF8) (most likely a Pi Zero (https://adafru.it/vIa)) project, this might be just the thing you need! The Adafruit PiOLED is your little OLED pal, ready to snap onto any and all Raspberry Pi computers, to give you a little display. The PiOLED comes with a monochrome 128x32 OLED, with sharp white pixels.
These displays are small, only about 1" diagonal, but very readable due to the high contrast of an OLED display. This screen is made of 128x32 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! Using the display is very easy, we have a Python library for the SSD1306 chipset.
Comes completely pre-assembled and tested so you don't need to do anything but plug it in and install our Python code! Works with any Raspberry Pi computer, including the original Pi 1, B+, Pi 2, Pi 3 and Pi Zero. © Adafruit Industries https://learn.adafruit.
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.
Running Stats on Boot You can pretty easily make it so this handy program runs 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/stats.py & on its own line right before exit 0 Then save and exit. Reboot to verify that the screen comes up on boot! © Adafruit Industries https://learn.adafruit.
For more advanced usage, check out our linux system services guide (https://adafru.it/wFR) Library Usage Inside the examples subdirectory you'll find python scripts which demonstrate the usage of the library. These are covered in more detail in our OLED guide here, so do check them out. (https://adafru.it/wF9) To help you get started, I'll walk through the stats.py code below, that way you can use this file as the basis of a future project. import time import Adafruit_GPIO.
# Raspberry Pi pin configuration: RST = None # Note the following are only used with SPI: DC = 23 SPI_PORT = 0 SPI_DEVICE = 0 # 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) # Alternatively you can specify an explicit I2C bus number, for example # with the 128x32 display you would use: # disp = Adafruit_SSD1306.
# 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.
while True: # Draw a black filled box to clear the image. draw.rectangle((0,0,width,height), outline=0, fill=0) # Shell scripts for system monitoring from here : https://unix.stackexchange.com/questions/119126/command-to-disp cmd = "hostname -I | cut -d\' \' -f1" IP = subprocess.check_output(cmd, shell = True ) cmd = "top -bn1 | grep load | awk '{printf \"CPU Load: %.2f\", $(NF-2)}'" CPU = subprocess.check_output(cmd, shell = True ) cmd = "free -m | awk 'NR==2{printf \"Mem: %s/%sMB %.2f%%\", $3,$2,$3*100/$
# 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.SSD1306_128_32(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_POR$ # 128x64 display with hardware SPI: # disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, dc=DC, spi=SPI.
Downloads Files EagleCAD PCB files on GitHub (https://adafru.it/wFa) UG-2832HSWEG02 (https://adafru.it/qrf) Datasheet SSD1306 (https://adafru.it/aJK) Datasheet Fritzing object in Adafruit Fritzing Library (https://adafru.it/c7M) Schematic & Fabrication Print © Adafruit Industries https://learn.adafruit.
© Adafruit Industries Last Updated: 2018-08-22 04:00:34 PM UTC Page 15 of 15