Closed hathach closed 1 year ago
@ita1024 one thing I still haven't tested is reading actual sensor data. I have lots of sensor, but I don't quite sure which tools/driver/script that can be used to e.g print out temperature from sensor. Do you have any suggestion ?
@hathach It works on my computer
I created an Arduino project using the three new files that you provided, then uploaded the result successfully to an Adafruit Trinket M0.
$ ls ~/Arduino/offi2c
Adafruit_WireUSB.cpp Adafruit_WireUSB.h offi2c.ino
The following Python example uses the sht31 sensor:
#! /usr/bin/env python3
#
# before running, install required libraries:
# pip3 install adafruit-circuitpython-sht31d
# pip3 install adafruit-extended-bus
import adafruit_sht31d, adafruit_extended_bus, time
sensor = adafruit_sht31d.SHT31D(adafruit_extended_bus.ExtendedI2C(22))
while 1:
print(sensor.temperature, sensor.relative_humidity)
time.sleep(1)
After connecting the trinket to my computer, the temperature and humidity are detected correctly:
# dmesg -T
[Wed Mar 15 22:50:44 2023] i2c-tiny-usb 1-1.1:1.2: version 1.00 found at bus 001 address 005
[Wed Mar 15 22:50:44 2023] i2c i2c-22: connected i2c-tiny-usb device
# ./sht.py
20.802319371328295 46.86198214694438
20.802319371328295 46.8711375600824
20.818341344319833 46.91386282139315
20.802319371328295 46.927595941100176
20.78629739833677 46.857404440375372
For other i2c sensors, you will need a corresponding application or library (in Python, C, ...). There is no generic solution.
@ita1024 thank you, I am able to get it running with BME280, with extended bus we could reuse lots of Adafruit CircuitPython driver lib !! Considering to make it as part of built-in class driver.
merged as it is for now (as example) since I have to switch to other works, will re-visit to make it as part of class driver later on
Thank you for the additional sensor example in the documentation, and for having this merged! :heart:
based on suggestion in #252, this PR add example to implement i2c-tiny-usb adapter using vendor API that works with Linux driver. close #252
UPDATE: This works so well, that I am considering to make it as part of built-in class driver of this library (tentative)