Coder Social home page Coder Social logo

joshuanunn / micropython_mlx90621 Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 18 KB

Micropython module to communicate with Melexis MLX90621 16 x 4 Pixel Thermal Imager

License: GNU General Public License v2.0

Python 100.00%
micropython micropython-driver melexis mlx90621 infrared-sensors thermal-imaging electronics pyboard i2c

micropython_mlx90621's Introduction

Introduction

Micropython module to communicate with Melexis MLX90621 16 x 4 Pixel Thermal Imager.

Usage

This module has been created for, and tested with, the Micropython Pyboard v1.1. Changes to the I2C commands may be needed if moving to another Micropython platform and note that the I2C protocol must be able to support repeated start commands.

Usage of the module requires the creation of an MLX90621 instance (specifying the MLX90621 refresh rate), followed by sensor initialisation, and finally acquiring measurements on demand. Consult the MLX90621 datasheet for details of refresh rate - this defines the rate the sensor samples at, but it is up to the user how frequently new results are pulled from the device itself, and therefore limited to the processing overhead of each sensor_read sequence.

The results of the latest measurement are held in two internal 4 x 16 arrays in the class instance, and are available as either floats (as degrees C) or integers (as 10 x degrees C to provide more precision).

# Create MLX90621 instance and initialise sensor at 8 Hz (the MLX90621 is now sampling at 8 Hz)
ir_sensor = MLX90621(refresh_rate=8, i2c=i2c)
ir_sensor.mlx90621_init()

# Read in a single 16 x 4 "frame" of temperature readings (this reads temperatures into python arrays)
ir_sensor.mlx90621_read_ir()

# Access the temperature values for your application (i: 0-3 and j: 0-16)
# degrees C (10x) integers
ir_sensor.temperatures_int[i][j]
# degrees C floats
ir_sensor.temperatures_flt[i][j]

Full Code Example for Micropython Pyboard v1.1

This code should be saved in a file called main.py and should be placed alongside mlx90621.py in the root Pyboard directory

import time
from machine import I2C
from mlx90621 import MLX90621

# Enable I2C bus 1 (X9, X10) on Pyboard v1.1 and set clock rate to 400 kHz
i2c = I2C(1, freq=400000)

# Create MLX90621 instance and initialise sensor
ir_sensor = MLX90621(refresh_rate=8, i2c=i2c)
ir_sensor.mlx90621_init()

# Very basic example of loop to get temperatures and return via serial to terminal
while True:
    ir_sensor.mlx90621_read_ir()
    time.sleep_us(500000) # Long delay to provide sensible screen update
    for i in range(4):
        line = ["{0:.1f}".format(ir_sensor.temperatures_flt[i][j]) for j in range(16)]
        print('\t'.join(line))
    print('') # Print block separator

Acknowledgements

This project is based upon the daemon component of the C implementation 'mlxd' written for the Raspberry Pi, by Chuck Werbick 2015 - https://github.com/alphacharlie/mlxd

micropython_mlx90621's People

Contributors

joshuanunn avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

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.