2x I2C Connection - Invalid Pin Error

I am connecting 2x (in the end 4) BNO85 IMUs to Raspberry Pi Pico W using I2C. I can connect one BNO85 with GP8 & GP9, though when I go to connect the other BNO85 I receive a “ValueError: invalid pins”. I have tried pins GP20 with GP21 and pins GP26 with GP27 but the same error occurs. Any helps greatly appreciated. If any more information is needed, let me know.

Can you link the BN0085 device you are using. And maybe the Python code you are using.
I2C works with an addressing scheme, each device will need its own address.

The Adafruit guide for their 9-DOF Orientation IMU Fusion Breakout - BNO085 says only two addresses can be used. But this might not be the device you are using.

The Core Electronics web page says the device has an SPI interface. This may be the reason for invalid pins, the SPI pins are different than I2C. Micropython knows which pins should be used, so flags an error if the pin designations are incorrect.

The following Python program will show the I2C devices on the bus.

import machine

i2c=machine.I2C(0, sda=machine.Pin(8), scl=machine.Pin(9), freq=400000)
 
print('I2C address:')
print('Dec Hex')

devices = i2c.scan()
for i in devices:

    print(i,hex(i))

1 Like

Thanks James.

I am using - 9-DOF Orientation IMU Fusion Breakout - BNO085

See attached, note not correct error message.



Start of 3rd photo has I2C definitions

Hi @Mitchell258024
currently you have:
i2c2 = busio.I2C(board.GP20, board.GP21, frequency=800_000)

I think this is wrong for two reasons:

  • it looks like CircuitPython busio.I2C is expecting the pins to be ordered SCL, SDA. Similar to your setup of i2c1 where the first argument is the SCL pin.
  • these pins are for the I2C0 bus, which has already been initialised on GP9, GP8. I2C0 cannot be reused.

so you might want to modify the initialisation of i2c2 to be as follows
i2c2 = busio.I2C(board.GP27, board.GP26, frequency=800_000)

I use GP27, GP26 in the order SCL, SDA and have selected pins from the I2C1 bus


To avoid ambiguity, it might be best to use bus names consistent with the pinout diagram. Here’s an alternative initialisation that might reduce confusion. Of course, you’ll have to update the rest of your code.

i2c0 = busio.I2C(board.GP9, board.GP8, frequency=800_000)
i2c1 = busio.I2C(board.GP27, board.GP26, frequency=800_000)
2 Likes

I think @Michael has hit on the problem which would explain the invalid pin error.
CircuitPython should be installed on the Pico. I have next to no experience with CircuitPython.

The way the Pico pinout is shown by the Raspberry Pi corporation can be confusing. The Pico has two I2C interfaces which can be allocated to particular pins, once allocated the other pins are available for anything else. Probably you already know all this.

Cheers
Jim

2 Likes

Epic, works well, thank you… Is there a way to use the information from 2 more BNO85’s - Via the pico W? Note these two BNO85’s will also transmit information to another pico W which again will be linked to an additional 2x BNO85’s

@James46717 I’m really sry to interrupt your conversation but sir is there any way i can contact you, maybe via mail? I’m 17 and i want to build something I’m facing some issue which i think you can help me, I’ve tried my best but got no luck, it’s regarding wireless communication between 2 pico Ws (without any other external wifi network, just the 2 picos communicating independently)
Regards

1 Like

@Aarav270150 This would be a starting point.

Just post in that thread.

Cheers
Jim

2 Likes

Hi @Aarav270150, welcome to the forums!

James has suggested an awesome forum post that’s definitely worth reading through and adding to if you need.

Alternatively, if you think your issue is different enough feel free to create your own topic on this matter and we will be sure to dive in with a response!

There is a tutorial on how to make a forum post here.

1 Like

okk thank you

1 Like