Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added TTGO-T-Beam board + option to send ADC values in volt #863

Merged
merged 7 commits into from
Feb 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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