Metadata-Version: 2.4
Name: gpiozero-sequent-microsystems
Version: 0.1.0
Summary: Sequent Microsystems Multi-IO / Megaind HAT support for gpiozero (pin factories + Potentiometer)
Project-URL: Homepage, https://gitlab.com/alainsanguinetti/gpiozero-sequent
Project-URL: Repository, https://gitlab.com/alainsanguinetti/gpiozero-sequent
Author: Marie Sauzay, Alain Sanguinetti
License-Expression: BSD-3-Clause
License-File: LICENSE
Keywords: gpiozero,i2c,megaind,multiio,raspberry-pi,sequent-microsystems
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development :: Embedded Systems
Classifier: Topic :: System :: Hardware
Requires-Python: >=3.9
Requires-Dist: gpiozero
Requires-Dist: smmegaind
Requires-Dist: smmultiio
Description-Content-Type: text/markdown

# gpiozero-sequent-microsystems

Sequent Microsystems Multi-IO / Megaind HAT support for
[gpiozero](https://gpiozero.readthedocs.io/), as a separate add-on package.
No changes to gpiozero's own source are required — these classes only
extend it (`PiFactory`, `PiPin`, `SmoothedInputDevice`), the same mechanism
any third-party pin factory uses.

## Install

```bash
pip install gpiozero-sequent-microsystems
```

This pulls in `gpiozero`, plus Sequent Microsystems' `smmultiio` and
`smmegaind` Python drivers, all from PyPI. You still need the I2C driver
stack set up on the host board itself (I2C enabled, `build-essential`/
`i2c-tools`) — see Sequent Microsystems' own board documentation for that
part. This isn't Raspberry Pi-only: any SBC that exposes an I2C bus works
(e.g. a Radxa ROCK 4 SE), via the `i2c` factory parameter below.

## Usage

```python
from gpiozero import LED
from gpiozero_sequent_microsystems import MultiIOFactory, Potentiometer

relay_factory = MultiIOFactory(stack=0, pin_type='relay')
analog_factory = MultiIOFactory(stack=0, pin_type='analog_in')

relay = LED(1, pin_factory=relay_factory)
pot = Potentiometer(1, pin_factory=analog_factory, threshold=0.25)
pot._queue.start()

relay.on()
print(pot.read(), "V")
relay.off()
```

`MegaindFactory` works the same way for the Megaind HAT (`pin_type='od'` or
`'opto'`).

Both factories default to I2C bus 1 (the Raspberry Pi's default bus). On
other SBCs where the HATs are wired to a different bus — e.g. bus 7 on a
Radxa ROCK 4 SE — pass `i2c` to select it:

```python
relay_factory = MultiIOFactory(stack=0, pin_type='relay', i2c=7)
od_factory = MegaindFactory(stack=0, pin_type='od', i2c=7)
```

`pin_type='opto'` and `pin_type='led'` work the same way as `'relay'`, and
can drive gpiozero devices like `Button`/`LED` directly:

```python
from gpiozero import Button, LED
from gpiozero_sequent_microsystems import MultiIOFactory

opto_factory = MultiIOFactory(stack=0, pin_type='opto')
led_factory = MultiIOFactory(stack=0, pin_type='led')

button = Button(1, pin_factory=opto_factory)
status_led = LED(1, pin_factory=led_factory)

button.when_pressed = status_led.on
button.when_released = status_led.off
```

For channel families that don't fit gpiozero's pin model (analog outputs,
current loops, RTD probes, servo, motor, quadrature encoders), the factory
exposes lightweight wrapper objects instead, bypassing the `Pin` machinery
entirely:

```python
servo = relay_factory.servo(channel=1)
servo.value = -45.0  # % position, range [-140..140]

rtd = relay_factory.rtd(channel=1)
print(rtd.temperature, "C", rtd.resistance, "ohm")
```

`MegaindFactory` has the same full set of wrapper methods for the Megaind
HAT (`led()`, `analog_in()`, `analog_out()`, `current_in()`,
`current_out()`, plus board-level `rtc()`, `watchdog()` and
`one_wire_bus()`):

```python
from gpiozero_sequent_microsystems import MegaindFactory

od_factory = MegaindFactory(stack=0, pin_type='od')

led = od_factory.led(channel=1)
led.on()

# differential=True reads -10..10V instead of 0..10V
analog = od_factory.analog_in(channel=1, differential=True)
print(analog.value, analog.volts, "V")

current = od_factory.current_out(channel=1)
current.milliamps = 12.0

rtc = od_factory.rtc()
print(rtc.datetime)

watchdog = od_factory.watchdog()
watchdog.period = 60
watchdog.reload()

bus = od_factory.one_wire_bus()
for sensor in bus:
    print(sensor.temperature, "C")
```

`MegaindFactory` also exposes read-only board diagnostics as properties:
`firmware_version`, `raspberry_voltage`, `power_voltage`, `cpu_temperature`.

## Examples

The [`examples/`](examples/) directory has runnable scripts demonstrating
both HATs, each verified against real hardware. Each board also gets its
own standalone example, so you don't need both HATs to try one out:

- **`relay_potentiometer.py`** (Multi-IO only) — reads a potentiometer and
  switches a relay on/off around a voltage threshold.
- **`led_array_flash.py`** (Multi-IO only) — chases the status LEDs one at
  a time, then flashes them all together via the bulk bitmask helpers.
- **`megaind_analog_pwm_threshold.py`** (Megaind only) — reads Megaind's
  own analog input to dim a PWM LED and drive a threshold indicator.
- **`megaind_led_flash.py`** (Megaind only) — the Megaind counterpart to
  `led_array_flash.py`.
- **`dual_relay_pwm_led.py`** (both boards) — a potentiometer on the
  Multi-IO HAT drives a Megaind PWM LED and a pair of Multi-IO relays.

Run any of them directly, e.g.:

```bash
python examples/relay_potentiometer.py
```
