UCTRONICS / U6143_ssd1306

70 stars 88 forks source link

Script fail to start automatically after reboot - Ubuntun Server 22.04 #31

Open pcbpaiva opened 2 years ago

pcbpaiva commented 2 years ago

The script doesn't start automatically on Ubuntu server 22.04 after reboot.

mgiuli commented 2 years ago

I ran into the same issue. After researching various sites, I cobbled together a method that worked for me. I'm posting it below in hopes of helping someone else in the future. Please note that I am not an expert and this method could include steps that are not needed.

To start using the I2C, we have to install some packages before:

sudo apt update sudo apt upgrade -y reboot sudo apt install -y i2c-tools python3-pip After that, we have to install the smbus2 package using pip: sudo pip3 install smbus2

Remaining setup: Environmental configuration

sudo apt install make sudo apt install gcc

Download library

git clone https://github.com/UCTRONICS/U6143_ssd1306.git

Manually create a systemd service We will need to manually create a SystemD service which will start at system boot.

sudo nano /etc/systemd/system/rc-local.service

Now enter the following text, save and close the file. [Unit] Description=/etc/rc.local Compatibility ConditionPathExists=/etc/rc.local

[Service] Type=forking ExecStart=/etc/rc.local start TimeoutSec=0 StandardOutput=tty RemainAfterExit=yes SysVStartPriority=99

[Install] WantedBy=multi-user.target

Open the /lib/systemd/system/rc-local.service file and add the following content at the end of the file.

sudo nano /lib/systemd/system/rc-local.service Paste in the following to the bottom of the file, save, and exit. [Install] WantedBy=multi-user.target Alias=rc-local.service

Create and Edit rc.local file Now we will need to edit the /etc/rc.local file. Issue the following command and press Enter

sudo nano /etc/rc.local Paste in the following, this ensures that the script is bash executable, all bash scripts should have this at the top

!/bin/bash

cd /home/ubuntu/U6143_ssd1306/C sudo make clean sudo make sudo ./display &

save and close the file. We will now need to append permissions to make the newly created file executable. Issue the following command and press Enter

sudo chmod +x /etc/rc.local

Enable the service on boot (enable rc.local with systemd on Ubuntu 20.04) Create a soft link in the /etc/systemd/system directory

sudo ln -s /lib/systemd/system/rc.local.service /etc/systemd/system/

After that, enable the service on system boot

sudo systemctl enable rc-local

Now let’s reboot the system and check to see if the service is working.

Sources: I2C enable Source: https://medium.com/vacatronics/getting-started-with-raspberry-pi-i2c-and-ubuntu-server-eaa57ee0baf2

/etc/rc.local system enable source: https://marsown.com/wordpress/how-to-enable-etc-rc-local-with-systemd-on-ubuntu-20-04/

UCTRONICS Ubuntu Source: https://github.com/UCTRONICS/U6143_ssd1306/tree/master/Ubuntu

noahbrooks commented 1 year ago

I made a script for Ubuntu 22.04 LTS with the default "ubuntu" user.

https://github.com/noahbrooks/U6143_ssd1306_Ubuntu_22.04_LTS_64-bit_ARM