Raspberry Pi (Part 3)

OLED display

Raspberry Pi OLED display

The Raspberry Pi can output text (and simple graphics) to an OLED display using Python.

OLED wiring

i2cdetect -y 1

Luma-OLED Driver

I installed the Luma-OLED driver by following these instructions:

https://luma-oled.readthedocs.io/en/latest/install.html

I installed the driver with this command

$ sudo -H pip3 install --upgrade luma.oled

I enabled I2C communications using the raspi-config application

$ sudo raspi-config

Interface Options | I2C | enable ARM I2C

i2c permissions

I followed the steps described by Alexander Rüedlinger to allow non-root users to access i2c devices (specifically the OLED display).

1) Create new user group called i2c:
$ sudo groupadd i2c

2) Change the group ownership of /dev/i2c-1 to i2c:
$ sudo chown :i2c /dev/i2c-1

3) Change the file permissions of the device /dev/i2c-1 so users of the i2c group can read and write to the device:
$ sudo chmod g+rw /dev/i2c-1

4) Add your user to the group i2c:
$ sudo usermod -aG i2c <username>

Python code

hello.py

The hello.py code running on configured hardware

Displaying an image on the OLED display

I downloaded a stop sign image and updated the hello.py code to display the image on the OLED display.

Stop sign

stop_sign_display.py

Using OpenCV and luma.oled to display video on the OLED display

OpenCV (Open Source Computer Vision Library) is an open-source computer vision and machine learning software library. It provides a comprehensive set of tools and functions that enable developers to perform various computer vision tasks, such as image and video processing, object detection, facial recognition, and feature extraction. 

I used the cv2 library to read frames from a dog video I downloaded from:
https://pixabay.com/videos/puppy-dog-playful-beach-sand-play-4740/

Then I updated the code to send image captured by the webcam to the OLED display.

Dog video

dog_display_window_and_oled.py

Webcam

webcam_display_window_and_oled.py