Skip to content

Commit

Permalink
Added TTGO-T-Beam board + option to send ADC values in volt (#863)
Browse files Browse the repository at this point in the history
* Added Voltage measure option
* Added TTGO Beam with Battery voltage measure
  • Loading branch information
hallard authored Feb 6, 2021
1 parent 67823d2 commit 14fedfd
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
22 changes: 22 additions & 0 deletions main/ZsensorADC.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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<JSON_MSG_CALC_BUFFER> 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;
}
Expand Down
31 changes: 31 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 14fedfd

Please sign in to comment.