adafruit / Adafruit_Blinka

Add CircuitPython hardware API and libraries to MicroPython & CPython devices
https://learn.adafruit.com/circuitpython-on-raspberrypi-linux
MIT License
439 stars 327 forks source link

board.I2C() AttributeError: 'module' object has no attribute 'I2C' #690

Closed Miner34dev closed 11 months ago

Miner34dev commented 11 months ago

Hello, i'm trying to use a msa301 on a RPi Pico running Micropython. Sadly, when i try to run the first example, it trows an error:

Traceback (most recent call last):
  File "<stdin>", line 5, in <module>
AttributeError: 'module' object has no attribute 'I2C'

I reinstalled all the libraries 3 times, but it still doesn't work :disappointed:. There is the code i was trying to execute:

import time
import board
import adafruit_msa3xx

i2c = board.I2C()
msa = adafruit_msa3xx.MSA301(i2c)

Can somebody help me?

tannewt commented 11 months ago

Init the I2C with explicit pins using busio.I2C(). The pico doesn't have a default set of pins labeled for I2C.

Miner34dev commented 11 months ago

Ok, now it works.

import time
import board
import busio
import adafruit_msa3xx

i2c = busio.I2C(board.GP1, board.GP0)
msa = adafruit_msa3xx.MSA301(i2c)