Skip to content

ADC for Battery and an analog sensor #302

@I-em-zain

Description

@I-em-zain

Battery Voltage Measurement Issue on Heltec CubeCell HTCC-AB01

Hardware

  • Heltec CubeCell HTCC-AB01 v2
  • EC5 Soil Moisture Sensor (connected to GPIO1)

Issue Description

I'm developing a low cost soil moisture sensor using the Heltec CubeCell. While the soil moisture readings from my EC5 sensor are working properly, I'm experiencing issues with the battery voltage measurement functionality.

Code

#include "Arduino.h"
#include "LoRaWan_APP.h"
#define ADC_PIN GPIO1
float voltage=0;
void setup() {
  Serial.begin(115200);
  pinMode(VBAT_ADC_CTL,OUTPUT);
  digitalWrite(VBAT_ADC_CTL,HIGH);
  voltage=analogRead(ADC)*2;
  pinMode(VBAT_ADC_CTL,OUTPUT);
}
void loop() {
  Serial.println(voltage);
  delay(3000);
  int adcRaw = analogReadmV(ADC_PIN);
  Serial.print("ADC RAW: ");
  Serial.println(adcRaw);
  delay(1000);
}

Output/Results

When running the corrected code that properly attempts to read the battery voltage:

Battery Voltage: 0.00 V
Soil Moisture ADC RAW: 676 mV
Battery Voltage: 0.00 V
Soil Moisture ADC RAW: 676 mV
Battery Voltage: 0.00 V
Soil Moisture ADC RAW: 676 mV
Battery Voltage: 0.00 V
Soil Moisture ADC RAW: 250 mV
Battery Voltage: 0.00 V
Soil Moisture ADC RAW: 11 mV
Battery Voltage: 0.00 V
Soil Moisture ADC RAW: 2399 mV
Battery Voltage: 0.00 V
Soil Moisture ADC RAW: 2399 mV

Expected Behavior

The battery voltage should reflect the actual voltage of the connected battery (typically between 3.3V-4.2V for a LiPo battery).

Attempted Solutions

I've tried various approaches:

  1. Using the VBAT_ADC_CTL pin to enable/disable the battery measurement circuit
  2. Trying both analogRead(ADC) and analogReadmV(ADC) methods
  3. Trying different calculation methods to convert raw ADC readings to voltage

None of these approaches produce a correct battery voltage value. The battery voltage consistently reads as either 0.00V or an incorrect value (424.00 mV in initial tests), while manual measurements of the battery show the correct voltage.

Questions

  1. Is there a specific procedure for reading battery voltage on the HTCC-AB01 v2?
  2. Could there be a hardware issue with the battery voltage measurement circuit?
  3. Are there any known bugs with battery measurement in the current firmware?

Any assistance would be greatly appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions