On to the next obstacle.
Yes, the hardware I2C defaults work for the official RP2040 board. But there are now many alternative boards available form Adafruit, Sparkfun and others.
Most, if not all, of these offer many multiplexed mappings for the default ports. I am currently working mostly on the Sparkfun Pro Micro RP2040 and the Adafruit QtPy RP2040 boards. The attraction of these boards is a smaller footprint.
For me this is important. And for many MicroPython ports these alternative mappings are available. As best I can tell, these are commonly selected through the machine.Pin class.
The SoftI2C class gets me to the pins that I need to use...
Code: Select all
import rp2
import machine
print("Soft i2c bus: 1")
i2cs = machine.SoftI2C(scl=machine.Pin(17), sda=machine.Pin(16), freq=100000, timeout=200)
output = i2cs.scan()
print(output, len(output))
i = 0
#for i < len(output):
print("I2C Address : " + hex(output[0]).upper())
print("I2C Address : " + hex(output[1]).upper())
# i = i + 1
print("I2C Configuration: " + str(i2cs))
print("Done")
... works as expected: output ...
Code: Select all
Soft i2c bus: 1
[24, 32] 2
I2C Address : 0X18
I2C Address : 0X20
I2C Configuration: SoftI2C(scl=17, sda=16, freq=100000)
Done
>>>
...but for my purposes, this is
neither good nor sufficient.
I need to use the hardware implementation of the I2C drivers, just on supposedly available alternate pins.
Close reading of the documentation for class machine.Pin seems to suggest that alternate pin functionality may be accessed using the Pin.ALT mode setting, at least where it is implemented.
I have tried to use many variations of this code (Warning:
DOES NOT WORK!):
Code: Select all
import rp2
import machine
print("Hardware i2c bus: 1")
pin17 = machine.Pin(17, mode=machine.Pin.ALT)
pin16 = machine.Pin(16, mode=machine.Pin.ALT)
i2cAlt = machine.I2C(id=1, scl=pin17, sda=pin16, freq=100000)
output = i2cAlt.scan()
print(output, len(output))
print("Done")
... all with more or less the same result:
Code: Select all
Hardware i2c bus: 1
Traceback (most recent call last):
File "<stdin>", line 18, in <module>
ValueError: bad SCL pin
>>>
I am not sure if this
can work and I'm just missing something, or if I am on the wrong track altogether.
Perhaps this ability to map alternate pin functionality simply does not exist in the RP2 MicroPython port.
If this does not work for the hardware I2C ports, I imagine that it does not work for any of the alternate functionality mappings in the RP2 port.
If not, this is a serious oversight and precludes my use of MicroPython.
Dave