From 14fedfdf53dd1e4d9b28ff186f8b64a280d62206 Mon Sep 17 00:00:00 2001 From: Charles Date: Sat, 6 Feb 2021 19:47:52 +0100 Subject: [PATCH] Added TTGO-T-Beam board + option to send ADC values in volt (#863) * Added Voltage measure option * Added TTGO Beam with Battery voltage measure --- main/ZsensorADC.ino | 22 ++++++++++++++++++++++ platformio.ini | 31 +++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/main/ZsensorADC.ino b/main/ZsensorADC.ino index e28c04f..2a0fc70 100644 --- a/main/ZsensorADC.ino +++ b/main/ZsensorADC.ino @@ -54,10 +54,32 @@ void MeasureADC() { } else { if (val >= persistedadc + ThresholdReadingADC || val <= persistedadc - ThresholdReadingADC) { Log.trace(F("Creating ADC buffer" CR)); +# if defined(ADC_DIVIDER) + const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(2); +# else const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(1); +# endif StaticJsonBuffer jsonBuffer; JsonObject& ADCdata = jsonBuffer.createObject(); ADCdata.set("adc", (int)val); +# if defined(ADC_DIVIDER) + float volt = 0; +# if defined(ESP32) + // Convert the analog reading (which goes from 0 - 4095) to a voltage (0 - 3.3V): + volt = val * (3.3 / 4096.0); +# elif defined(ESP8266) + // Convert the analog reading (which goes from 0 - 1024) to a voltage (0 - 3.3V): + volt = val * (3.3 / 1024.0); +# else + // Asume 5V and 10bits ADC + volt = val * (5.0 / 1024.0); +# endif + volt *= ADC_DIVIDER; + // let's give 2 decimal point + val = (volt * 100); + volt = (float)val / 100.0; + ADCdata.set("volt", (float)volt); +# endif pub(ADCTOPIC, ADCdata); persistedadc = val; } diff --git a/platformio.ini b/platformio.ini index 11b3f17..aa7407a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -49,6 +49,7 @@ extra_configs = ;default_envs = esp32-m5stick-cp-ble ;default_envs = esp32-m5atom ;default_envs = ttgo-lora32-v1 +;default_envs = ttgo-t-beam ;default_envs = nodemcuv2-rf ;default_envs = nodemcuv2-rf-cc1101 ;default_envs = nodemcuv2-somfy-cc1101 @@ -497,6 +498,36 @@ build_flags = '-DZgatewayLORA="LORA"' '-DGateway_Name="OpenMQTTGateway_ESP32_LORA"' +[env:ttgo-t-beam] +# See version pinout differences here +# https://www.thethingsnetwork.org/forum/t/big-esp32-sx127x-topic-part-3/18436 +platform = ${com.esp32_platform} +board = ttgo-t-beam +lib_deps = + ${com-esp.lib_deps} + ${libraries.ble} + ${libraries.lora} +build_flags = + ${com-esp.build_flags} + '-DZgatewayLORA="LORA"' + '-DZgatewayBT="BT"' + '-DGateway_Name="OpenMQTTGateway_ESP32_BLE_LORA"' + + '-DLED_RECEIVE=21' # T-BEAM board V0.5 +# '-DLED_RECEIVE=14' # T-BEAM board V0.7 +# '-DLED_RECEIVE=4' # T-BEAM board V1.0+ + '-DTimeLedON=0.05' + '-DLED_RECEIVE_ON=1' # Set 0 for board V1.0+ + + # for V0.5 and V0.7 ONLY (V1.0+ as onboard AXP202 dedicated chip, need driver) + # it's a 100K/100K divider (so 2 divider) and connected to GPIO35 + '-DZsensorADC="ADC"' + '-DADC_GPIO=35' + '-DADC_DIVIDER=2' + # Reading battery level every minutes should be more than enought + '-DTimeBetweenReadingADC=60000' + + [env:nodemcuv2-all-test] platform = ${com.esp8266_platform} board = nodemcuv2