Skip to content

Commit 4133421

Browse files
committed
add new article
1 parent d721dcf commit 4133421

File tree

2 files changed

+124
-2
lines changed

2 files changed

+124
-2
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
---
2+
layout: post
3+
title: "Setting up Uctronics OLED display with a startup service"
4+
date: 2023-02-26 12:00:00 -0500
5+
category: "Service Setup"
6+
tags: ['raspberry pi', 'uctronics']
7+
---
8+
9+
This is a quick setup for both the Uctronics display code, and the startup service. I will also give an example using `rc.local`.
10+
11+
<!--more-->
12+
13+
## Preparing the Pi
14+
15+
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.
16+
17+
```bash
18+
sudo raspi-config
19+
```
20+
21+
## Creating the Binary
22+
23+
First, you will need to pull down the Uctronics code. I feel like they change the repository names so [I have forked the repo](https://github.com/BinaryPatrick/U6143_ssd1306). Use the following command to pull down my fork, or follow the link and github to Uctronics codebase.
24+
25+
```bash
26+
git clone https://github.com/BinaryPatrick/U6143_ssd1306.git
27+
```
28+
29+
Once it's in place, you will need to navigate to the `C` folder inside
30+
31+
```bash
32+
cd ./U6143_ssd1306/C/
33+
```
34+
35+
Then you can use the `make` command to compile to C code for your architecture.
36+
37+
```bash
38+
sudo make clean && sudo make
39+
```
40+
41+
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.
42+
43+
```bash
44+
./display
45+
```
46+
47+
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.
48+
49+
Now that you've compiled and tested the file, it will need to be copied to the user space binary folder.
50+
51+
```bash
52+
sudo mv ./display /usr/bin/uctronics-display
53+
```
54+
55+
> Note that the binary is renamed to `uctronics-display` with the command
56+
{: .prompt-warning }
57+
58+
## Autostart
59+
60+
Now that the binary is in place, we need to configure a way to start it automatically.
61+
62+
### rc.local
63+
64+
The easiest way to configure the binary to run automatically is to add a line to the `rc.local` file.
65+
66+
```bash
67+
sudo nano /etc/rc.local
68+
```
69+
70+
Add a line at the bottom before `exit 0`.
71+
72+
```text
73+
/usr/bin/uctronics-display &
74+
```
75+
76+
The ampersand at the end ensures the binary starts as a background task, allowing the script to continue and exit with state 0.
77+
78+
When you reboot, you should see the screen start automatically.
79+
80+
### Creating a Service
81+
82+
Navigate to the systemd system folder.
83+
84+
```bash
85+
cd /etc/systemd/system
86+
```
87+
88+
Once there, create a new service file.
89+
90+
```bash
91+
sudo nano uctronics-display.service
92+
```
93+
94+
```text
95+
[Unit]
96+
Description=UCTRONICS OLED Display Service
97+
After=network.target
98+
StartLimitIntervalSec=0
99+
[Service]
100+
Type=simple
101+
Restart=always
102+
RestartSec=1
103+
User=patrick
104+
ExecStart=/usr/bin/uctronics-display
105+
106+
[Install]
107+
WantedBy=multi-user.target
108+
```
109+
110+
Now you can start your service and enable it's run on startup with the following commands.
111+
112+
```bash
113+
sudo systemctl start uctronics-display
114+
sudo systemctl enable uctronics-display
115+
```
116+
117+
Now you can check the status of your service with the following command.
118+
119+
```bash
120+
sudo systemctl status uctronics-display
121+
```
122+
123+
When you reboot, you should see the screen start automatically.

_posts/2023-1-1-lxc-docker-setup.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ Now check to make sure v2 is installed
5656

5757
```bash
5858
docker compose version
59-
# Docker Compose version 2.14.2
6059
```
6160

6261
## Run Docker from a non-root user without sudo
@@ -65,4 +64,4 @@ docker compose version
6564
sudo usermod -aG docker $USER
6665
```
6766

68-
You'll need to logout and log back in for the change to take effect
67+
You'll need to logout and log back in for the change to take effect

0 commit comments

Comments
 (0)