Skip to content
This repository has been archived by the owner on Oct 27, 2024. It is now read-only.

Commit

Permalink
Replaced ESP32AnalogRead by analogReadMilliVolts() (#89)
Browse files Browse the repository at this point in the history
* Replaced ESP32AnalogRead by analogReadMilliVolts()
* CI workflow
    * Target heltec_wireless_stick: removed parameter 'PSRAM'
    * Renamed target m5stack-core2 to m5stack_core2
  • Loading branch information
matthias-bs authored Jun 6, 2024
1 parent bd6610e commit 86bd73b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 121 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
#- esp32:esp32:ttgo-lora32:Revision=TTGO_LoRa32_V1
#- esp32:esp32:ttgo-lora32:Revision=TTGO_LoRa32_V2
- esp32:esp32:ttgo-lora32:Revision=TTGO_LoRa32_v21new
- esp32:esp32:heltec_wireless_stick:PSRAM=disabled
- esp32:esp32:heltec_wireless_stick
- esp32:esp32:heltec_wifi_lora_32_V2
- esp32:esp32:featheresp32
- esp32:esp32:m5stack-core2
- esp32:esp32:m5stack_core2
- esp32:esp32:adafruit_feather_esp32s2
- rp2040:rp2040:adafruit_feather:dbgport=Serial

Expand Down Expand Up @@ -75,14 +75,13 @@ jobs:
|
#declare -a required_libs=("https://github.com/matthias-bs/BresserWeatherSensorReceiver.git"
declare -a required_libs=(
"RadioLib@6.5.0"
"RadioLib@6.6.0"
"[email protected]"
"MCCI LoRaWAN LMIC [email protected]"
"MCCI Arduino LoRaWAN [email protected]"
"MCCI Arduino Development Kit [email protected]"
"LoRa [email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
"[email protected]"
Expand Down
139 changes: 28 additions & 111 deletions BresserWeatherSensorTTN.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// MCCI Arduino LoRaWAN Library by Terry Moore, MCCI (https://github.com/mcci-catena/arduino-lorawan)
// Lora-Serialization by Joscha Feth (https://github.com/thesolarnomad/lora-serialization)
// ESP32Time by Felix Biego (https://github.com/fbiego/ESP32Time)
// ESP32AnalogRead by Kevin Harrington (madhephaestus) (https://github.com/madhephaestus/ESP32AnalogRead)
// OneWireNg by Piotr Stolarz (https://github.com/pstolarz/OneWireNg)
// DallasTemperature / Arduino-Temperature-Control-Library by Miles Burton (https://github.com/milesburton/Arduino-Temperature-Control-Library)
//
Expand All @@ -29,11 +28,10 @@
// MCCI Arduino Development Kit ADK 0.2.2
// MCCI LoRaWAN LMIC library 4.1.1
// MCCI Arduino LoRaWAN Library 0.10.0
// RadioLib 6.1.0
// RadioLib 6.6.0
// LoRa_Serialization 3.2.1
// ESP32Time 2.0.4
// BresserWeatherSensorReceiver 0.12.1
// ESP32AnalogRead 0.2.1 (optional)
// OneWireNg 0.13.1 (optional)
// DallasTemperature 3.9.0 (optional)
// NimBLE-Arduino 1.4.1 (optional)
Expand Down Expand Up @@ -124,6 +122,7 @@
// 20240222 Added weatherSensor.clearSlots() (part of fix for #82), added workaround for (#81)
// 20240303 Added evaluation of temp_ok/humidity_ok/rain_ok (#82)
// 20240325 Added configuration for M5Stack Core2 with M5Stack Module LoRa868
// 20240606 Replaced ESP32AnalogRead by analogReadMilliVolts()
//
// ToDo:
// - Split this file
Expand Down Expand Up @@ -202,13 +201,6 @@
#include <DistanceSensor_A02YYUW.h>
#endif

#ifdef ADC_EN
#ifdef ESP32
// ESP32 calibrated Analog Input Reading
#include <ESP32AnalogRead.h>
#endif
#endif

// BresserWeatherSensorReceiver
#include "WeatherSensorCfg.h"
#include "WeatherSensor.h"
Expand Down Expand Up @@ -521,34 +513,21 @@ public:
*/
float getTemperature(void);

#ifdef ADC_EN
/*!
* \fn getVoltage
*
* \brief Get supply voltage (fixed ADC input circuit on FireBeetle ESP32 board)
*
* \returns Voltage [mV]
*/
uint16_t getVoltage(void);

#if defined(ESP32)
/*
* \fn getVoltage
*
* \brief Get ADC voltage from specified port with averaging and application of divider
*
* \param adc ADC port
*
* \param samples No. of samples used in averaging
*
* \param divider Voltage divider
*
* \returns Voltage [mV]
*/
uint16_t getVoltage(ESP32AnalogRead &adc, uint8_t samples, float divider);
#else
uint16_t getVoltage(pin_size_t pin, uint8_t samples, float divider);
#endif
#ifdef ADC_EN
/*
* \fn getVoltage
*
* \brief Get ADC voltage from specified pin with averaging and application of divider
*
* \param adc ADC pin
*
* \param samples No. of samples used in averaging
*
* \param divider Voltage divider
*
* \returns Voltage [mV]
*/
uint16_t getVoltage(uint8_t pin = PIN_ADC_IN, uint8_t samples = UBATT_SAMPLES, float divider = UBATT_DIV);
#endif

/*!
Expand Down Expand Up @@ -646,27 +625,6 @@ const cMyLoRaWAN::lmic_pinmap myPinMap = {
time_t rtcLastClockSync; //!< timestamp of last RTC synchonization to network time
#endif

#ifdef ESP32
#ifdef ADC_EN
// ESP32 ADC with calibration
ESP32AnalogRead adc; //!< ADC object for supply voltage measurement
#endif

// ESP32 ADC with calibration
#if defined(ADC_EN) && defined(PIN_ADC0_IN)
ESP32AnalogRead adc0; //!< ADC object
#endif
#if defined(ADC_EN) && defined(PIN_ADC1_IN)
ESP32AnalogRead adc1; //!< ADC object
#endif
#if defined(ADC_EN) && defined(PIN_ADC2_IN)
ESP32AnalogRead adc2; //!< ADC object
#endif
#if defined(ADC_EN) && defined(PIN_ADC3_IN)
ESP32AnalogRead adc3; //!< ADC object
#endif
#endif

/// Bresser Weather Sensor Receiver
WeatherSensor weatherSensor;

Expand Down Expand Up @@ -1617,10 +1575,7 @@ cSensor::setup(std::uint32_t uplinkPeriodMs) {
#endif

#ifdef ADC_EN
#ifdef ESP32
// Use ADC with PIN_ADC_IN
adc.attach(PIN_ADC_IN);
#elif defined(ARDUINO_ADAFRUIT_FEATHER_RP2040)
#if defined(ARDUINO_ADAFRUIT_FEATHER_RP2040)
// Set resolution to 12 bits
analogReadResolution(12);
#endif
Expand All @@ -1630,11 +1585,6 @@ cSensor::setup(std::uint32_t uplinkPeriodMs) {
prepareSleep();
}
#endif

#if defined(ADC_EN) && defined(PIN_ADC3_IN)
// Use ADC3 with PIN_ADC3_IN
adc3.attach(PIN_ADC3_IN);
#endif

#if defined(MITHERMOMETER_EN) || defined(THEENGSDECODER_EN)
bleSensors.begin();
Expand Down Expand Up @@ -1724,59 +1674,26 @@ cSensor::loop(void) {
}

#ifdef ADC_EN
//
// Get supply / battery voltage
//
uint16_t
cSensor::getVoltage(void)
{
float voltage_raw = 0;
for (uint8_t i=0; i < UBATT_SAMPLES; i++) {
#ifdef ESP32
voltage_raw += float(adc.readMiliVolts());
#else
voltage_raw += float(analogRead(PIN_ADC_IN)) / 4095.0 * 3300;
#endif
}
uint16_t voltage = int(voltage_raw / UBATT_SAMPLES / UBATT_DIV);

log_d("Voltage = %dmV", voltage);

return voltage;
}

//
// Get supply / battery voltage
//
#if defined(ESP32)
uint16_t
cSensor::getVoltage(ESP32AnalogRead &adc, uint8_t samples, float divider)
{
float voltage_raw = 0;
for (uint8_t i=0; i < samples; i++) {
voltage_raw += float(adc.readMiliVolts());
}
uint16_t voltage = int(voltage_raw / samples / divider);

log_d("Voltage = %dmV", voltage);

return voltage;
}
#else
//
// Get supply / battery voltage
//
uint16_t
cSensor::getVoltage(pin_size_t pin, uint8_t samples, float divider)
cSensor::getVoltage(uint8_t pin, uint8_t samples, float divider)
{
float voltage_raw = 0;
for (uint8_t i=0; i < samples; i++) {
voltage_raw += float(analogRead(pin)) / 4095.0 * 3.3;
#if defined(ESP32)
voltage_raw += float(analogReadMilliVolts(pin));
#else
voltage_raw += float(analogRead(pin)) / 4095.0 * 3300;
#endif
}
uint16_t voltage = int(voltage_raw / samples / divider);

log_d("Voltage = %dmV", voltage);

return voltage;
}
#endif
#endif

#ifdef ONEWIRE_EN
Expand Down Expand Up @@ -1881,7 +1798,7 @@ cSensor::doUplink(void) {
uint16_t supply_voltage = getVoltage();
#endif
#if defined(ADC_EN) && defined(PIN_ADC3_IN)
uint16_t battery_voltage = getVoltage(adc3, ADC3_SAMPLES, ADC3_DIV);
uint16_t battery_voltage = getVoltage(PIN_ADC3_IN, ADC3_SAMPLES, ADC3_DIV);
#endif
bool mithermometer_valid = false;
#if defined(MITHERMOMETER_EN) || defined(THEENGSDECODER_EN)
Expand Down
8 changes: 5 additions & 3 deletions BresserWeatherSensorTTNCfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@
// 20240325 Added configuration for M5Stack Core2 with M5Stack Module LoRa868
//
// Note:
// Depending on the environment, selecting M5Stack Core2 defines
// either ARDUINO_M5STACK_Core2 or ARDUINO_M5STACK_CORE2
// so both variants have to be checked!!!
// Depending on board package file date, either
// ARDUINO_M5STACK_Core2 or ARDUINO_M5STACK_CORE2
// is used - see https://github.com/espressif/arduino-esp32/issues/9423!
// Consequently both variants have to be checked!!!
//
// ToDo:
// -
Expand Down Expand Up @@ -156,6 +157,7 @@
#define BATTERY_LOW 3200
#endif


// Enable sleep mode - sleep after successful transmission to TTN (recommended!)
#define SLEEP_EN

Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ Mains adapter or Li-Ion battery (with or without solar charger) - depending on d
| ESP32Time | r |
| BresserWeatherSensorReceiver | r |
| Preferences | r (RP2040) |
| ESP32AnalogRead | o |
| OneWireNg | o |
| DallasTemperature | o |
| NimBLE-Arduino + ATC_MiThermometer | o |
Expand Down Expand Up @@ -434,7 +433,6 @@ Based on
* [MCCI Arduino LoRaWAN Library](https://github.com/mcci-catena/arduino-lorawan) by Terry Moore, MCCI
* [Lora-Serialization](https://github.com/thesolarnomad/lora-serialization) by Joscha Feth
* [ESP32Time](https://github.com/fbiego/ESP32Time) by Felix Biego
* [ESP32AnalogRead](https://github.com/madhephaestus/ESP32AnalogRead) by Kevin Harrington (madhephaestus)
* [OneWireNg](https://github.com/pstolarz/OneWireNg) by Piotr Stolarz
* [DallasTemperature / Arduino-Temperature-Control-Library](https://github.com/milesburton/Arduino-Temperature-Control-Library) by Miles Burton
* [NimBLE-Arduino](https://github.com/h2zero/NimBLE-Arduino) by h2zero
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"RadioLib": "jgromes/RadioLib#semver:^6.5.0",
"lora-serialization": "thesolarnomad/lora-serialization#semver:^3.2.1",
"ESP32Time": "fbiego/ESP32Time#semver:^2.0.6",
"ESP32AnalogRead": "madhephaestus/ESP32AnalogRead#semver:^0.2.2",
"OneWireNg": "https://github.com/pstolarz/OneWireNg#semver:^0.13.1",
"Arduino-Temperature-Control-Library": "milesburton/Arduino-Temperature-Control-Library#semver:^3.9.1",
"NimBLE-Arduino": "h2zero/NimBLE-Arduino#semver:^1.4.1",
Expand Down

0 comments on commit 86bd73b

Please sign in to comment.