micropython-mlx90614
micropython-mlx90614 copied to clipboard
Errno 5 by useing mlx90614.py
Hey, I tryed to use my mlx90614 but i had some issues by using it. Maybe someone can help?
So i tryed this code from you:
import mlx90614 from machine import I2C, Pin
i2c = I2C(scl=Pin(5), sda=Pin(4)) sensor = mlx90614.MLX90614(i2c)
print(sensor.read_ambient_temp()) print(sensor.read_object_temp()) if sensor.dual_zone: print(sensor.object2_temp)
but i got this Output:
Traceback (most recent call last):
File "
So i added an id = 0 and then i got:
Traceback (most recent call last):
File "
And i was not able to fix this until now. I would be thankful if someone would help me :)
I think that you have a wrong declaration of i2c. Try this:
i2c = I2C(id=0, sda = Pin(4), scl = Pin(5), freq=100000)
Here you can find out working example of mine: https://github.com/jmodrako/astroclouds/blob/main/app/main.py
Hey, @jmodrako, this library was originally written to work with the ESP8266 port and its software I2C. It's been a few years now and I've pivoted all of my projects to the ESP32.
According to the docs, these are the latest I2C init patterns for ESP32. https://docs.micropython.org/en/latest/esp32/quickref.html#software-i2c-bus
# software I2C
from machine import Pin, SoftI2C
i2c = SoftI2C(scl=Pin(5), sda=Pin(4), freq=100000)
# hardware I2C
from machine import Pin, I2C
i2c = I2C(0)
i2c = I2C(1, scl=Pin(5), sda=Pin(4), freq=400000)
I'll update the example code
Also, the datasheet mentions a requirement about the I2C frequency needing to be 100k or less
Sadly none of these examples where working. I am using an raspberry pi pico w and not an ESP32.
I alwasy get Errno5 or some other errors not even the "working example" of @jmodrako where working with my pico. I dont know what i am doing wrong. ^^
I have found my Problem ... I was not using the ADCs. After i switched that all was working just fine.
Code: import mlx90614 import time from machine import SoftI2C, Pin
i2c = SoftI2C(scl=Pin(27), sda=Pin(26), freq=100000) sensor = mlx90614.MLX90614(i2c)
while True: print(sensor.read_object_temp()) time.sleep_ms(500)
Thanks for your fast response!