Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

CLUE i2c change speed
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

CLUE i2c change speed

by drountre on Sun May 03, 2020 5:16 pm

When connecting adafruit_mlx90614 to CLUE, the the i2c default mode of 400k has to be changed to 100k.
I have tried i2c = io.I2C(board.SCL, board.SDA, frequency=100000) and as long as i comment out #from adafruit_clue import clue , clue will print object and ambient temps fine.
When i try them together, if get a "P19 in use" error.
The mlx90614 works great with my other Circuit python boards, but i want to use all the other sensors of the Clue with the mlx90614.
Is there a clue.xxx command that will let me set the i2c speed to 100k?
Thanks
David

drountre
 
Posts: 14
Joined: Tue Jul 16, 2019 9:00 am

Re: CLUE i2c change speed

by danhalbert on Sun May 03, 2020 5:32 pm

Hi - There are two problems:

1. The adafruit_clue library is using `board.I2C()` to get the default I2C object. That grabs the default pins, and your subsequent attempt to use those pins fails.
2. There is no way right now to change an I2C object bus frequency once the I2C object has been created, and there is no way to pass the frequency to `board.I2C(). We might consider adding either or both of these features.

Two solutions:
a. Use two other pins for I2C and create a second I2C bus for the external mlx90614. But it's harder to get to the pins from the edge connector.
b. Modify adafruit_clue to create an I2C object explicitly with the right frequency:
I.e. https://github.com/adafruit/Adafruit_Ci ... ue.py#L202
right now is:
Code: Select all | TOGGLE FULL SIZE
        self._i2c = board.I2C()

and could be changed to:
Code: Select all | TOGGLE FULL SIZE
        self._i2c = busio.I2C(board.SCL, board.SDA, frequency=100000)

When your code needs to use the same I2C bus for the external sensor, use `clue._i2c()` instead of `board.I2C()`.

danhalbert
 
Posts: 2037
Joined: Tue Aug 08, 2017 12:37 pm

Re: CLUE i2c change speed

by drountre on Mon May 04, 2020 8:21 am

danhalber
Thank you for your quick reply...
Below is the (condensed) code i tried and below it is the errno 19 i got, which as i believe is the frequency didn't get changed to 100000.
Did i misunderstand your instructions?
I am connected into the STEMMA QT connector.
Again, thank you for your time.


Code: Select all | TOGGLE FULL SIZE
from adafruit_clue import clue   
import adafruit_mlx90614
class Clue:   
    def __init__(self):
        #self._i2c = board.I2C()
        self._i2c = busio.I2C(board.SCL, board.SDA, frequency=100000)       
mlx = adafruit_mlx90614.MLX90614(clue._i2c) 
print("Ambient Temp:  %0.1f" %mlx.ambient_temperature,"  Object Temp: "," %0.1f"%mlx.object_temperature)


Traceback (most recent call last):
  File "code.py", line 97, in <module>
  File "adafruit_mlx90614.py", line 109, in ambient_temperature
  File "adafruit_mlx90614.py", line 117, in _read_temp
  File "adafruit_mlx90614.py", line 128, in _read_16
  File "adafruit_mlx90614.py", line 127, in _read_16
  File "adafruit_bus_device/i2c_device.py", line 139, in write_then_readinto
OSError: [Errno 19] Unsupported operation

drountre
 
Posts: 14
Joined: Tue Jul 16, 2019 9:00 am

Re: CLUE i2c change speed

by danhalbert on Mon May 04, 2020 9:18 am

You need to replace adafruit_clue.mpy with your own copy of adafruit_clue.py with the `self._i2c =` line fixed. It can be in lib or in the top level folder. Is that what you did, or did you just try to redefine it in your code.py? When you do `from adafruit_clue import clue`, the `clue` variable gets set, and it's too late.

danhalbert
 
Posts: 2037
Joined: Tue Aug 08, 2017 12:37 pm

Re: CLUE i2c change speed

by drountre on Mon May 04, 2020 9:49 am

danhalbert
Yep, I just try to redefine it in my code.py.
I didn't think of using my own edited copy of adafruit_clue.py. (that does makes more sense)
I will give that a go.
Thanks again

drountre
 
Posts: 14
Joined: Tue Jul 16, 2019 9:00 am

Please be positive and constructive with your questions and comments.