-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpg 3
More file actions
174 lines (128 loc) · 4.33 KB
/
pg 3
File metadata and controls
174 lines (128 loc) · 4.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//copyright 2020 Alexander I Rusich
#include "irarray.h"
void CIRArray::setup()
{
if (isConnected() == false)
{
Serial.println("MLX90640 not detected at default I2C address. Please check wiring. Freezing.");
return;
}
Display.setup();
//Get device parameters - We only have to do this once
int status;
uint16_t eeMLX90640[832];
status = MLX90640_DumpEE(address, eeMLX90640);
if (status != 0) {
Serial.println("Failed to load system parameters");
return;
}
status = MLX90640_ExtractParameters(eeMLX90640, &mlx90640);
if (status != 0){
Serial.println("Parameter extraction failed");
return;
}
//Once params are extracted, we can release eeMLX90640 array
//Set refresh rate
//A rate of 0.5Hz takes 4Sec per reading because we have to read two frames to get complete picture
//MLX90640_SetRefreshRate(MLX90640_address, 0x00); //Set rate to 0.25Hz effective - Works
//MLX90640_SetRefreshRate(MLX90640_address, 0x01); //Set rate to 0.5Hz effective - Works
//MLX90640_SetRefreshRate(MLX90640_address, 0x02); //Set rate to 1Hz effective - Works
//MLX90640_SetRefreshRate(MLX90640_address, 0x03); //Set rate to 2Hz effective - Works
MLX90640_SetRefreshRate(address, 0x03); //Set rate to 4Hz effective - Works
//MLX90640_SetRefreshRate(MLX90640_address, 0x04); //Set rate to 4Hz effective - Works
//MLX90640_SetRefreshRate(MLX90640_address, 0x05); //Set rate to 8Hz effective - Works at 800kHz
//MLX90640_SetRefreshRate(MLX90640_address, 0x06); //Set rate to 16Hz effective - Works at 800kHz
//MLX90640_SetRefreshRate(MLX90640_address, 0x07); //Set rate to 32Hz effective - fails
//Once EEPROM has been read at 400kHz we can increase to 1MHz
// Wire.setClock(1000000); //Teensy will now run I2C at 800kHz (because of clock division)
//TimeStamp();
bReady=true;
}
void CIRArray::loop()
{
if(!bReady) return;
char pixel[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
long startTime = millis();
float ftot=0.0,fmin,fmax,y;
for (byte x = 0 ; x < 2 ; x++)
{
uint16_t mlx90640Frame[834];
int status = MLX90640_GetFrameData(address, mlx90640Frame);
float vdd = MLX90640_GetVdd(mlx90640Frame, &mlx90640);
float Ta = MLX90640_GetTa(mlx90640Frame, &mlx90640);
float tr = Ta - TA_SHIFT; //Reflected temperature based on the sensor ambient temperature
float emissivity = 0.95;
MLX90640_CalculateTo(mlx90640Frame, &mlx90640, emissivity, tr, mlx90640To);
}
long stopTime = millis();
if(0&&(millis()>last +15000)){
last=millis();
int offset=rand()%700 +5; //random between 7 and 705
y=mlx90640To[offset];
if((y<-100.0)||(y>200.0)){
offset=rand()%700 +3; //random between 7 and 705
y=mlx90640To[offset+1];
}
fmin=y;
fmax=y;
int counter=0;
for (int x = 0 ; x < 768 ; x++) //Find min max
{
y=mlx90640To[x];
if(isnan(y)) continue;
counter++;
ftot+=y;
if(y<fmin) fmin=y;
if(y>fmax) fmax=y;
//Display.Print(y,0,0);
// Serial.println(y);
// delay(20);
}
favg=ftot/float(counter);
Display.Clear();
Display.Print(fmin,0,0);
Display.Print(fmax,35,0);
Display.Print(favg,0,40);
imin=(int) floor(fmin*10);
imax=(int) ceil(fmax*10);
Display.Show();
//delay(5000);
}
/*
pixelTable[768]=NULL;
pixelTable[769]=NULL;
for (int x = 0 ; x < 768 ; x++){ //32x24
y=mlx90640To[x];
if (y!=NULL){
offset= (int) map(y*10, imin, imax, 0, 62);
pixelTable[x]=pixel[offset];
}
else pixelTable[x]='A';
}
Serial.println(pixelTable);
*/
Display.Clear();
for (int x = 0 ; x < 768 ; x++){ //32x24
y=mlx90640To[x];
//
// if (y>favg+20) Display.Pt32x24(x%32,x/32);
if (y>80) Display.Pt32x24(x%32,x/32);
}
Display.Show();
// delay(10);
}
void CIRArray::Output(){
char memchar[193];
for(int z=0;z<4;z++){
// Done();
}
}
//Returns true if the MLX90640 is detected on the I2C bus
bool CIRArray::isConnected()
{
Wire.beginTransmission((uint8_t)address);
if (Wire.endTransmission() != 0)
return (false); //Sensor did not ACK
Serial.print("m");
return (true);
}