batt monitoring

This commit is contained in:
Klaus K Wilting 2018-06-03 14:07:26 +02:00
parent c61b4d1d53
commit b93c80b924
3 changed files with 10 additions and 6 deletions

View File

@ -21,14 +21,14 @@ Supported ESP32 based LoRa IoT boards:
- Heltec LoRa-32 {1} - Heltec LoRa-32 {1}
- TTGOv1 {1} - TTGOv1 {1}
- TTGOv2 {1}{4} - TTGOv2 {1}{4}
- TTGOv2.1 {1} - TTGOv2.1 {1}{5}
- Pycom LoPy {2} - Pycom LoPy {2}
- Pycom LoPy4 {2} - Pycom LoPy4 {2}
- Pycom FiPy {2} - Pycom FiPy {2}
- LoLin32 with [LoraNode32 shield](https://github.com/hallard/LoLin32-Lora) {2}{3} - LoLin32 with [LoraNode32 shield](https://github.com/hallard/LoLin32-Lora) {2}{3}
- LoLin32 Lite with [LoraNode32-Lite shield](https://github.com/hallard/LoLin32-Lite-Lora) {2}{3} - LoLin32 Lite with [LoraNode32-Lite shield](https://github.com/hallard/LoLin32-Lite-Lora) {2}{3}
{1} on board OLED Display supported; {2} on board RGB LED supported; {3} on board Hardware unique DEVEUI supported; {4} special wiring needed, see instructions in /hal/ttgov2.h {1} on board OLED Display supported; {2} on board RGB LED supported; {3} on board Hardware unique DEVEUI supported; {4} special wiring needed, see instructions in /hal/ttgov2.h; {5} battery voltage monitoring supported
Target platform must be selected in [platformio.ini](https://github.com/cyberman54/ESP32-Paxcounter/blob/master/platformio.ini).<br> Target platform must be selected in [platformio.ini](https://github.com/cyberman54/ESP32-Paxcounter/blob/master/platformio.ini).<br>
Hardware dependent settings (pinout etc.) are stored in board files in /hal directory.<br> Hardware dependent settings (pinout etc.) are stored in board files in /hal directory.<br>

View File

@ -12,7 +12,7 @@
#include <driver/adc.h> #include <driver/adc.h>
#include <esp_adc_cal.h> #include <esp_adc_cal.h>
#define DEFAULT_VREF 1100 // we use adc2_vref_to_gpio() to obtain a better estimate #define DEFAULT_VREF 1100 // optional use adc2_vref_to_gpio() to obtain a better estimate
#define NO_OF_SAMPLES 64 // we do multisampling #define NO_OF_SAMPLES 64 // we do multisampling
// Local logging tag // Local logging tag
@ -49,17 +49,17 @@ static void print_char_val_type(esp_adc_cal_value_t val_type)
uint16_t read_voltage(void) uint16_t read_voltage(void)
{ {
static const adc1_channel_t channel = HAS_BATTERY_PROBE; static const adc1_channel_t channel = HAS_BATTERY_PROBE;
static const adc_atten_t atten = ADC_ATTEN_DB_0; static const adc_atten_t atten = ADC_ATTEN_DB_11;
static const adc_unit_t unit = ADC_UNIT_1; static const adc_unit_t unit = ADC_UNIT_1;
//Check if Two Point or Vref are burned into eFuse //Check if Two Point or Vref are burned into eFuse
check_efuse(); check_efuse();
//Configure GPIO used fpr ADC1 //Configure GPIO used fpr ADC1
gpio_set_direction(GPIO_NUM_35, GPIO_MODE_INPUT); //gpio_set_direction(GPIO_NUM_35, GPIO_MODE_INPUT);
//Configure ADC1 //Configure ADC1
ESP_ERROR_CHECK(adc_gpio_init(unit, (adc_channel_t) channel)); //ESP_ERROR_CHECK(adc_gpio_init(unit, (adc_channel_t) channel));
ESP_ERROR_CHECK(adc1_config_width(ADC_WIDTH_BIT_12)); ESP_ERROR_CHECK(adc1_config_width(ADC_WIDTH_BIT_12));
ESP_ERROR_CHECK(adc1_config_channel_atten(channel, atten)); ESP_ERROR_CHECK(adc1_config_channel_atten(channel, atten));
@ -79,6 +79,9 @@ uint16_t read_voltage(void)
//Convert adc_reading to voltage in mV //Convert adc_reading to voltage in mV
uint32_t voltage = esp_adc_cal_raw_to_voltage(adc_reading, adc_chars); uint32_t voltage = esp_adc_cal_raw_to_voltage(adc_reading, adc_chars);
#ifdef BATT_FACTOR
voltage *= BATT_FACTOR;
#endif
ESP_LOGI(TAG,"Raw: %d\tVoltage: %dmV", adc_reading, voltage); ESP_LOGI(TAG,"Raw: %d\tVoltage: %dmV", adc_reading, voltage);
return voltage; return voltage;
} }

View File

@ -6,6 +6,7 @@
#define DISPLAY_FLIP 1 // rotated display #define DISPLAY_FLIP 1 // rotated display
#define HAS_LED 23 // green on board LED_G3 (not in initial board version) #define HAS_LED 23 // green on board LED_G3 (not in initial board version)
#define HAS_BATTERY_PROBE ADC1_GPIO35_CHANNEL // battery probe GPIO pin -> ADC1_CHANNEL_7 #define HAS_BATTERY_PROBE ADC1_GPIO35_CHANNEL // battery probe GPIO pin -> ADC1_CHANNEL_7
#define BATT_FACTOR 2 // voltage divider 100k/100k on board
// re-define pin definitions of pins_arduino.h // re-define pin definitions of pins_arduino.h
#define PIN_SPI_SS 18 // ESP32 GPIO18 (Pin18) -- HPD13A NSS/SEL (Pin4) SPI Chip Select Input #define PIN_SPI_SS 18 // ESP32 GPIO18 (Pin18) -- HPD13A NSS/SEL (Pin4) SPI Chip Select Input