forked from coldeg/Thermal-Sniffer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Thermal-sniffer V1.0.ino
374 lines (352 loc) · 12.4 KB
/
Thermal-sniffer V1.0.ino
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
// libraries_____________________________________________________________________
#include <SPI.h>
#include <epd2in9.h> //epaper
#include <epdpaint.h>
#define COLORED 0
#define UNCOLORED 1
#include <MS5611.h> //barosensor
#define Addr 0x18 // MCP9808 I2C address is 0x18(24) tempsensor
#include <Wire.h> // serial monitor
//epaper module___________________________________________________________________
/**
* Due to RAM not enough in Arduino UNO, a frame buffer is not allowed.
* In this case, a smaller image buffer is allocated and you have to
* update a partial display several times.
* 1 byte = 8 pixels, therefore you have to set 8*N pixels at a time.
*/
unsigned char image[1024];
Paint paint(image, 0, 0); // width should be the multiple of 8
Epd epd;
int counterDisp = 0;
//Barosensor module______________________________________________________________
MS5611 baro;
// create variable insta pressure
double pressure;
double pressureA;
double pressureB;
double pressureC;
double pressureD;
double pressureE;
// create variable recorded pressure
double pressureP;
// create variable pressure diff between recorded and insta
double diffPress;
double treshPress;
//tempsensor module______________________________________________________________
// create variable recorded temp
float temperatureP = 0;
// create variable recorded temp when change above abs treshold
float treshTemp = 0;
// create variable temp diff between recorded and insta
float diffTemp;
// create variable for temp correction with recorded temp
float tempCorr;
//Buzzer module_______________________________________________________________________
// create la note for buzzer
float tonal = 440;
// create one note pitch for buzzer
float pitch = 1.059463119;
// strictly positive number for pitch modulo
int variaNote = 1;
// create counter for resetting tonal to 440 hz if no temp change for 5 seconds
int counter = 1;
//sensibility thermal sniffer potentiometer module____________________________________
int treshCount = 1; //
// select the analog input pin for the potentiometer
int potPin = 2;
// variable to store the value coming from the sensor
float pot = 0;
float val = 0;
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void setup()
{
Serial.begin(9600); // Start serial (UART) for monitor
//Barosensor module______________________________________________________________
// Start barometer
baro = MS5611();
baro.begin();
// Serial.begin(9600);
delay(2);
//epaper module___________________________________________________________________
if (epd.Init(lut_full_update) != 0) {
return;
}
/**
* there are 2 memory areas embedded in the e-paper display
* and once the display is refreshed, the memory area will be auto-toggled,
* i.e. the next action of SetFrameMemory will set the other memory area
* therefore you have to clear the frame memory twice.
*/
epd.ClearFrameMemory(0xFF); // bit set = white, bit reset = black
epd.DisplayFrame();
epd.ClearFrameMemory(0xFF); // bit set = white, bit reset = black
epd.DisplayFrame();
paint.SetRotate(ROTATE_0);
paint.SetWidth(128);
paint.SetHeight(24);
/* For simplicity, the arguments are explicit numerical coordinates */
paint.Clear(UNCOLORED);
paint.DrawStringAt(0, 4, "Captain Ovious", &Font12, COLORED);
epd.SetFrameMemory(paint.GetImage(), 0, 10, paint.GetWidth(), paint.GetHeight());
paint.Clear(UNCOLORED);
paint.DrawStringAt(0, 4, "Thermal sniffer", &Font12, COLORED);
epd.SetFrameMemory(paint.GetImage(), 0, 30, paint.GetWidth(), paint.GetHeight());
paint.Clear(UNCOLORED);
paint.DrawStringAt(0, 4, "V 1.0", &Font12, COLORED);
epd.SetFrameMemory(paint.GetImage(), 0, 50, paint.GetWidth(), paint.GetHeight());
epd.DisplayFrame();
delay(2000);
if (epd.Init(lut_partial_update) != 0) {
return;
}
epd.ClearFrameMemory(0xFF); // bit set = white, bit reset = black
epd.DisplayFrame();
epd.ClearFrameMemory(0xFF); // bit set = white, bit reset = black
epd.DisplayFrame();
//tempsensor module______________________________________________________________
// Initialise I2C communication as MASTER
Wire.begin();
// Initialise Serial Communication, set baud rate = 9600
Serial.begin(9600);
// Start I2C Transmission
Wire.beginTransmission(Addr);
// Select configuration register
Wire.write(0x01);
// Continuous conversion mode, Power-up default
Wire.write(0x00);
Wire.write(0x00);
// Stop I2C Transmission
Wire.endTransmission();
// Start I2C Transmission
Wire.beginTransmission(Addr);
// Select resolution register
Wire.write(0x08);
// Resolution = +0.0625 / C
Wire.write(0x03);
// Stop I2C Transmission
Wire.endTransmission();
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void loop()
{
Serial.begin(9600);
//Barosensor module______________________________________________________________
// Read insta pressure in mbar and make average pressure baro can be offset
pressureA = baro.getPressure();
//tempsensor module______________________________________________________________
//tempsensor first read
unsigned int data[2];
// Starts I2C communication
Wire.beginTransmission(Addr);
// Select data register
Wire.write(0x05);
// Stop I2C transmission
Wire.endTransmission();
// Request 2 bytes of data
Wire.requestFrom(Addr, 2);
// Read 2 bytes of data
// temp MSB, temp LSB
if(Wire.available() == 2)
{
data[0] = Wire.read();
data[1] = Wire.read();
}
// Convert the data to 13-bits
int temp = ((data[0] & 0x1F) * 256 + data[1]);
if(temp > 4095)
{
temp -= 8192;
}
float cTemp1 = temp * 0.0625;
//Barosensor module______________________________________________________________
pressureB = baro.getPressure();
//tempsensor module______________________________________________________________
//tempsensor second read
// Starts I2C communication
Wire.beginTransmission(Addr);
// Select data register
Wire.write(0x05);
// Stop I2C transmission
Wire.endTransmission();
// Request 2 bytes of data
Wire.requestFrom(Addr, 2);
// Read 2 bytes of data
// temp MSB, temp LSB
if(Wire.available() == 2)
{
data[0] = Wire.read();
data[1] = Wire.read();
}
// Convert the data to 13-bits
temp = ((data[0] & 0x1F) * 256 + data[1]);
if(temp > 4095)
{
temp -= 8192;
}
float cTemp2 = temp * 0.0625;
//Barosensor module______________________________________________________________
pressureC = baro.getPressure();
//tempsensor module______________________________________________________________
//tempsensor third read
// Starts I2C communication
Wire.beginTransmission(Addr);
// Select data register
Wire.write(0x05);
// Stop I2C transmission
Wire.endTransmission();
// Request 2 bytes of data
Wire.requestFrom(Addr, 2);
// Read 2 bytes of data
// temp MSB, temp LSB
if(Wire.available() == 2)
{
data[0] = Wire.read();
data[1] = Wire.read();
}
// Convert the data to 13-bits
temp = ((data[0] & 0x1F) * 256 + data[1]);
if(temp > 4095)
{
temp -= 8192;
}
float cTemp3 = temp * 0.0625;
//Barosensor module______________________________________________________________
pressureD = baro.getPressure();
//tempsensor module______________________________________________________________
//tempsensor fourth read
// Starts I2C communication
Wire.beginTransmission(Addr);
// Select data register
Wire.write(0x05);
// Stop I2C transmission
Wire.endTransmission();
// Request 2 bytes of data
Wire.requestFrom(Addr, 2);
// Read 2 bytes of data
// temp MSB, temp LSB
if(Wire.available() == 2)
{
data[0] = Wire.read();
data[1] = Wire.read();
}
// Convert the data to 13-bits
temp = ((data[0] & 0x1F) * 256 + data[1]);
if(temp > 4095)
{
temp -= 8192;
}
float cTemp4 = temp * 0.0625;
//Barosensor module______________________________________________________________
pressureE = baro.getPressure();
//tempsensor module______________________________________________________________
//tempsensor fifth read
// Starts I2C communication
Wire.beginTransmission(Addr);
// Select data register
Wire.write(0x05);
// Stop I2C transmission
Wire.endTransmission();
// Request 2 bytes of data
Wire.requestFrom(Addr, 2);
// Read 2 bytes of data
// temp MSB, temp LSB
if(Wire.available() == 2)
{
data[0] = Wire.read();
data[1] = Wire.read();
}
// Convert the data to 13-bits
temp = ((data[0] & 0x1F) * 256 + data[1]);
if(temp > 4095)
{
temp -= 8192;
}
float cTemp5 = temp * 0.0625;
//Barosensor module______________________________________________________________
pressure = (pressureA + pressureB + pressureC + pressureD + pressureE)/500;
if (pressureP < 10 )
{
pressureP = pressure;
}
// get pressure diff between recorded press and insta press
diffPress = (pressure - pressureP);
// get temp correction with pressure diff
tempCorr = diffPress*0.09411616;
//record pressure for next loop
pressureP = pressure ;
//epaper module___________________________________________________________________
counterDisp = counterDisp +1;
if (counterDisp > 40)
{char temp[8]; // Buffer big enough for 7-character float
// display temp
dtostrf(temperatureP, 6, 2, temp); // Leave room for too large numbers! dtostrf transform float to char
paint.SetRotate(ROTATE_0);
paint.SetWidth(128);
paint.SetHeight(24);
paint.Clear(UNCOLORED);
paint.DrawStringAt(0, 10, temp , &Font12, COLORED);
epd.SetFrameMemory(paint.GetImage(), 0, 10, paint.GetWidth(), paint.GetHeight());
// display baro
char pressu[8];
dtostrf(pressureP, 6, 2, pressu);
paint.DrawStringAt(0, 30, pressu , &Font12, COLORED);
epd.SetFrameMemory(paint.GetImage(), 0, 30, paint.GetWidth(), paint.GetHeight());
epd.DisplayFrame();
counterDisp=0;
}
//tempsensor module______________________________________________________________
// get temp diff between recorded temp and insta temp
diffTemp = (cTemp1 + cTemp2 + cTemp3 + cTemp4 + cTemp5)/5 - temperatureP + tempCorr;
//record temp for next loop
temperatureP = (cTemp1 + cTemp2 + cTemp3 + cTemp4 + cTemp5)/5;
//sensibility thermal sniffer potentiometer module____________________________________
// read the value from the potentiometer as treshold for beep with temp change, analogRead() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin.
pot = analogRead(potPin)/100;
val = pot/10 + 0.6;
//Buzzer module_______________________________________________________________________
// speakertone code to be tweaked I wanted notes to be played therefore i use 440 hertz as base note and varianote pitches tonal to one (or more) notes higher or lesser in function of the temp diff
// val = treshold breaker from potentiometer
if (treshCount < 2) // set treshTemp and treshPress as temperatureP and pressureP at startup and if temp stagnation over 20 loops it gives a base reference like (this is 0 m/s for an altivario)
{
treshTemp = temperatureP;
treshPress = pressureP;
treshCount = 2;
}
// get pressure diff between recorded press and insta press
diffPress = (treshPress - pressureP);
// get temp correction with pressure diff
tempCorr = diffPress*0.09411616;
if ( (abs(diffTemp) - (val/10)) > 0)
{
if (diffTemp > 0.00) // temp increase
{
counter = 2;
// create absolute value of temp diff
variaNote = abs(treshTemp - temperatureP + tempCorr)*5;
//Serial.println(variaNote);
tonal = 440 * pow(pitch,variaNote);
tone(6,tonal,1000);
}
if (-diffTemp > 0.00 ) // temp decrease
{
counter = 2;
variaNote = (1 - abs(treshTemp - temperatureP + tempCorr))*5;
tonal = 440 / pow(pitch,variaNote);
tone(6,tonal,1000);
}
}
if ( (abs(diffTemp) - (val/10)) < 0) // temp stagnation
{
counter = counter +1;
if (counter < 20)
{
tone(6,tonal,1000); //reset tonal if stagnation
}
//Serial.print(" counter = ");Serial.println(counter);
if (counter > 20) //
{
treshCount = 1;
counter = 22;
}
}
}