A service interface for one or more Raspberry Pi* SBCs to be monitored & controlled by a Raspberry Pi Pico†, using i2c.
Work in progress. See Hardware & Software Instructions below.
- The RPi* must have GPIO pins 18 & 19 free for use by
pigpio
as SDA & SCL of secondary i2c controller. - RPi4 must have manual installaltion of
pigpio
for compatible i2c use. - Pico† must be running CircuitPython-6.x.
- Pico† must have
adafruit_bus_device
&pico_pi_controller
CircuitPython libraries installed.
* RPi 4/3/Zero, RPi4: GPIO pins 10 & 11; pigpio
enables use of the Broadcom SoC secondary i2c controller as a 'peripheral' device.
† or any CircuitPython-capable MCU.
pip install pico_pi_controller
If using the simple setup of one RPi controlled by a Pico. Additinal RPi may be added by repeating steps 1 & 4.
-
Connect RPi secondary i2c pins to Pico primary i2c pins SDA↔SDA SCL↔SCL GND↔GND:
- On RPi*, connect GPIO pins 18 (SDA), 19 (SCL) and GND (any GND pin), e.g. using Female/Female Jumper Wires; color conventions may be found here.
- On Pico†, connect wires from RPi (above) to the primary i2c bus, board pins 4 (SDA), 5 (SCL), and GND (any GND pin).
-
Plug Pico into RPi USB port, e.g. using MicroB to USB A cable.
-
From RPi, install CircuitPython & CircuitPython Library Bundle onto the Pico:
- On RPi, download CircuitPython & install it on your Pico.
- On RPi, download & unzip CircuitPython Library Bundle, then copy from the
lib
folderadafruit_bus_device
to thelib
folder on your Pico (CIRCUITPY drive).
-
On RPi, install
pico_pi_controller
components.- On RPi, install
pico_pi_controller
(e.g.pip3 install pico_pi_controller
) - On RPi, locate‡ & copy
ppc-daemon.py
to the location of your choice and configure your system(s) to run the script on startup (it's a daemon), then reboot or manually run the daemon.
- On RPi, install
-
From RPi, install
pico_pi_controller
for CircuitPython onto the Pico. 2. On RPi, download & unzippico_pi_controller
for CircuitPython, then copy from thelib
folderpico_pi_controller
to thelib
folder on your Pico (CIRCUITPY drive). -
Unplug the Pico from the RPi USB port and connect it to a reguar USB power source.
* RPi4 uses GPIO pins 10 (SDA), 11 (SCL).
† Other MCU boards will have different pinouts. If using an MCU board with a Qwiic or STEMMA QT connector, e.g. Adafruit Feather RP2040, this cable is useful.
‡ locate the installed files, e.g. in ~/.local/lib/python3.7/site-packages/pico_pi_controller/examples
.
On each RPi, with pigpiod
running, run this example ppc-daemon.py
script:
import pico_pi_controller
mydevice = pico_pi_controller.PPPeripheral(0x13)
Where 0x13
is the chosen unique I2C address of your RPi on the I2C bus where an MCU controller is running (e.g. a Pico running CircuitPython_pico_pi_controller
.
A more sophisticated example:
import pico_pi_controller
import time
import threading
import logging
address=0x13
def i2c_peripheral(address):
global mydevice
mydevice = pico_pi_controller.PPPeripheral(*args, **kwargs)
logging.info("PPC: starting I2C peripheral ",hex(address))
t = threading.Thread(target=i2c_peripheral(address, bosmang=True, UART_TX=8, UART_RX=9, PWR=10, PEN=11)
threads.append(t)
t.start()
while True:
logging.info("PPC: last controller contact",mydevice.last_contact(),"seconds ago.")
sleep(1)
When your device declares itself to be bosmang, it sends its own datetime for setting the controller's RTC. Optionally, a bosmang can send commands to the controller, e.g. to reboot or shutdown any connected RPi. Additionally, bosmang may have its console UART, gpio-poweroff, and PEN pins connected to GPIO pins on the controller which enables the controller to execute a safe shutdown & poweroff plus full poweronn of bosmang.