fossasia / pslab-python

Python Library for PSLab Desktop: https://pslab.io
GNU General Public License v3.0
1.63k stars 225 forks source link

MLX90614: migrate to new I2C API #181

Closed orangecms closed 1 year ago

orangecms commented 3 years ago

This if for #182. With the changes, I can read from the sensor again. I'm not sure what to do about the baud rate change though. It's not strictly necessary.

Here's how:

from pslab import ScienceLab
from pslab.external.MLX90614 import MLX90614
from time import sleep

psl = ScienceLab()  # This initializes the I2C bus.
sensor = MLX90614()

data = sensor.getAmbientTemperature()
print(data)

sleep(2)

data = sensor.getObjectTemperature()
print(data)

yields

25.32000000000005
21.500000000000057

:tada:

orangecms commented 3 years ago

@bessman I took the i2c bus part from your patch to migrate the SSD1306 driver. Now I'm not sure where I got it from. For reference, see #184

Edit: found it, the branch is in here and was for some reason even targeted by the PR automatically; I looked at your fork only :sweat_smile: https://github.com/fossasia/pslab-python/commits/ssd1306

bessman commented 3 years ago

Data sheet: https://www.sparkfun.com/datasheets/Sensors/Temperature/MLX90614_rev001.pdf