Skip to content

Convert i2c.sh to Python#401

Merged
makermelissa merged 1 commit into
adafruit:mainfrom
makermelissa-piclaw:convert-i2c
Jun 16, 2026
Merged

Convert i2c.sh to Python#401
makermelissa merged 1 commit into
adafruit:mainfrom
makermelissa-piclaw:convert-i2c

Conversation

@makermelissa-piclaw

Copy link
Copy Markdown
Contributor

Converts i2c.sh to i2c.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:

  • Wheezy/Jessie/Squeeze release checks
  • armv6/armhf-only gating
  • the "no Device Tree" branch
  • the legacy i2c-bcm2708 module name and raspi-blacklist.conf handling

Following the repo's modernization approach for these conversions, i2c.py does the modern equivalent:

  • shell.run_raspi_config("do_i2c 0") — raspi-config performs the dtparam=i2c_arm=on device-tree edit and loads the kernel module (same pattern as arcade-bonnet.py, joy-bonnet.py, raspi-blinka.py).
  • shell.append_if_missing("/etc/modules", "i2c-dev") + modprobe i2c-dev — ensures the i2c-dev character interface is available at boot so /dev/i2c-* exists for i2cdetect / Blinka / user tools.
  • Keeps the original "trusted source" warning and continue prompt.

Uses append_if_missing, which is in adafruit-python-shell >= 1.14.0.

Testing

Hardware-tested on a Raspberry Pi 5 (Trixie):

  • Started from a disabled I2C state (dtparam=i2c_arm=off, i2c-dev removed from /etc/modules, get_i2c = 1).
  • Ran the script → dtparam=i2c_arm=on, i2c-dev back in /etc/modules, get_i2c = 0, i2c_dev module loaded live.
  • Idempotent: a second run did not duplicate the /etc/modules entry.
  • Rig reverted to baseline after testing.

ruff format + ruff check clean.

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py that enables I2C via shell.run_raspi_config("do_i2c 0").
  • Ensures /etc/modules contains i2c-dev (idempotently) and loads it immediately via modprobe.
  • 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 makermelissa merged commit c4c9b6c into adafruit:main Jun 16, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants