Skip to content

Commit 14fedfd

Browse files
authored
Added TTGO-T-Beam board + option to send ADC values in volt (#863)
* Added Voltage measure option * Added TTGO Beam with Battery voltage measure
1 parent 67823d2 commit 14fedfd

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

main/ZsensorADC.ino

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,32 @@ void MeasureADC() {
5454
} else {
5555
if (val >= persistedadc + ThresholdReadingADC || val <= persistedadc - ThresholdReadingADC) {
5656
Log.trace(F("Creating ADC buffer" CR));
57+
# if defined(ADC_DIVIDER)
58+
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(2);
59+
# else
5760
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(1);
61+
# endif
5862
StaticJsonBuffer<JSON_MSG_CALC_BUFFER> jsonBuffer;
5963
JsonObject& ADCdata = jsonBuffer.createObject();
6064
ADCdata.set("adc", (int)val);
65+
# if defined(ADC_DIVIDER)
66+
float volt = 0;
67+
# if defined(ESP32)
68+
// Convert the analog reading (which goes from 0 - 4095) to a voltage (0 - 3.3V):
69+
volt = val * (3.3 / 4096.0);
70+
# elif defined(ESP8266)
71+
// Convert the analog reading (which goes from 0 - 1024) to a voltage (0 - 3.3V):
72+
volt = val * (3.3 / 1024.0);
73+
# else
74+
// Asume 5V and 10bits ADC
75+
volt = val * (5.0 / 1024.0);
76+
# endif
77+
volt *= ADC_DIVIDER;
78+
// let's give 2 decimal point
79+
val = (volt * 100);
80+
volt = (float)val / 100.0;
81+
ADCdata.set("volt", (float)volt);
82+
# endif
6183
pub(ADCTOPIC, ADCdata);
6284
persistedadc = val;
6385
}

platformio.ini

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ extra_configs =
4949
;default_envs = esp32-m5stick-cp-ble
5050
;default_envs = esp32-m5atom
5151
;default_envs = ttgo-lora32-v1
52+
;default_envs = ttgo-t-beam
5253
;default_envs = nodemcuv2-rf
5354
;default_envs = nodemcuv2-rf-cc1101
5455
;default_envs = nodemcuv2-somfy-cc1101
@@ -497,6 +498,36 @@ build_flags =
497498
'-DZgatewayLORA="LORA"'
498499
'-DGateway_Name="OpenMQTTGateway_ESP32_LORA"'
499500

501+
[env:ttgo-t-beam]
502+
# See version pinout differences here
503+
# https://www.thethingsnetwork.org/forum/t/big-esp32-sx127x-topic-part-3/18436
504+
platform = ${com.esp32_platform}
505+
board = ttgo-t-beam
506+
lib_deps =
507+
${com-esp.lib_deps}
508+
${libraries.ble}
509+
${libraries.lora}
510+
build_flags =
511+
${com-esp.build_flags}
512+
'-DZgatewayLORA="LORA"'
513+
'-DZgatewayBT="BT"'
514+
'-DGateway_Name="OpenMQTTGateway_ESP32_BLE_LORA"'
515+
516+
'-DLED_RECEIVE=21' # T-BEAM board V0.5
517+
# '-DLED_RECEIVE=14' # T-BEAM board V0.7
518+
# '-DLED_RECEIVE=4' # T-BEAM board V1.0+
519+
'-DTimeLedON=0.05'
520+
'-DLED_RECEIVE_ON=1' # Set 0 for board V1.0+
521+
522+
# for V0.5 and V0.7 ONLY (V1.0+ as onboard AXP202 dedicated chip, need driver)
523+
# it's a 100K/100K divider (so 2 divider) and connected to GPIO35
524+
'-DZsensorADC="ADC"'
525+
'-DADC_GPIO=35'
526+
'-DADC_DIVIDER=2'
527+
# Reading battery level every minutes should be more than enought
528+
'-DTimeBetweenReadingADC=60000'
529+
530+
500531
[env:nodemcuv2-all-test]
501532
platform = ${com.esp8266_platform}
502533
board = nodemcuv2

0 commit comments

Comments
 (0)