Remarks

Mlx90640
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Camera.Mlx90640
Mlx90640 sensor;

public MeadowApp()
{
    Console.WriteLine("Initialize hardware...");

    var i2cBus = Device.CreateI2cBus(I2cBusSpeed.Fast);
    sensor = new Mlx90640(i2cBus, measurementUnit: Mlx90640.Units.Celsius);
    sensor.Initialize();

    //View sensor data as temperature values
    Run(showTempArrayAsAsciiArt: false);
}

void Run(bool showTempArrayAsAsciiArt)
{
    Console.WriteLine("Run sample...");

    float[] frame;

    Console.WriteLine($"Serial #:{sensor.SerialNumber}");

    sensor.SetMode(Mlx90640.Mode.Chess);
    Console.WriteLine($"Current Mode: {sensor.GetMode()}");  

    sensor.SetResolution(Mlx90640.Resolution.EighteenBit);
    Console.WriteLine($"Current resolution: {sensor.GetResolution()}");

    sensor.SetRefreshRate(Mlx90640.RefreshRate.TwoHZ);
    Console.WriteLine($"Current frame rate: {sensor.GetRefreshRate()}");

    Console.WriteLine($"Broken Pixels: {sensor.Config.BrokenPixels.Count}");
    Console.WriteLine($"Outlier Pixels: {sensor.Config.OutlierPixels.Count}");
    Console.WriteLine($"Broken Pixels has adjacent broken pixel: {sensor.Config.BrokenPixelHasAdjacentBrokenPixel}");
    Console.WriteLine($"Broken Pixels has adjacent Outlier pixel: {sensor.Config.BrokenPixelHasAdjacentOutlierPixel}");
    Console.WriteLine($"Outlier Pixels has adjacent Outlier pixel: {sensor.Config.OutlierPixelHasAdjacentOutlierPixel}");

    Thread.Sleep(2000);

    while (true)
    {
        Thread.Sleep(1000);

        frame = sensor.Read();

        Console.WriteLine();

        //Print out each value
        for (byte h = 0; h < 24; h++)
        {
            for (byte w = 0; w < 32; w++)
            {
                float t = frame[h * 32 + w];
                //View sensor data as ascii art. It is easier to see shapes, like your fingers.
                if (!showTempArrayAsAsciiArt)
                {
                    //Write the Temp value
                    Console.Write($"{t:0},");
                }
                else
                {
                    //Write the ascii art character
                    char c = '&';
                    if (t < 68) c = ' ';
                    else if (t < 73.4) c = '.';
                    else if (t < 77) c = '-';
                    else if (t < 80.6) c = '*';
                    else if (t < 84) c = '+';
                    else if (t < 87) c = 'x';
                    else if (t < 91) c = '%';
                    else if (t < 95) c = '#';
                    else if (t < 98.6) c = '$';
                    Console.Write(c);
                }
            }

            Console.WriteLine();
        }
   }
}

Sample project(s) available on GitHub

|

Code Example

Mlx90640 sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize...");

    var i2cBus = Device.CreateI2cBus(I2cBusSpeed.Fast);
    sensor = new Mlx90640(i2cBus);

    return Task.CompletedTask;
}

