forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Labels
bugsupportissues that involve helping a user accomplish a taskissues that involve helping a user accomplish a task
Milestone
Description
CircuitPython version and board name
Adafruit CircuitPython 9.2.6 on 2025-03-23; Waveshare RP2040-Zero with rp2040Code/REPL
import time
import board
import busio
import adafruit_sht31dBehavior
Adafruit CircuitPython 9.2.6 on 2025-03-23; Waveshare RP2040-Zero with rp2040
>>>
soft reboot
Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Traceback (most recent call last):
File "code.py", line 14, in <module>
AttributeError: 'module' object has no attribute 'SHT31D'
Code done running.
Press any key to enter the REPL. Use CTRL-D to reload.
Description
Hello.
Trying to read some I2C sensors with RP2040-Zero but without success.
I always recieve the error: AttributeError: 'module' object has no attribute
In this case since using SHT31, the error is: AttributeError: 'module' object has no attribute 'SHT31D'
On the RP2040 "lib" I have these libraries (version 9.x):
This is the code.py got from https://github.com/adafruit/Adafruit_CircuitPython_SHT31D/blob/main/examples/sht31d_simple_mode.py and I modified only the "i2c" part to be used with RP2040:
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
import time
import board
import busio
import adafruit_bitbangio
import adafruit_sht31d
# Create sensor object, communicating over the board's default I2C bus
i2c = busio.I2C(board.GP29, board.GP28)
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
sensor = adafruit_sht31d.SHT31D(i2c)
print("\033[1mSensor\033[0m = SHT31-D")
print("\033[1mSerial Number\033[0m = ", sensor.serial_number, "\n")
sensor.frequency = adafruit_sht31d.FREQUENCY_1
sensor.mode = adafruit_sht31d.MODE_PERIODIC
for i in range(3):
print("Please wait...", end="\r")
if i == 2:
sensor.heater = True
if i == 1:
time.sleep(4)
print("\033[91mCache half full.\033[0m")
else:
time.sleep(8)
if sensor.heater:
print("\033[1mHeater:\033[0m On ")
sensor.heater = False
print("\033[1mTemperature:\033[0m ", sensor.temperature)
if not sensor.heater:
print("\033[1mHeater:\033[0m Off")
print("\033[1mHumidity:\033[0m ", sensor.relative_humidity, "\n")
sensor.mode = adafruit_sht31d.MODE_SINGLE
Where is the issue?
Many thanks!
Metadata
Metadata
Assignees
Labels
bugsupportissues that involve helping a user accomplish a taskissues that involve helping a user accomplish a task
