-
Notifications
You must be signed in to change notification settings - Fork 1
/
SmokingGrillControl.ino
149 lines (109 loc) · 3.32 KB
/
SmokingGrillControl.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
#include "SSD1306Wire.h"
#include <driver/adc.h>
#include "images.h"
#include "keys.h"
#include "esp32-hal.h"
#include <Arduino.h>
#include <WiFi.h>
#include <WiFiMulti.h>
#include <HTTPClient.h>
#include <IOXhop_FirebaseESP32.h>
WiFiMulti wifiMulti;
SSD1306Wire display(0x3c, 5, 4);
#define ANALOG_PIN_0 25
int demoMode = 0;
int counter = 1;
int adcval = 0;
float temp_celsius;
int dataArray[100];
int currentPointIndex = 0;
void initGraph() {
display.setColor(WHITE);
for (int i = 0; i < 100 ; i++)
dataArray[i] = 0;
}
void setup() {
Serial.begin(115200);
Serial.println("Hello");
Serial.println();
// Initialising the UI will init the display too.
display.init();
display.flipScreenVertically();
display.setFont(Dialog_plain_7);
// pinMode(ANALOG_PIN_0, INPUT);
adc1_config_width(ADC_WIDTH_12Bit);
adc1_config_channel_atten(ADC1_CHANNEL_0, ADC_ATTEN_11db);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("connecting");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.print("connected: ");
Serial.println(WiFi.localIP());
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
initGraph();
}
void drawImageDemo() {
// see http://blog.squix.org/2015/05/esp8266-nodemcu-how-to-create-xbm.html
// on how to create xbm files
display.drawXbm(34, 14, WiFi_Logo_width, WiFi_Logo_height, WiFi_Logo_bits);
}
void updateDataToCloud(int data, float temperture) {
if ((wifiMulti.run() == WL_CONNECTED)) {
HTTPClient http;
Serial.println("adc : " + String(data));
http.begin("https://api.thingspeak.com/update?api_key="+ String(THINGSPEAK_KEY) +"&field1=" + String(data) + "&field2=" + String(temperture)); //HTTP
int httpCode = http.GET();
http.end();
}
}
void loop() {
// Serial.println("Hello");
// clear the display
display.clear();
display.drawHorizontalLine(10, 54, 100);
display.drawVerticalLine(10, 5, 50);
// adcval = analogRead(ANALOG_PIN_0);
adcval = adc1_get_voltage(ADC1_CHANNEL_0);
float voltage = adcval * (3.9 / 4095.0);
// int voltage = adc1_get_voltage(ADC1_CHANNEL_0);
// temp_celsius = (voltage - 0.5) * 100 ;
temp_celsius = (adcval * 0.0424) + 6 ;
if (counter > 15) {
updateDataToCloud(adcval, temp_celsius);
counter = 0;
}
display.setTextAlignment(TEXT_ALIGN_CENTER);
display.setFont(ArialMT_Plain_10);
// display.drawString(64, 50, "Temperture :" + String(temp_celsius));
// display.drawString(64, 54, "Voltage :" + String(voltage));
display.drawString(64, 54, "Temperture :" + String(temp_celsius));
display.drawString(64, 0, "adc :" + String(adcval));
// draw the current demo method
// drawImageDemo();
updateGraph(temp_celsius / 4);
display.display();
//updateGraph((adcval - 568) / 20);
counter++;
delay(1000);
}
void updateGraph(int val) {
dataArray[currentPointIndex] = val ;
Serial.println("val : " + String(val) + " currentPoint : " + String(55 - dataArray[currentPointIndex]));
for (int i = 0 ; i < 100 ; i++) {
int x = i;
int y = 0;
if (100 - i < currentPointIndex) {
y = dataArray[currentPointIndex - (100 - i)] ;
} else {
y = dataArray[currentPointIndex + i];
}
display.setPixel(x + 10, 54 - y );
}
currentPointIndex++;
if (currentPointIndex >= 99) {
currentPointIndex = 0;
}
}