I'm trying to run a service which uses the UART to control some hardware. The UART is using pins 8/10 (GPIO 14/15).
raspi-config has been used to disable the login shell over serial and enable the serial port hardware (both under Interface Options -> P6 Serial Port). The hardware identifier for the port is "/dev/serial0".
The code works when I am logged in via SSH. I can start the code from the command line, or I can use systemd and I have no issues with the UART.
However, when the Pi first boots, systemd tries to start the code but the UART fails to communicate. Trying to start the code remotely (something like
ssh email@example.com /home/pi/code_to_run) also fails.
When I SSH into the Pi and start the code everything is fine. I can now exit the session and the code will continue to work (either under systemd or starting it via SSH). If I reboot (
sudo reboot) the code will continue to work after the restart. However, if I shutdown (
sudo shutdown now and turn the power off and on) the code does not work until I SSH in and run it once from the command line.
The status of the service:
pi@MTM24:~ $ sudo systemctl status radar_interface.service ● radar_interface.service - Radar Interface Loaded: loaded (/etc/systemd/system/radar_interface.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2020-12-08 16:33:29 GMT; 2min 10s ago Main PID: 359 (radar_inter) Tasks: 1 (limit: 4915) CGroup: /system.slice/radar_interface.service └─359 /home/pi/radar_interface /home/pi/radar_config.txt Dec 08 16:33:31 MTM24 radar_interface: active: T Dec 08 16:33:31 MTM24 radar_interface: running: FAILURE Dec 08 16:33:31 MTM24 radar_interface: 6:
(The last few lines are output from my code, but the "running: FAILURE" is caused by a failure to communicate over UART)
The service file:
pi@MTM24:~ $ sudo systemctl cat radar_interface.service # /etc/systemd/system/radar_interface.service [Unit] Description=Radar Interface [Service] Type=simple ExecStart=/home/pi/radar_interface /home/pi/radar_config.txt Restart=always RestartSec=10 KillMode=process WatchdogSec=5 Nice=-20 [Install] WantedBy=multi-user.target
Update. Having got some more testing time, the UART is sometimes working on startup, sometimes not. Update The sometimes working/sometimes not working persists across reboot. Shutdown and restart returns the code to a non-working state - I've updated the description above