From 5ba4c9667795df4264cf064699473eee1bd1dc51 Mon Sep 17 00:00:00 2001 From: Hel Gibbons Date: Fri, 14 Jun 2024 12:24:10 +0100 Subject: [PATCH 1/4] enable i2c automatically --- pyproject.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index a6a13e5..cf2ed0a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -120,4 +120,7 @@ ignore = [ [tool.pimoroni] apt_packages = [] configtxt = [] -commands = [] +commands = [ + "printf \"Setting up i2c..\\n\"", + "sudo raspi-config nonint do_i2c 0", +] \ No newline at end of file From 45a68d70534b4b94c8394d7370a62a94415b22d7 Mon Sep 17 00:00:00 2001 From: Hel Gibbons Date: Fri, 14 Jun 2024 12:35:38 +0100 Subject: [PATCH 2/4] tweak readme --- README.md | 52 ++++++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 4972c13..7b66060 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,6 @@ This library is also used to power our other Nuvoton-based boards and breakouts! * Weather HAT: https://shop.pimoroni.com/products/weather-hat-only * Inventor HAT Mini: https://shop.pimoroni.com/products/inventor-hat-mini - ### Breakouts * IO Expander Breakout: https://shop.pimoroni.com/products/io-expander @@ -24,41 +23,47 @@ This library is also used to power our other Nuvoton-based boards and breakouts! * RGB Encoder Breakout: https://shop.pimoroni.com/products/rgb-encoder-breakout * MICS6814 3-in-1 Gas Sensor Breakout: https://shop.pimoroni.com/products/mics6814-gas-sensor-breakout +## Installing -# Getting the Library - -**Stable library only (no examples) from PyPi:** - -* Just run `python3 -m pip install pimoroni-ioexpander` +### Full install (recommended): -In some cases you may need to install pip with: `sudo apt install python3-pip` +We've created an easy installation script that will install all pre-requisites and get your IO Expander-based breakout +up and running with minimal efforts. To run it, fire up Terminal which you'll find in Menu -> Accessories -> Terminal +on your Raspberry Pi desktop, as illustrated below: -**Stable library, with latest examples from GitHub:** +![Finding the terminal](http://get.pimoroni.com/resources/github-repo-terminal.png) -* `git clone https://github.com/pimoroni/ioe-python` -* `cd ioe-python` -* `./install.sh` +In the new terminal window type the command exactly as it appears below (check for typos) and follow the on-screen instructions: -**Latest/development library and examples from GitHub:** +```bash +git clone https://github.com/pimoroni/ioe-python +cd ioe-python +./install.sh +``` -* `git clone https://github.com/pimoroni/ioe-python` -* `cd ioe-python` -* `./install.sh --unstable` +**Note** Libraries will be installed in the "pimoroni" virtual environment, you will need to activate it to run examples: +``` +source ~/.virtualenvs/pimoroni/bin/activate +``` -# Configuring your Raspberry Pi +### Development: -## Enable I2C +If you want to contribute, or like living on the edge of your seat by having the latest code, you can install the development version like so: -In order to use the IO Expander, you need to enable the I2C interface of your Raspberry Pi. This can be done in the terminal by running: +```bash +git clone https://github.com/pimoroni/ioe-python +cd ioe-python +./install.sh --unstable +``` -* `sudo raspi-config nonint do_i2c 0` +The install script should do it for you, but in some cases you might have to enable the i2c bus. -Alternatively, you can enable the I2C interface by: -* running `sudo raspi-config` and enabling the option under **Interfacing Options**. -* opening the graphical **Raspberry Pi Configuration** application from the **Preferences** menu. +On a Raspberry Pi you can do that like so: -You may need to reboot after enabling I2C for the change to take effect. +``` +sudo raspi-config nonint do_i2c 0 +``` ## Note for Raspberry Pi 1 @@ -71,7 +76,6 @@ There are various examples to get you started with your IO Expander. With the li To take IO Expander further, the full API is described in the [library reference](/REFERENCE.md), with additional feature specific information found in the [docs folder](/docs). - # Removing the Library To uninstall the library only (keeping all examples): From 182370a32337a3fc82b385a850f4736b115cd33a Mon Sep 17 00:00:00 2001 From: Hel Gibbons Date: Fri, 28 Jun 2024 15:33:05 +0100 Subject: [PATCH 3/4] docs: update readme --- README.md | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 7b66060..ed450f6 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,8 @@ This library is also used to power our other Nuvoton-based boards and breakouts! ## Installing +We'd recommend using this library with Raspberry Pi OS Bookworm or later. It requires Python ≥3.7. + ### Full install (recommended): We've created an easy installation script that will install all pre-requisites and get your IO Expander-based breakout @@ -57,13 +59,19 @@ cd ioe-python ./install.sh --unstable ``` -The install script should do it for you, but in some cases you might have to enable the i2c bus. +## Install stable library from PyPi and configure manually -On a Raspberry Pi you can do that like so: +* Set up a virtual environment: `python3 -m venv --system-site-packages $HOME/.virtualenvs/pimoroni` +* Switch to the virtual environment: `source ~/.virtualenvs/pimoroni/bin/activate` +* Install the library: `pip install pimoroni-ioexpander` -``` -sudo raspi-config nonint do_i2c 0 -``` +In some cases you may need to us `sudo` or install pip with: `sudo apt install python3-pip`. + +This will not make any configuration changes, so you may also need to enable: + +* i2c: `sudo raspi-config nonint do_i2c 0` + +You can optionally run `sudo raspi-config` or the graphical Raspberry Pi Configuration UI to enable interfaces. ## Note for Raspberry Pi 1 @@ -80,7 +88,7 @@ To take IO Expander further, the full API is described in the [library reference To uninstall the library only (keeping all examples): -* Just run `python3 -m pip uninstall pimoroni-ioexpander` +* Just run `pip uninstall pimoroni-ioexpander` Or if you have grabbed the library from Github: From ed0a59eebd465c55648f9bb9f0e43d9d95a39bfa Mon Sep 17 00:00:00 2001 From: Hel Gibbons Date: Wed, 10 Jul 2024 15:23:10 +0100 Subject: [PATCH 4/4] rotary.py - use `interrupt_pin=None` as default (should help with #29 and #30) --- examples/rotary.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/rotary.py b/examples/rotary.py index a26900f..58da087 100755 --- a/examples/rotary.py +++ b/examples/rotary.py @@ -27,7 +27,9 @@ BRIGHTNESS = 0.5 # Effectively the maximum fraction of the period that the LED will be on PERIOD = int(255 / BRIGHTNESS) # Add a period large enough to get 0-255 steps at the desired brightness -ioe = io.IOE(i2c_addr=I2C_ADDR, interrupt_pin=4) +ioe = io.IOE(i2c_addr=I2C_ADDR, interrupt_pin=None) +# If you'd like to use the hardware interrupt pin on your encoder breakout, you can use the following instead: +# ioe = io.IOE(i2c_addr=I2C_ADDR, interrupt_pin=4) # Swap the interrupt pin for the Rotary Encoder breakout if I2C_ADDR == 0x0F: