Code Monkey home page Code Monkey logo

micropython-mlx90614's Introduction

MicroPython MLX90614

A MicroPython library for interfacing with a Melexis MLX90614 IR temperature sensor.

For example, the GY-906 module.

demo

Examples

Copy the file to your device, using ampy, webrepl or compiling and deploying. eg.

$ ampy put mlx90614.py

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())
if sensor.dual_zone:
    print(sensor.object2_temp)

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/.

Parts

Connections

WeMos D1 Mini GY-906 module
D1 (GPIO5) SCL
D2 (GPIO4) SDA
3V3 VCC
G GND

Links

License

Licensed under the MIT License.

micropython-mlx90614's People

Contributors

boryszef avatar ckuethe avatar mcauser avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

micropython-mlx90614's Issues

OSError 5 when doing i2c.readfrom_mem

Board: Raspberry Pi Pico

Code:

import uos
import machine
import time

print(uos.uname())
print("Freq: "  + str(machine.freq()) + " Hz")

i2c = machine.I2C(0, scl=machine.Pin(5), sda=machine.Pin(4))
print(i2c)

print("Available i2c devices: "+ str(hex(i2c.scan()[0])))

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('<H', _config1)[0] & (1<<6)
		self.dual_zone = True if _dz else False

	def read16(self, register):
		data = self.i2c.readfrom_mem(self.address, register, 2)
		return ustruct.unpack('<H', data)[0]

	def read_temp(self, register):
		temp = self.read16(register);
		# apply measurement resolution (0.02 degrees per LSB)
		temp *= .02;
		# Kelvin to Celcius
		temp -= 273.15;
		return temp;

	def read_ambient_temp(self):
		return self.read_temp(_REGISTER_TA)

	def read_object_temp(self):
		return self.read_temp(_REGISTER_TOBJ1)

	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()
	
sensor = MLX90614(i2c)

while True:
    print(sensor.read_ambient_temp())
    time.sleep(1)

Output:

(sysname='rp2', nodename='rp2', release='1.14.0', version='v1.14 on 2021-02-09 (GNU 10.2.0 MinSizeRel)', machine='Raspberry Pi Pico with RP2040')
Freq: 125000000 Hz
I2C(0, freq=399361, scl=5, sda=4)
Available i2c devices: 0x5a
Traceback (most recent call last):
  File "<stdin>", line 63, in <module>
  File "<stdin>", line 23, in __init__
OSError: 5

OSError: [Errno 5] EIO

Maixpy IDE
Corgidude board

Code

import mlx90614
from machine import I2C
from fpioa_manager import fm

fm.register(14, fm.fpioa.SCCB_SDA)
fm.register(15, fm.fpioa.SCCB_SCLK)

i2c = I2C(I2C.I2C0, freq=100000, scl=15, sda=14)

sensor = mlx90614.MLX90614(i2c)
print(sensor.read_ambient_temp())
print(sensor.read_object_temp())
if sensor.dual_zone:
    print(sensor.object2_temp)

OUTPUT

Traceback (most recent call last):
  File "<stdin>", line 10, in <module>
  File "mlx90614.py", line 37, in __init__
OSError: [Errno 5] EIO
MicroPython v0.5.0-47-ge29a95c42-dirty on 2020-07-24; Sipeed_M1 with kendryte-k210
Type "help()" for more information.

OSError: 5 when i2c is reading from memory

_config1 = i2c.readfrom_mem(address, 0x25, 2)
This line is giving me lots of headache, I've tried using the proposed solution of using machine.SoftI2C instead but the sensor just outputs -273.15 which means that it is reading 0 from the sensor itself. I did an i2cscan and it the sensor is fine.

Anything would be of great help, Thanks. Btw, I'm using the Raspberry Pi Pico

Huge temperatures

Hello, I've tried to use this module but I got huge temperature values, around 1000ÂēC. Which could it be the reason? Does this module work with single zone MLX90614 sensor?

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 "", line 4, in
TypeError: 'id' argument required

So i added an id = 0 and then i got:

Traceback (most recent call last):
File "", line 5, in
File "mlx90614.py", line 76, in init
OSError: [Errno 5] EIO

And i was not able to fix this until now. I would be thankful if someone would help me :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤ī¸ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.