-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemperature_with_Display.ino
More file actions
81 lines (63 loc) · 2.14 KB
/
Temperature_with_Display.ino
File metadata and controls
81 lines (63 loc) · 2.14 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
#include <Arduino.h>
#include <U8g2lib.h>
#include <Wire.h>
#include <Adafruit_MLX90614.h>
//Wiring I2C
// A4 - SDA
// A5 - SCLK
//
//Wiring SPI
// CLK - 13
// DATA - 11
// CS - 10
// DC - 9
// RESET - 8
//IR Temperature
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
//OLED Object
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
//Button
const int buttonPin = 2;
//variable
int buttonState = 0; // push button state
void setup() {
Serial.begin(9600);
pinMode(buttonPin, INPUT);
Serial.println("BITSOC MLX90614 Temperature with OLED Display");
u8g2.begin();
initializeDisplay();
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
// read temperature and display
readAndDisplay();
}
}
void initializeDisplay () {
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_t0_16b_tf); // choose a suitable font
u8g2.drawStr(20,20,"Temperature"); // write something to the internal memory
u8g2.drawStr(40,40,"----");
u8g2.sendBuffer(); // transfer internal memory to the display
delay(500);
}
void readAndDisplay(){
mlx.begin(); // This declaration must be inside the reader function
char tempC [10];
float tempValue = 0;
char *pointer_to_created_string;
Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempC());
Serial.println();
tempValue = mlx.readObjectTempC();
Serial.print("*C\tObject = "); Serial.print(mlx.readObjectTempC()); Serial.println("*C");
Serial.println();
pointer_to_created_string = dtostrf(tempValue, 4, 2, tempC);
Serial.print("converted to string: "); Serial.println(pointer_to_created_string);
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_t0_16b_tf); // choose a suitable font
u8g2.drawStr(10,20,"Temperature *C"); // write something to the internal memory
u8g2.drawStr(40,40,pointer_to_created_string); // write something to the internal memory
u8g2.sendBuffer(); // transfer internal memory to the display
delay(500);
}