From 915228ed079a72c0f343529e23a0086c86017e4f Mon Sep 17 00:00:00 2001 From: Mike Causer Date: Sat, 24 Jun 2017 16:24:00 +1000 Subject: [PATCH 01/10] upip preparation --- LICENSE => LICENSE.txt | 0 README.md | 2 +- setup.py | 23 +++++++++++++++-------- 3 files changed, 16 insertions(+), 9 deletions(-) rename LICENSE => LICENSE.txt (100%) diff --git a/LICENSE b/LICENSE.txt similarity index 100% rename from LICENSE rename to LICENSE.txt diff --git a/README.md b/README.md index 8cb51d6..071603e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# MLX90614 +# MicroPython MLX90614 A MicroPython library for interfacing with a MLX90614 IR temperature sensor. diff --git a/setup.py b/setup.py index caf059a..08acdf5 100644 --- a/setup.py +++ b/setup.py @@ -1,18 +1,25 @@ -from distutils.core import setup +import sys +# Remove current dir from sys.path, otherwise setuptools will peek up our +# module instead of system. +sys.path.pop(0) +from setuptools import setup setup( name='micropython-mlx90614', py_modules=['mlx90614'], - version="1.0", - description="Driver for MicroPython for the MLX90614 IR temperature sensor.", - long_description="""\ -This library lets you communicate with a MLX90614 IR temperature sensor. -""", + version='1.0.0', + description='MicroPython library for the MLX90614 IR temperature sensor.', + long_description='This library lets you communicate with a MLX90614 IR temperature sensor.', + keywords='mlx90614 infrared temperature micropython', + url='https://github.com/mcauser/micropython-mlx90614', author='Mike Causer', author_email='mcauser@gmail.com', + maintainer='Mike Causer', + maintainer_email='mcauser@gmail.com', + license='MIT', classifiers = [ - 'Development Status :: 6 - Mature', - 'Programming Language :: Python :: 3', + 'Development Status :: 5 - Production/Stable', + 'Programming Language :: Python :: Implementation :: MicroPython', 'License :: OSI Approved :: MIT License', ], ) \ No newline at end of file From c501b504da9ff1fb267f0c7817782729a15e000d Mon Sep 17 00:00:00 2001 From: Mike Causer Date: Sun, 25 Jun 2017 00:54:56 +1000 Subject: [PATCH 02/10] Update readme --- README.md | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 071603e..a7df4f2 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,33 @@ A MicroPython library for interfacing with a MLX90614 IR temperature sensor. -For full documentation see http://micropython-mlx90614.rtfd.io/. +![demo](docs/GY-906-MLX90614.jpg) + +#### Examples + +Basic measurement + +``` +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()) +``` -![demo](docs/GY-906-MLX90614.jpg) \ No newline at end of file +Continuous measurement + +``` +import time +import mlx90614 +from machine import I2C, Pin +i2c = I2C(scl=Pin(5), sda=Pin(4)) +sensor = mlx90614.MLX90614(i2c) + +while True: + print(sensor.read_ambient_temp(), sensor.read_object_temp()) + time.sleep_ms(500) +``` + +For full documentation see http://micropython-mlx90614.rtfd.io/. From 5895dbacdaac5d0337a38869f0b366dc8be34742 Mon Sep 17 00:00:00 2001 From: Chris Kuethe Date: Fri, 8 Sep 2017 13:12:46 -0700 Subject: [PATCH 03/10] the '_B_' version has two sensor zones --- mlx90614.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mlx90614.py b/mlx90614.py index 525758a..2ec37cd 100644 --- a/mlx90614.py +++ b/mlx90614.py @@ -6,6 +6,7 @@ _REGISTER_TA = const(0x06) # ambient _REGISTER_TOBJ1 = const(0x07) # object +_REGISTER_TOBJ2 = const(0x08) # object class MLX90614: def __init__(self, i2c, address=0x5a): @@ -29,3 +30,6 @@ def read_ambient_temp(self): def read_object_temp(self): return self.read_temp(_REGISTER_TOBJ1) + + def read_object_temp2(self): + return self.read_temp(_REGISTER_TOBJ2) From 4891369386d0d47d67cd3960260202d5b74a27c1 Mon Sep 17 00:00:00 2001 From: Chris Kuethe Date: Fri, 8 Sep 2017 14:02:58 -0700 Subject: [PATCH 04/10] document the second zone --- docs/mlx90614.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/mlx90614.rst b/docs/mlx90614.rst index 40ee530..2f590f1 100644 --- a/docs/mlx90614.rst +++ b/docs/mlx90614.rst @@ -21,3 +21,7 @@ MLX90614 .. method:: read_object_temp() Get the object temperature in Celcius + + .. method:: read_object_temp2() + + Get the object temperature in Celcius from the second measurement zone From 18758f4eda2c16e056c750ec2c23526b13bc40ff Mon Sep 17 00:00:00 2001 From: Chris Kuethe Date: Fri, 8 Sep 2017 22:42:17 -0700 Subject: [PATCH 05/10] detect single (xAx) and dual (xBx) zone sensors and act accordingly. If having dual zones is important to your use case, check the `.dual_zone` attribute, otherwise you will get a RuntimeError exception --- mlx90614.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mlx90614.py b/mlx90614.py index 2ec37cd..776ee68 100644 --- a/mlx90614.py +++ b/mlx90614.py @@ -12,6 +12,9 @@ class MLX90614: def __init__(self, i2c, address=0x5a): self.i2c = i2c self.address = address + _config1 = i2c.readfrom_mem(address, 0x25, 2) + _dz = ustruct.unpack(' Date: Sun, 10 Sep 2017 18:19:03 -0700 Subject: [PATCH 06/10] Cleanup the second thermopile handling * refer to it as object2_temp rather than object_temp2 * make temperatures accessible as properties of the sensor object * more documentation --- README.md | 2 ++ docs/examples.rst | 6 ++++++ docs/mlx90614.rst | 24 +++++++++++++++++++++--- mlx90614.py | 16 ++++++++++++++-- 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a7df4f2..98634bb 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ 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) ``` Continuous measurement diff --git a/docs/examples.rst b/docs/examples.rst index 67b7bb9..6b98bb0 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -16,6 +16,8 @@ Now, to make basic measurement:: sensor = mlx90614.MLX90614(i2c) print(sensor.read_ambient_temp()) print(sensor.read_object_temp()) + if sensor.dual_zone: + print(sensor.object2_temp) To perform continuous measurement:: @@ -23,3 +25,7 @@ To perform continuous measurement:: while True: print(sensor.read_ambient_temp(), sensor.read_object_temp()) time.sleep_ms(500) + +There are some useful properties: + * ``.dual_zone`` - set to ``True`` if the sensor has two thermopiles + * ``.ambient_temp`` - equivalent to read_ambient_temp(), also works for object and object2 diff --git a/docs/mlx90614.rst b/docs/mlx90614.rst index 2f590f1..aff98fd 100644 --- a/docs/mlx90614.rst +++ b/docs/mlx90614.rst @@ -14,14 +14,32 @@ MLX90614 specifies which sensor to connect to, if you have more than one and have changed their addresses with the ``Addr`` pin. + All temperatures are returned in Celsius. + .. method:: read_ambient_temp() - Get the ambient temperature in Celcius + Get the ambient sensor temperature .. method:: read_object_temp() - Get the object temperature in Celcius + Get the object temperature from the first or only thermopile .. method:: read_object_temp2() - Get the object temperature in Celcius from the second measurement zone + Get the object temperature the second thermopile, if it exists + + .. property:: dual_zone + + set to ``True`` if this sensor has two thermopiles + + .. property:: ambient_temp + + Equivalent to ``read_ambient_temp()`` + + .. property:: object_temp + + Equivalent to ``read_object_temp()`` + + .. property:: object2_temp + + Equivalent to ``read_object2_temp()`` diff --git a/mlx90614.py b/mlx90614.py index 776ee68..1520ffe 100644 --- a/mlx90614.py +++ b/mlx90614.py @@ -6,7 +6,7 @@ _REGISTER_TA = const(0x06) # ambient _REGISTER_TOBJ1 = const(0x07) # object -_REGISTER_TOBJ2 = const(0x08) # object +_REGISTER_TOBJ2 = const(0x08) # object2 class MLX90614: def __init__(self, i2c, address=0x5a): @@ -34,8 +34,20 @@ def read_ambient_temp(self): def read_object_temp(self): return self.read_temp(_REGISTER_TOBJ1) - def read_object_temp2(self): + def read_object2_temp(self): if self.dual_zone: return self.read_temp(_REGISTER_TOBJ2) else: raise RuntimeError("Device only has one thermopile") + + @property + def ambient_temp(self): + return self.read_ambient_temp() + + @property + def object_temp(self): + return self.read_object_temp() + + @property + def object2_temp(self): + return self.read_object2_temp() From 6406ed22b24bd2ccbc08dab4ab21edefc8a1ff59 Mon Sep 17 00:00:00 2001 From: Chris Kuethe Date: Wed, 13 Sep 2017 09:05:59 -0700 Subject: [PATCH 07/10] fix --- docs/mlx90614.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/mlx90614.rst b/docs/mlx90614.rst index aff98fd..97e5b9a 100644 --- a/docs/mlx90614.rst +++ b/docs/mlx90614.rst @@ -24,7 +24,7 @@ MLX90614 Get the object temperature from the first or only thermopile - .. method:: read_object_temp2() + .. method:: read_object2_temp() Get the object temperature the second thermopile, if it exists From f8477e074fb695e99aa2db7f9352c702308bc2dc Mon Sep 17 00:00:00 2001 From: Mike Causer Date: Wed, 8 Aug 2018 02:14:58 +1000 Subject: [PATCH 08/10] Update readme --- README.md | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 98634bb..56a876f 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,41 @@ # MicroPython MLX90614 -A MicroPython library for interfacing with a MLX90614 IR temperature sensor. +A MicroPython library for interfacing with a Melexis MLX90614 IR temperature sensor. + +For example, the [GY-906 module](https://www.aliexpress.com/item/GY-906-MLX90614ESF-New-MLX90614-Contactless-Temperature-Sensor-Module-For-Arduino-Compatible/32474869821.html). ![demo](docs/GY-906-MLX90614.jpg) -#### Examples +## Examples -Basic measurement +Copy the file to your device, using ampy, webrepl or compiling and deploying. eg. +```bash +$ ampy put mlx90614.py ``` + +**Basic measurement** + +```python 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) ``` -Continuous measurement +**Continuous measurement** -``` +```python import time import mlx90614 from machine import I2C, Pin + i2c = I2C(scl=Pin(5), sda=Pin(4)) sensor = mlx90614.MLX90614(i2c) @@ -34,3 +45,29 @@ while True: ``` For full documentation see http://micropython-mlx90614.rtfd.io/. + +## Parts + +* [WeMos D1 Mini](https://www.aliexpress.com/store/product/D1-mini-Mini-NodeMcu-4M-bytes-Lua-WIFI-Internet-of-Things-development-board-based-ESP8266/1331105_32529101036.html) $3.50 USD +* [GY-906 module](https://www.aliexpress.com/item/GY-906-MLX90614ESF-New-MLX90614-Contactless-Temperature-Sensor-Module-For-Arduino-Compatible/32474869821.html) $4.05 USD + +## Connections + +WeMos D1 Mini | GY-906 module +------------- | ---------- +D1 (GPIO5) | SCL +D2 (GPIO4) | SDA +3V3 | VCC +G | GND + +## Links + +* [MLX90614 product page](https://www.melexis.com/en/product/MLX90614/Digital-Plug-Play-Infrared-Thermometer-TO-Can) +* [MLX90614 datasheet](https://www.melexis.com/-/media/files/documents/datasheets/mlx90614-datasheet-melexis.pdf) +* [WeMos D1 Mini](https://wiki.wemos.cc/products:d1:d1_mini) +* [micropython.org](http://micropython.org) +* [Adafruit Ampy](https://learn.adafruit.com/micropython-basics-load-files-and-run-code/install-ampy) + +## License + +Licensed under the [MIT License](http://opensource.org/licenses/MIT). From 6cb5befe34261c82444040d412ebff4a4db8ebfa Mon Sep 17 00:00:00 2001 From: Mike Causer Date: Wed, 8 Aug 2018 02:15:04 +1000 Subject: [PATCH 09/10] Add license --- mlx90614.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/mlx90614.py b/mlx90614.py index 1520ffe..e4caae0 100644 --- a/mlx90614.py +++ b/mlx90614.py @@ -1,5 +1,27 @@ """ -MicroPython driver for MLX90614 IR temperature sensor +MicroPython MLX90614 IR temperature sensor driver +https://github.com/mcauser/micropython-mlx90614 + +MIT License +Copyright (c) 2016 Mike Causer + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. """ import ustruct From 7bb388bd946e39247b92abee7296e68f8cfb2223 Mon Sep 17 00:00:00 2001 From: Borys Szefczyk Date: Sat, 20 Mar 2021 22:48:16 +0100 Subject: [PATCH 10/10] Add support for the MLX90615 sensor --- mlx90614.py | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/mlx90614.py b/mlx90614.py index e4caae0..9036712 100644 --- a/mlx90614.py +++ b/mlx90614.py @@ -26,17 +26,7 @@ import ustruct -_REGISTER_TA = const(0x06) # ambient -_REGISTER_TOBJ1 = const(0x07) # object -_REGISTER_TOBJ2 = const(0x08) # object2 - -class MLX90614: - def __init__(self, i2c, address=0x5a): - self.i2c = i2c - self.address = address - _config1 = i2c.readfrom_mem(address, 0x25, 2) - _dz = ustruct.unpack('