forked from RoelKroes/TBTracker-ESP32
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathADC.ino
More file actions
85 lines (77 loc) · 2.66 KB
/
ADC.ino
File metadata and controls
85 lines (77 loc) · 2.66 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
//===============================================================================
// You will need to create your own code here.
// This is all optional.
// You only need to look at it if you want to include sensor data in your tracker
//===============================================================================
//===============================================================================
// Read the VCC voltage.
// Create your own code here
// Useful for checking battery voltage.
//===============================================================================
float ReadVCC() {
#if defined(USE_VOLTAGE_INFO)
float in_voltage = 0.0;
float adc_calibrated = 0.0;
int Iterations = 16;
pinMode(VOLTAGE_IN_PIN,INPUT);
// Measure a couple of times
for (int i=1; i<= Iterations;i++ )
{
adc_calibrated += analogReadMilliVolts(VOLTAGE_IN_PIN);
delay(1);
}
adc_calibrated = adc_calibrated / Iterations;
adc_calibrated = adc_calibrated / 1000.0;
in_voltage = adc_calibrated / (float(VOLTAGE_DIVIDER_R2) / (float(VOLTAGE_DIVIDER_R1) + float(VOLTAGE_DIVIDER_R2)));
in_voltage += float(VOLTAGE_DEVIATION);
return (in_voltage);
#else
return (0.0);
#endif
}
//===============================================================================
// Read the temperature
// Create your own code here
//===============================================================================
float ReadTemp(void) {
#if defined(USE_BME280)
// The returned temperature is in degrees Celcius.
return (bme280_temperature());
#else
return (0.0);
#endif
}
//===============================================================================
// Read the air pressure
// Create your own code here
//===============================================================================
float ReadPressure(void) {
#if defined(USE_BME280)
// The returned pressure is in hPa
return (bme280_pressure());
#else
return (0.0);
#endif
}
//===============================================================================
// Read the air pressure
// Create your own code here
//===============================================================================
float ReadHumidity(void) {
#if defined(USE_BME280)
// The returned pressure is in hPa
return (bme280_humidity());
#else
return (0.0);
#endif
}
//===============================================================================
// Write the Voltage information for debugging purposes to the Serial Console
//===============================================================================
void printVoltageInfo() {
#if defined(USE_VOLTAGE_INFO)
toSerialConsole(" Voltage: ");
toSerialConsole(ReadVCC());
toSerialConsole(" V\n");
#endif
}