I tried using the Raspberry Pi Pico I2C Scanner Code (from hackster.io) earlier but I kept getting
%Run -c $EDITOR_CONTENT
Traceback (most recent call last):
File “”, line 10
SyntaxError: invalid syntax
The code from your link (How To Electronics) was the same apart from the indents.
if len(devices) == 0:
print(“No i2c device !”)
else:
print(‘i2c devices found:’,len(devices))
for device in devices:
print("Decimal address: “,device,” | Hexa address: ",hex(device))
So that is one thing I’ve learnt today … make sure of your indents! I now get
Scan i2c bus…
i2c devices found: 1
Decimal address: 116 | Hexa address: 0x74
Yippee!!
Of course I also learnt that Pin(8) isn’t pin 8!! in the Raspberry Pi Pico I2C Scanner Code
sda=machine.Pin(8)
scl=machine.Pin(9)
But … Pin(8) is not the physical pin 8 but GP8 which is physical pin 11 (ergo Pin(9) = physical pin 12)
So for non programmers where Demo.py has
PINS_BREAKOUT_GARDEN = {“sda”: 4, “scl”: 5}
PINS_PICO_EXPLORER = {“sda”: 8, “scl”: 9}
it might be better written as
PINS_BREAKOUT_GARDEN = {“sda”: 4, “scl”: 5}
#sda = physical pin 6, scl = physical pin 7
PINS_PICO_EXPLORER = {“sda”: 8, “scl”: 9}
#sda = physical pin 11, scl = physical pin 12
To cut a loooooonnnggg story short IT WORKS!!!
Thanks to alphanumeric for all his/her help!!
Andrew