MicroPython code to list available I2C/SPI and default GPIO assigned
Simple MicroPython code to list available I2C/SPI and default GPIO assigned. Tested on Raspberry Pi Pico 2 (RP2350) running micropython v1.24.0-preview.201.
"""
MicroPython to list available I2C/SPI and default GPIO assigned
"""
import sys, os
import machine
print("====================================")
print(sys.implementation[0], os.uname()[3],
"\nrun on", os.uname()[4])
print("====================================")
print("List available I2C and SPI\n")
print("Available I2C and default GPIO assigned:")
n = 0
while True:
try:
i2c = machine.I2C(n)
print(i2c)
n = n+1
except ValueError as exc:
print("ValueError:", exc)
break
print()
print("Available SPI and default GPIO assigned:")
n = 0
while True:
try:
spi = machine.SPI(n)
print(spi)
n = n+1
except ValueError as exc:
print("ValueError:", exc)
break
Output
====================================
micropython v1.24.0-preview.201.g269a0e0e1 on 2024-08-09 (GNU 14.1.0 MinSizeRel)
run on Raspberry Pi Pico2 with RP2350
====================================
List available I2C and SPI
Available I2C and default GPIO assigned:
I2C(0, freq=400000, scl=5, sda=4, timeout=50000)
I2C(1, freq=400000, scl=7, sda=6, timeout=50000)
ValueError: I2C(2) doesn't exist
Available SPI and default GPIO assigned:
SPI(0, baudrate=1000000, polarity=0, phase=0, bits=8, sck=18, mosi=19, miso=16)
SPI(1, baudrate=1000000, polarity=0, phase=0, bits=8, sck=10, mosi=11, miso=8)
ValueError: SPI(2) doesn't exist
Comments
Post a Comment