Skip to content

Issue with i2c setup #4

@vacquah

Description

@vacquah

Hello

I am trying to use this cool library on a raspberrypi 4b with circuitpython. I have two other sensors connected on the i2c working ok. My circuitpython i2c interface is setup like so:

import json
import socket
import time

import adafruit_scd30
import adafruit_sht4x
import board

i2c = board.I2C() 
sht = adafruit_sht4x.SHT4x(i2c)
scd = adafruit_scd30.SCD30(i2c)

So adding the code for sps30 looks like this:

import json
import socket
import time

import adafruit_scd30
import adafruit_sht4x
import board

import sys  # this is not working - greyed out
from sps30 import SPS30

i2c = board.I2C() 
sht = adafruit_sht4x.SHT4x(i2c)
scd = adafruit_scd30.SCD30(i2c)

# sps dust sensor setup
if __name__ == "__main__":
    pm_sensor = SPS30(i2c)
    print(f"Firmware version: {pm_sensor.firmware_version()}")
    print(f"Product type: {pm_sensor.product_type()}")
    print(f"Serial number: {pm_sensor.serial_number()}")
    print(f"Status register: {pm_sensor.read_status_register()}")
    print(
        f"Auto cleaning interval: {pm_sensor.read_auto_cleaning_interval()}s")
    print(f"Set auto cleaning interval: {pm_sensor.write_auto_cleaning_interval_days(2)}s")
    pm_sensor.start_measurement()

This throws an error, because I guess its referencing a different I2C setup in your files?

Traceback (most recent call last):
  File "/opt/piMonitor_env/airmonitor.py", line 111, in <module>
    pm_sensor = SPS30(i2c)
  File "/opt/piMonitor_env/sps30.py", line 50, in __init__
    self.i2c = I2C(bus, address)
  File "/opt/piMonitor_env/i2c/i2c.py", line 11, in __init__
    self.fr = io.open("/dev/i2c-"+str(bus), "rb", buffering=0)
FileNotFoundError: [Errno 2] No such file or directory: '/dev/i2c-<busio.I2C object at 0x7f86cf22b0>'

Any ideas how to use circuitpythons i2c setup?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions