Skip to content

Commit 1fa6c33

Browse files
committed
Initial commit
0 parents  commit 1fa6c33

14 files changed

+3111
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
Read the temperature pixels from the MLX90640 IR array
3+
By: Nathan Seidle
4+
SparkFun Electronics
5+
Date: May 22nd, 2018
6+
License: MIT. See license file for more information but you can
7+
basically do whatever you want with this code.
8+
9+
Feel like supporting open source hardware?
10+
Buy a board from SparkFun! https://www.sparkfun.com/products/14769
11+
12+
This example initializes the MLX90640 and outputs the 768 temperature values
13+
from the 768 pixels.
14+
15+
This example will work with a Teensy 3.1 and above. The MLX90640 requires some
16+
hefty calculations and larger arrays. You will need a microcontroller with 20,000
17+
bytes or more of RAM.
18+
19+
This relies on the driver written by Melexis and can be found at:
20+
https://github.com/melexis/mlx90640-library
21+
22+
Hardware Connections:
23+
Connect the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
24+
to the Qwiic board
25+
Connect the male pins to the Teensy. The pinouts can be found here: https://www.pjrc.com/teensy/pinout.html
26+
Open the serial monitor at 9600 baud to see the output
27+
*/
28+
29+
#include <Wire.h>
30+
31+
#include "MLX90640_API.h"
32+
#include "MLX90640_I2C_Driver.h"
33+
34+
const byte MLX90640_address = 0x33; //Default 7-bit unshifted address of the MLX90640
35+
36+
#define TA_SHIFT 8 //Default shift for MLX90640 in open air
37+
38+
static float mlx90640To[768];
39+
paramsMLX90640 mlx90640;
40+
41+
void setup()
42+
{
43+
Wire.begin();
44+
Wire.setClock(400000); //Increase I2C clock speed to 400kHz
45+
46+
Serial.begin(9600);
47+
while (!Serial); //Wait for user to open terminal
48+
Serial.println("MLX90640 IR Array Example");
49+
50+
if (isConnected() == false)
51+
{
52+
Serial.println("MLX90640 not detected at default I2C addres. Please check wiring. Freezing.");
53+
while (1);
54+
}
55+
Serial.println("MLX90640 online!");
56+
57+
//Get device parameters - We only have to do this once
58+
int status;
59+
uint16_t eeMLX90640[832];
60+
status = MLX90640_DumpEE(MLX90640_address, eeMLX90640);
61+
if (status != 0)
62+
Serial.println("Failed to load system parameters");
63+
64+
status = MLX90640_ExtractParameters(eeMLX90640, &mlx90640);
65+
if (status != 0)
66+
Serial.println("Parameter extraction failed");
67+
68+
//Once params are extracted, we can release eeMLX90640 array
69+
}
70+
71+
void loop()
72+
{
73+
for (byte x = 0 ; x < 2 ; x++) //Read both subpages
74+
{
75+
uint16_t mlx90640Frame[834];
76+
int status = MLX90640_GetFrameData(MLX90640_address, mlx90640Frame);
77+
if (status < 0)
78+
{
79+
Serial.print("GetFrame Error: ");
80+
Serial.println(status);
81+
}
82+
83+
float vdd = MLX90640_GetVdd(mlx90640Frame, &mlx90640);
84+
float Ta = MLX90640_GetTa(mlx90640Frame, &mlx90640);
85+
86+
float tr = Ta - TA_SHIFT; //Reflected temperature based on the sensor ambient temperature
87+
float emissivity = 0.95;
88+
89+
MLX90640_CalculateTo(mlx90640Frame, &mlx90640, emissivity, tr, mlx90640To);
90+
}
91+
92+
for (int x = 0 ; x < 10 ; x++)
93+
{
94+
Serial.print("Pixel ");
95+
Serial.print(x);
96+
Serial.print(": ");
97+
Serial.print(mlx90640To[x], 2);
98+
Serial.print("C");
99+
Serial.println();
100+
}
101+
102+
delay(1000);
103+
}
104+
105+
//Returns true if the MLX90640 is detected on the I2C bus
106+
boolean isConnected()
107+
{
108+
Wire.beginTransmission((uint8_t)MLX90640_address);
109+
if (Wire.endTransmission() != 0)
110+
return (false); //Sensor did not ACK
111+
return (true);
112+
}
113+

0 commit comments

Comments
 (0)