Convert i2c.sh to Python#401
Merged
Merged
Conversation
Modernized port of the I2C-enable installer. The original 363-line Pimoroni-template script carried a large amount of dead scaffolding (Wheezy/Jessie/Squeeze checks, armv6 detection, the no-device-tree branch, the legacy i2c-bcm2708 module and raspi-blacklist.conf handling) that no longer applies to current Raspberry Pi OS. The modern equivalent is small: enable I2C via raspi-config's do_i2c, and ensure the i2c-dev character interface loads at boot so /dev/i2c-* is available. Uses append_if_missing (adafruit-python-shell >= 1.14.0) for the /etc/modules entry.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a modern Python replacement for the legacy i2c.sh installer, focusing solely on enabling I2C on current Raspberry Pi OS using raspi-config and ensuring the i2c-dev interface is available.
Changes:
- Adds
i2c.pythat enables I2C viashell.run_raspi_config("do_i2c 0"). - Ensures
/etc/modulescontainsi2c-dev(idempotently) and loads it immediately viamodprobe. - Preserves the “trusted source” warning + confirmation prompt and offers a reboot prompt at the end.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
makermelissa
approved these changes
Jun 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Converts
i2c.shtoi2c.py, modernized for current Raspberry Pi OS.What changed
The original 363-line script was the Pimoroni installer template, but its actual job is small: enable I2C. Most of it was scaffolding that no longer applies to current Pi OS:
i2c-bcm2708module name andraspi-blacklist.confhandlingFollowing the repo's modernization approach for these conversions,
i2c.pydoes the modern equivalent:shell.run_raspi_config("do_i2c 0")— raspi-config performs thedtparam=i2c_arm=ondevice-tree edit and loads the kernel module (same pattern asarcade-bonnet.py,joy-bonnet.py,raspi-blinka.py).shell.append_if_missing("/etc/modules", "i2c-dev")+modprobe i2c-dev— ensures thei2c-devcharacter interface is available at boot so/dev/i2c-*exists for i2cdetect / Blinka / user tools.Uses
append_if_missing, which is inadafruit-python-shell >= 1.14.0.Testing
Hardware-tested on a Raspberry Pi 5 (Trixie):
dtparam=i2c_arm=off,i2c-devremoved from/etc/modules,get_i2c= 1).dtparam=i2c_arm=on,i2c-devback in/etc/modules,get_i2c= 0,i2c_devmodule loaded live./etc/modulesentry.ruff format+ruff checkclean.