rPi Systemd help

I am trying to get the python script @Peter_Johnson wrote for the color sensor running on a raspberry pi imaged with wpilib at startup. I am not running it in the vision app as that is already used.

I was following the steps for starting up in systemd detailed here Five Ways to Run a Program On Your Raspberry Pi At Startup

my .service file looks like

pi@wpilibpi(ro):~$ cat /lib/systemd/system/colorSensor.service
Description=Color Sensor

ExecStart=/usr/bin/python3.7 rpi-colorsensor.py

After reboot if I run sudo systemctl I get

  busybox-klogd.service       loaded active exited    LSB: Starts klogd
  busybox-syslogd.service     loaded active running   LSB: Starts syslogd
● colorSensor.service         loaded failed failed    Color Sensor
  console-setup.service       loaded active exited    Set console font and keym

If I change my .service file to add > /home/pi/colorSensor.log 2>&1 no file shows up.

I am not a linux guy nor python so any help is appreciated.

Before I tried to daemonize this I could run the /usr/bin/python3.7 rpi-colorsensor.py and get meaningful results (I have some prints that aren’t in Peters project just so I could know it is working.

try running service colorSensor status or systemctl status colorSensor.service it should print out any errors

1 Like

Thank you. This gave me what I needed. I forgot the path to my script
My ExecStart should have been
ExecStart=/usr/bin/python3.7 /home/pi/rpi-colorsensor.py

Glad you got it working with systemd. Note the readme also has the configuration steps needed to make it a background service using svc (which is how the vision program is started).

I guess I missed that update this morning, still had the readme from yesterday morning up in my browser

Ok, trying to move to the pi 4 we will be using and having some issues. I only have one thing plugged in and am trying to run foreground not daemon yet

pi@wpilibpi(ro):~$ /usr/bin/python3.7 rpi-colorsensor.py
Setting up NetworkTables client for team 5013
Unknown device found with same I2C addres as REV color sensor
Traceback (most recent call last):
  File "rpi-colorsensor.py", line 484, in <module>
    color = sensor1.getColor()
  File "rpi-colorsensor.py", line 266, in getColor
    return Color(r / mag, g / mag, b / mag)
ZeroDivisionError: division by zero

boot config for a 4 setup

pi@wpilibpi(ro):~$ cat /boot/config.txt
# For more options and information see
# http://rpf.io/configtxt
# Some settings may impact device functionality. See link above for details

# uncomment if you get no picture on HDMI for a default "safe" mode

# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan

# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border

# uncomment to force a console size. By default it will be display's size minus
# overscan.

# uncomment if hdmi display is not detected and composite is being output

# uncomment to force a specific HDMI mode (this will force VGA)

# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes

# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display

# uncomment for composite PAL

#uncomment to overclock the arm. 700 MHz is the default.

# Uncomment some or all of these to enable the optional hardware interfaces

# Uncomment this to enable infrared communication.

# Additional overlays and parameters are documented /boot/overlays/README

# Enable audio (loads snd_bcm2835)

# Enable camera

# Enable DRM VC4 V3D driver on top of the dispmanx display stack


I don’t have to do the 3 part on the 4 do i? when I did my session froze up

So it worked on the 3 but not the 4? You might try turning on I2C via the raspi-config method, potentially the config is a little different? Also the I2C bus numbering could conceivably be different between the two. My Pi4 recently died so I don’t have a good way to test :frowning:

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.