QTPY 2040: DPS310 Sensor: Error: 'busio' is not defined

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
TitaniumTeeth
 
Posts: 4
Joined: Sun Jul 04, 2021 4:45 pm

QTPY 2040: DPS310 Sensor: Error: 'busio' is not defined

Post by TitaniumTeeth »

Hi,

I have an Adafruit QTPY 2040 connected to a DPS310 Pressure sensor via the Stemma QT port with a cable.

I tried running the sample code provided:
---------------------------------

Code: Select all

# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

import time
import board
from adafruit_dps310.basic import DPS310

i2c = busio.I2C(board.SCL1, board.SDA1)
dps310 = DPS310(i2c)

while True:
    print("Temperature = %.2f *C" % dps310.temperature)
    print("Pressure = %.2f hPa" % dps310.pressure)
    print("")
    time.sleep(1.0)
------------------------

I even update the i2c = busio.I2C(board.SCL1, board.SDA1) to SCL1 and SDA1 for the non-board i2c connection (found that in a adafruit forum post)

Still no luck running the code.

I keep getting the error:
File "code.py", line 8, in <module>
NameError: name 'busio' is not defined

I checked and I have the DSP310 modules load in the lib directory.

Any help would be appreciated.
Attachments
Dps310 screenshot.jpg
Dps310 screenshot.jpg (31.77 KiB) Viewed 110 times
Last edited by dastels on Fri Aug 12, 2022 3:51 pm, edited 1 time in total.
Reason: Add code tag

User avatar
dastels
 
Posts: 15659
Joined: Tue Oct 20, 2015 3:22 pm

Re: QTPY 2040: DPS310 Sensor: Error: 'busio' is not defined

Post by dastels »

You need to

Code: Select all

import busio
.
Dave

User avatar
TitaniumTeeth
 
Posts: 4
Joined: Sun Jul 04, 2021 4:45 pm

Re: QTPY 2040: DPS310 Sensor: Error: 'busio' is not defined

Post by TitaniumTeeth »

Dave, Thanks!

I added: import busio and it worked.

It may be useful to put that in the sample code for this sensor found here:

https://learn.adafruit.com/adafruit-dps ... cuitpython

User avatar
dastels
 
Posts: 15659
Joined: Tue Oct 20, 2015 3:22 pm

Re: QTPY 2040: DPS310 Sensor: Error: 'busio' is not defined

Post by dastels »

I don't see where that sample code uses busio.

Dave

User avatar
adafruit2
 
Posts: 22148
Joined: Fri Mar 11, 2005 7:36 pm

Re: QTPY 2040: DPS310 Sensor: Error: 'busio' is not defined

Post by adafruit2 »

you can also use `board.STEMMA_I2C()`

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”