After every reboot my sensor service fails with no /dev/i2c-1
Facility manager at a hotel, I set up a Pi 4 with a BME280 in our plant room. A Python script reads it and publishes to Hermetry, running as a systemd service. It works until the Pi reboots, then the service dies with:
FileNotFoundError: [Errno 2] No such file or directory: '/dev/i2c-1'
sensor.service: Main process exited, code=exited, status=1/FAILURE
If I SSH in and run sudo modprobe i2c-dev then restart the service, it works until the next reboot. We had a power cut on Sunday and nobody noticed for a day because the board just showed old values.
Did you enable I2C in raspi-config? That should load it at boot.
I did, and I also added dtparam=i2c_arm=on to /boot/config.txt myself to be sure.
maybe put time.sleep(30) at the start of the script so the module has time to load?
Which OS release? If it’s Bookworm, that’s your bug: the file is /boot/firmware/config.txt now, and /boot/config.txt is not read anymore (there’s a note in it saying so). Your line is in a file nobody reads, and raspi-config may have been undone by something else you changed later.
What I’d do:
# /boot/firmware/config.txt
dtparam=i2c_arm=on
# load the char device at boot
echo i2c-dev | sudo tee /etc/modules-load.d/i2c.conf
And make the service survive a slow start instead of dying once:
[Service]
Restart=on-failure
RestartSec=10
Rahul, a sleep would work most days, but Restart= covers this and any other startup race.
About the old values after the power cut: add an offline alarm on the sensor’s profile. Then a dead Pi gets you an alarm instead of a chart that looks normal.
Why does raspi-config not just write both files? Seems like an easy trap.
Megan, spot on. Bookworm, and my line was in the old /boot/config.txt, which has a comment at the top saying it moved, never saw it. Fixed the right file, added the modules-load line and Restart=on-failure, pulled the plug twice, came up fine both times. Offline alarm is set too.
Marcus, raspi-config does write the right one. Emily’s own manual edit was the one in the wrong place.
- You must be logged in to reply to this topic.
Join the conversation
Sign in to ask and answer, like helpful posts and mark the reply that solved your problem. Every contribution earns points and levels.

