7 releases
0.2.1 | Oct 4, 2021 |
---|---|
0.2.0 |
|
0.1.1 | Aug 25, 2021 |
0.0.4 | Aug 10, 2021 |
0.0.3 | Jul 29, 2021 |
#624 in Embedded development
173 downloads per month
Used in r-u-still-there
360KB
6.5K
SLoC
mlx9064x
mlx9064x
is a library for using the MLX90640 and MLX90641 thermal cameras from
Melexis. It's no_std
, but these cameras require a fair bit of memory and
processing power to use fully.
This library is still under development, but the final API will be pretty close to the current one.
lib.rs
:
A pure-Rust library for accessing the MLX90640 and MLX90641 (eventually!) thermal cameras over I²C.
These cameras have a large amount of calibration data that must be pre-processed before use, and the output data also requires a somewhat complex process to turn it into temperature data. This crate has two levels of API, a high-level API that handles the calibration data and raw data processing for you, and a low-level API if you need to go beyond what the high-level API can do for you.
This library uses the embedded-hal
I²C traits, meaning you should be able to
use this library on other platforms, as long as there's an embedded-hal
I²C implementation
available. This library is also no_std
compatible (there is a large memory requirement
though).
High-Level API
use std::thread::sleep;
use std::time::Duration;
use mlx9064x::Mlx90640Driver;
use linux_embedded_hal::I2cdev;
let i2c_bus = I2cdev::new("/dev/i2c-1").expect("/dev/i2c-1 needs to be an I2C controller");
// Default address for these cameras is 0x33
let mut camera = Mlx90640Driver::new(i2c_bus, 0x33)?;
// A buffer for storing the temperature "image"
let mut temperatures = vec![0f32; camera.height() * camera.width()];
camera.generate_image_if_ready(&mut temperatures)?;
// Default frame rate is 2Hz
sleep(Duration::from_millis(500));
camera.generate_image_if_ready(&mut temperatures)?;
This snippet gives a quick example of using the high-level API with an MLX90640 on Linux. The
camera is using the I²C bus #1 (/dev/i2c-1
) and the default I²C address (0x33
). The
calibration data is loaded from the camera over I²C and saved into an
Mlx90640Calibration
within camera
. A destination buffer is
created to store the temperature data from the camera using a Vec
, and then the temperature
data is retrieved twice to cover both subpages, with a delay
between the accesses to allow the next frame of data to become available.
The high-level API is exposed through CameraDriver
, and also makes it easy to configure the
camera settings like frame rate or access mode. If you need to tailor the functionality beyond
what CameraDriver
provides for you, the low-level API is probably a better choice for you.
Low-Level API
The low-level API is the foundation for the high-level API, exposed for those cases where a
more customized approach is needed. A common example is customizing how the calibration data is
loaded. To reduce startup time and memory usage, you might want to pre-process the calibration
data for a specific camera and store it in a microcontroller's flash memory. This can be done
by implementing CalibrationData
. Because CameraDriver
is generic
over CalibrationData
, you can use your custom CalibrationData
with the rest of the
high-level API with almost no changes.
Most users of the low-level API will probably find the common
, register
, and
calculations
modules most relevant to their needs, with camera-model specific constants and
types available in the mlx90640
and mlx90641
modules.
Subpages and Access Patterns
A significant difference between these Melexis cameras and other common thermal cameras is how the Melexis cameras update their image data. Each frame, one [subpage][Subpage] of data is updated. For the MLX90640 each subpage covers half of the pixels, and the [access pattern][AccessPattern] determines how the pixels are divided between the subpages. The MLX90641's subpages cover all of the pixels (and the access pattern should not be changed from interleave).
Dependencies
~1.4–2.2MB
~48K SLoC