public override Task Run()
{
    bool showTempArrayAsAsciiArt = false;

    Resolver.Log.Info("Run sample...");

    float[] frame;

    Resolver.Log.Info($"Serial #:{sensor.SerialNumber}");

    sensor.SetMode(Mlx90640.Mode.Chess);
    Resolver.Log.Info($"Current Mode: {sensor.GetMode()}");

    sensor.SetResolution(Mlx90640.Resolution.EighteenBit);
    Resolver.Log.Info($"Current resolution: {sensor.GetResolution()}");

    sensor.SetRefreshRate(Mlx90640.RefreshRate._2hz);
    Resolver.Log.Info($"Current frame rate: {sensor.GetRefreshRate()}");

    Resolver.Log.Info($"Broken Pixels: {sensor.Config.BrokenPixels.Count}");
    Resolver.Log.Info($"Outlier Pixels: {sensor.Config.OutlierPixels.Count}");
    Resolver.Log.Info($"Broken Pixels has adjacent broken pixel: {sensor.Config.BrokenPixelHasAdjacentBrokenPixel}");
    Resolver.Log.Info($"Broken Pixels has adjacent Outlier pixel: {sensor.Config.BrokenPixelHasAdjacentOutlierPixel}");
    Resolver.Log.Info($"Outlier Pixels has adjacent Outlier pixel: {sensor.Config.OutlierPixelHasAdjacentOutlierPixel}");

    Thread.Sleep(2000);

    while (true)
    {
        Thread.Sleep(1000);

        frame = sensor.ReadRawData();

        Resolver.Log.Info("");

        //Print out each value
        for (byte h = 0; h < 24; h++)
        {
            StringBuilder logLine = new StringBuilder();
            for (byte w = 0; w < 32; w++)
            {
                float t = frame[h * 32 + w];
                //View sensor data as ascii art. It is easier to see shapes, like your fingers.
                if (!showTempArrayAsAsciiArt)
                {
                    //Write the Temp value
                    logLine.Append($"{t:0},");
                }
                else
                {
                    //Write the ascii art character
                    char c = '&';
                    if (t < 68) c = ' ';
                    else if (t < 73.4) c = '.';
                    else if (t < 77) c = '-';
                    else if (t < 80.6) c = '*';
                    else if (t < 84) c = '+';
                    else if (t < 87) c = 'x';
                    else if (t < 91) c = '%';
                    else if (t < 95) c = '#';
                    else if (t < 98.6) c = '$';
                    logLine.Append(c);
                }
            }

            Resolver.Log.Info(logLine.ToString());
        }
    }
}

Sample project(s) available on GitHub

Characteristic Locus
Inheritance System.Object > Mlx90640
Namespace Meadow.Foundation.Sensors.Camera
Assembly Mlx90640.dll

Syntax

public class Mlx90640 : object

Constructors

Mlx90640(II2cBus, Byte, Single)

Creates a new MLX90640 object

Declaration
public Mlx90640(II2cBus i2cBus, byte address = null, float emissivity = 0.95F)

Parameters

Type Name Description
II2cBus i2cBus

The I2C bus

System.Byte address

I2C address

System.Single emissivity

Emissivity

Properties

Config

Camera configuration

Declaration
public Mlx90640Config Config { get; }

Property Value

Type Description
Mlx90640Config

Emissivity

Emissivity

Declaration
public float Emissivity { get; set; }

Property Value

Type Description
System.Single

ReflectedTemperature

Reflected temperature

Declaration
public Units.Temperature ReflectedTemperature { get; set; }

Property Value

Type Description
Meadow.Units.Temperature

SerialNumber

Camera serial number as a string

Declaration
public string SerialNumber { get; }

Property Value

Type Description
System.String

Methods

GetMode()

Get the current reading pattern mode

Declaration
public Mlx90640.Mode GetMode()

Returns

Type Description
Mlx90640.Mode

Chess or Interleaved

GetRefreshRate()

Gets the Refresh rate

Declaration
public Mlx90640.RefreshRate GetRefreshRate()

Returns

Type Description
Mlx90640.RefreshRate

RefreshRate type

GetResolution()

Get the current resolution mode

Declaration
public Mlx90640.Resolution GetResolution()

Returns

Type Description
Mlx90640.Resolution

Resolution mode

ReadRawData()

Gets all 768 sensor readings

Declaration
public float[] ReadRawData()

Returns

Type Description
System.Single[]

Float array containing each individual reading

SetMode(Mlx90640.Mode)

Set the reading pattern mode

Declaration
public void SetMode(Mlx90640.Mode mode)

Parameters

Type Name Description
Mlx90640.Mode mode

Chess or Interleaved

SetRefreshRate(Mlx90640.RefreshRate)

Sets the refresh rate

Declaration
public void SetRefreshRate(Mlx90640.RefreshRate rate)

Parameters

Type Name Description
Mlx90640.RefreshRate rate

RefreshRate type

SetResolution(Mlx90640.Resolution)

Sets the resolution

Declaration
public void SetResolution(Mlx90640.Resolution res)

Parameters

Type Name Description
Mlx90640.Resolution res

Resolution type