The 1.3" OLED display with the SH1106 controller is a compact, high-contrast monochrome display ideal for embedded applications. With a resolution of 128x64 pixels and I2C connectivity, it integrates seamlessly with Raspberry Pi-based systems like Andino boards. This guide provides detailed instructions to set up the display, install the luma.oled
driver, create a file-to-OLED daemon for persistent text display, and control it via Node-RED. Additionally, it includes steps to run the daemon as a systemd service for reliable operation.
sudo raspi-config
sudo reboot
i2c-tools
:
sudo apt-get update
sudo apt-get install -y i2c-tools
0x3C
or 0x3D
):
sudo i2cdetect -y 1
If no address appears, check wiring and ensure I2C is enabled.
pip
are installed:
sudo apt-get install -y python3 python3-pip python3-venv
python3 --version
pip3 --version
luma.oled
Driverpython3 -m venv ~/oled_venv
source ~/oled_venv/bin/activate
luma.oled
and dependencies:
pip install --upgrade pip
pip install luma.oled
sudo apt-get install -y python3-pil python3-numpy
Test the installation with a simple script:
# /home/pi/test_oled.py
from luma.core.interface.serial import i2c
from luma.oled.device import sh1106
from luma.core.render import canvas
serial = i2c(port=1, address=0x3C)
device = sh1106(serial)
with canvas(device) as draw:
draw.text((0, 0), "Hello, Andino!", fill="white")
device.show()
source ~/oled_venv/bin/activate
python3 /home/pi/test_oled.py
The display should show "Hello, Andino!" temporarily.
To display text persistently, create a daemon that monitors a text file for updates and displays the content on the OLED.
Create the daemon script:
# /home/pi/sh1106_luma_display_daemon.py
import time
import os
from luma.core.interface.serial import i2c
from luma.oled.device import sh1106
from luma.core.render import canvas
# I2C connection
serial = i2c(port=1, address=0x3C)
device = sh1106(serial)
# File for text updates
TEXT_FILE = "/home/pi/display_text.txt"
# Initial text
current_text = "Andino OLED Ready"
# Update display function
def update_display(text):
with canvas(device) as draw:
draw.text((0, 0), text, fill="white")
device.show()
# Initial display
update_display(current_text)
# Monitor text file
try:
while True:
if os.path.exists(TEXT_FILE):
with open(TEXT_FILE, "r") as f:
new_text = f.read().strip()
if new_text != current_text:
current_text = new_text
update_display(current_text)
time.sleep(0.5) # Check every 0.5 seconds
except KeyboardInterrupt:
device.clear()
device.hide()
touch /home/pi/display_text.txt
chmod 666 /home/pi/display_text.txt
source ~/oled_venv/bin/activate
python3 /home/pi/sh1106_luma_display_daemon.py &
The display should show "Andino OLED Ready". Update the text file:
echo "Test Display" > /home/pi/display_text.txt
The display should update to "Test Display" and persist.
To update the display text using Node-RED:
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
node-red-start
http://<Raspberry-Pi-IP>:1880
)."Hello from Node-RED"
./home/pi/display_text.txt
.msg.payload
.To ensure the daemon starts automatically on boot:
sudo nano /etc/systemd/system/oled-daemon.service
Add the following:
[Unit]
Description=SH1106 OLED Display Daemon
After=network.target
[Service]
ExecStart=/home/pi/oled_venv/bin/python3 /home/pi/sh1106_luma_display_daemon.py
WorkingDirectory=/home/pi
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi
[Install]
WantedBy=multi-user.target
sudo systemctl enable oled-daemon.service
sudo systemctl start oled-daemon.service
sudo systemctl status oled-daemon.service
The display should show "Andino OLED Ready" or the last text written to /home/pi/display_text.txt
.
sudo i2cdetect -y 1
. Adjust address=0x3C
to 0x3D
if needed.ps aux | grep sh1106_luma_display_daemon
).pi
user and /home/pi/display_text.txt
has 666
permissions.journalctl -u oled-daemon.service
and ensure the virtual environment path is correct.This setup provides a robust solution for displaying persistent text on the 1.3" OLED display, controlled via Node-RED and running reliably as a systemd service.
The 1.3" OLED display with the SH1106 controller is a compact, high-contrast monochrome display ideal for embedded applications. With a resolution of 128x64 pixels and I2C connectivity, it integrates seamlessly with Raspberry Pi-based systems like Andino boards. This guide provides detailed instructions to set up the display, install the luma.oled
driver, create a file-to-OLED daemon for persistent text display, and control it via Node-RED. Additionally, it includes steps to run the daemon as a systemd service for reliable operation.
sudo raspi-config
sudo reboot
i2c-tools
:
sudo apt-get update
sudo apt-get install -y i2c-tools
0x3C
or 0x3D
):
sudo i2cdetect -y 1
If no address appears, check wiring and ensure I2C is enabled.
pip
are installed:
sudo apt-get install -y python3 python3-pip python3-venv
python3 --version
pip3 --version
luma.oled
Driverpython3 -m venv ~/oled_venv
source ~/oled_venv/bin/activate
luma.oled
and dependencies:
pip install --upgrade pip
pip install luma.oled
sudo apt-get install -y python3-pil python3-numpy
Test the installation with a simple script:
# /home/pi/test_oled.py
from luma.core.interface.serial import i2c
from luma.oled.device import sh1106
from luma.core.render import canvas
serial = i2c(port=1, address=0x3C)
device = sh1106(serial)
with canvas(device) as draw:
draw.text((0, 0), "Hello, Andino!", fill="white")
device.show()
source ~/oled_venv/bin/activate
python3 /home/pi/test_oled.py
The display should show "Hello, Andino!" temporarily.
To display text persistently, create a daemon that monitors a text file for updates and displays the content on the OLED.
Create the daemon script:
# /home/pi/sh1106_luma_display_daemon.py
import time
import os
from luma.core.interface.serial import i2c
from luma.oled.device import sh1106
from luma.core.render import canvas
# I2C connection
serial = i2c(port=1, address=0x3C)
device = sh1106(serial)
# File for text updates
TEXT_FILE = "/home/pi/display_text.txt"
# Initial text
current_text = "Andino OLED Ready"
# Update display function
def update_display(text):
with canvas(device) as draw:
draw.text((0, 0), text, fill="white")
device.show()
# Initial display
update_display(current_text)
# Monitor text file
try:
while True:
if os.path.exists(TEXT_FILE):
with open(TEXT_FILE, "r") as f:
new_text = f.read().strip()
if new_text != current_text:
current_text = new_text
update_display(current_text)
time.sleep(0.5) # Check every 0.5 seconds
except KeyboardInterrupt:
device.clear()
device.hide()
touch /home/pi/display_text.txt
chmod 666 /home/pi/display_text.txt
source ~/oled_venv/bin/activate
python3 /home/pi/sh1106_luma_display_daemon.py &
The display should show "Andino OLED Ready". Update the text file:
echo "Test Display" > /home/pi/display_text.txt
The display should update to "Test Display" and persist.
To update the display text using Node-RED:
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
node-red-start
http://<Raspberry-Pi-IP>:1880
)."Hello from Node-RED"
./home/pi/display_text.txt
.msg.payload
.To ensure the daemon starts automatically on boot:
sudo nano /etc/systemd/system/oled-daemon.service
Add the following:
[Unit]
Description=SH1106 OLED Display Daemon
After=network.target
[Service]
ExecStart=/home/pi/oled_venv/bin/python3 /home/pi/sh1106_luma_display_daemon.py
WorkingDirectory=/home/pi
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi
[Install]
WantedBy=multi-user.target
sudo systemctl enable oled-daemon.service
sudo systemctl start oled-daemon.service
sudo systemctl status oled-daemon.service
The display should show "Andino OLED Ready" or the last text written to /home/pi/display_text.txt
.
sudo i2cdetect -y 1
. Adjust address=0x3C
to 0x3D
if needed.ps aux | grep sh1106_luma_display_daemon
).pi
user and /home/pi/display_text.txt
has 666
permissions.journalctl -u oled-daemon.service
and ensure the virtual environment path is correct.This setup provides a robust solution for displaying persistent text on the 1.3" OLED display, controlled via Node-RED and running reliably as a systemd service.