Home Autostarting Uctronics Raspberry Pi OLED Display
Post
Cancel

Autostarting Uctronics Raspberry Pi OLED Display

This is a quick setup for both the Uctronics display code, and the startup service. I will also give an example using rc.local.

Preparing the Pi

You will need to activate I2C on your raspberry pi. This can be done using the following command, and then navigating the menu to Interface Options > I2C and enabling the interface.

1
sudo raspi-config

Creating the Binary

First, you will need to pull down the Uctronics code. I feel like they change the repository names so I have forked the repo. Use the following command to pull down my fork, or follow the link and github to Uctronics codebase.

1
git clone https://github.com/BinaryPatrick/U6143_ssd1306.git

Once it’s in place, you will need to navigate to the C folder inside

1
cd ./U6143_ssd1306/C/

Then you can use the make command to compile to C code for your architecture.

1
sudo make clean && sudo make

Once the binary is created you should see a new file named display in the folder with the execute permission set. Ensure it works by running the following command.

1
./display

You should see the screen come to life and start displaying status about the raspberry pi. CTRL+C will stop the script running. The OLED screen will freeze in whatever state it was in. As far as I can tell this is normal. The screen won’t clear until it loses power.

Now that you’ve compiled and tested the file, it will need to be copied to the user space binary folder.

1
sudo mv ./display /usr/bin/uctronics-display

Note that the binary is renamed to uctronics-display with the command

Autostart

Now that the binary is in place, we need to configure a way to start it automatically.

rc.local

The easiest way to configure the binary to run automatically is to add a line to the rc.local file.

1
sudo nano /etc/rc.local

Add a line at the bottom before exit 0.

1
/usr/bin/uctronics-display &

The ampersand at the end ensures the binary starts as a background task, allowing the script to continue and exit with state 0.

When you reboot, you should see the screen start automatically.

Creating a Service

Navigate to the systemd system folder.

1
cd /etc/systemd/system

Once there, create a new service file.

1
sudo nano uctronics-display.service
1
2
3
4
5
6
7
8
9
10
11
12
13
[Unit]
Description=UCTRONICS OLED Display Service
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=patrick
ExecStart=/usr/bin/uctronics-display

[Install]
WantedBy=multi-user.target

Now you can start your service and enable it’s run on startup with the following commands.

1
2
sudo systemctl start uctronics-display
sudo systemctl enable uctronics-display

Now you can check the status of your service with the following command.

1
sudo systemctl status uctronics-display

When you reboot, you should see the screen start automatically.

This post is licensed under CC BY 4.0 by the author.