-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathESP32_DataPlotter.ino
76 lines (66 loc) · 2.08 KB
/
ESP32_DataPlotter.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
#include "LogNPlot.h"
/*BEGIN USER CODE - USER LIBRARIES*/
/*END USER CODE - USER LIBRARIES*/
/*BEGIN USER CODE - GLOBAL DECLARATIONS*/
/*END USER CODE - GLOBAL DECLARATIONS*/
/*BEGIN USER CODE - WIFI (Replace with your network credentials)*/
const char* ssid = "REGOSH";
const char* password = "Libre2022";
const char* DataPlotterName = "dataplotter";
/*END USER CODE - WIFI*/
/*BEGIN USER CODE - NAMES OF PARAMETERS*/
const int NumberOfParameters = 4;
const char* ParameterNames[NumberOfParameters] = {"/voltagePinA", "/voltagePinB", "/voltagePinC", "/hallSensorESP32"};
/*END USER CODE - NAMES OF PARAMETERS*/
LogNPlot logger(ParameterNames, NumberOfParameters, ssid, password, DataPlotterName);
void setup(){
// Serial port for debugging purposes
Serial.begin(115200);
serialIncFlush();
serialOutFlush();
/*BEGIN USER CODE - SETUP*/
pinMode(32,INPUT);
pinMode(33,INPUT);
pinMode(34,INPUT);
/*END USER CODE - SETUP*/
logger.begin();
}
void loop(){
logger.checkConnection();
for(int i=0; i < logger.MeasurementPeriod/(2*logger.SamplingPeriod); i++){
measure_all();
}
time_t timeRightNow;
time(&timeRightNow);
for(int i=0; i < logger.MeasurementPeriod/(2*logger.SamplingPeriod); i++){
measure_all();
}
logger.saveMeasurement(timeRightNow);
}
void serialOutFlush()
{
Serial.flush();
}
void serialIncFlush()
{
while(Serial.available()) Serial.read();
}
void measure_all(){
long t1 = millis();
/*BEGIN USER CODE - Measuring a sample.*/
int adc1, adc2, adc3;
adc1 = analogRead(32);
adc2 = analogRead(33);
adc3 = analogRead(34);
logger.addSampleAtPosition(adc1*0.000806,0);
logger.addSampleAtPosition(adc2*0.000806,1);
logger.addSampleAtPosition(adc3*0.000806,2);
Serial.println("ADC: " + String(adc1) + " , " + String(adc2) + " , " + String(adc3));
int hallValue;
hallValue = hallRead();
logger.addSampleAtPosition(hallValue,3);
Serial.println("Hall Sensor: " + String(hallValue));
/*END USER CODE - Measuring a sample.*/
long t2 = millis();
if(logger.SamplingPeriod*1000-(millis()-t1) > 0) delay(logger.SamplingPeriod*1000-(t2-t1));
}