[Solved] ADC_battery example


Unfortunately the ADC example and the ADC_battery example both measure the same values (the voltage applied externally to the ADC) only that the later multiplies it by 2. Setting ADC_CTL to low has no effect and does not mesure the voltage of the attached battery (at least not when the USB power is connected and the Serial out put is visible). Am I missing something? Some wiring needed to make ADC_CTL work?

Background: I have 2 cubecell boards I want to use for solar monitoring and temperature of water in my pool. For the first use case I want to use the ADC to measure the open circuit voltage of a small panel (1V rating). But it would also be good to measure the battery voltage of the lipo battery I want to use. I’m not planning to use a solar panel as the lipo battery should last for long enough.

Regards, Marcus from Heidelberg

Hi @marcus

did you try this example? You can try this example with a USB cable connection, with USB connected, the value should close to 4.2V

The ADC example is to display the pin voltage, and the ADC_battery example is to display the battery voltage. When the battery voltage is measured, there is a voltage division in the circuit, so the pin voltage needs to be multiplied by 2 to get the battery voltage.
ADC_CTL can be pulled low directly using digitalWrite (ADC_CTL, LOW).

Yes, that’s the example I’m using. When I use it the voltage is not 4.2V on USB power but its 1.5V which is double the voltage on the ADC pin. When I use the ADC example then I get .75V which is the voltage on the ADC pin.

Maybe you can directly test the voltage of the ADC pin with a multimeter, it should be around 2V.

Yes, I have tested with a voltmeter and the ADC pin always has 0.75V as its tied to a voltage I want to measure. What is not working is the ADC_battery example where pulling ADC_CTL to low does not have the desired effect - the voltage measured is 1.5V which is not the 4.2V which I would expect when powered by USB.

I checked with a second cubecell that does not have anything tied to the ADC pin. In this case the ADC_battery example works!

I was expecting that one could measure the battery voltage with ADC_CTL low and another analog value with ADC_CTL high - this way one could measure an analog sensor value and also check on the battery voltage of the node in an IoT scenario. Too bad that this does not seem to be possible.

Workaround: Attach a voltage divider between VIN and GND and put the in between level on a GPIO pin that you make an INPUT. This way when you get close to your desired cutoff voltage for safe operation (from then on the device should only sleep) the GPIO input goes from 1 (above threshold) to 0 below threshold. Or you attach another ACD converter, or you use a digital sensor.

Why ADC does not measure voltage below approx 3,4V ?
Can I change it?
If battery volate is approx 3,3V 3,2V, ADC pin show stil 3,4 V
It is possible?


Hi, we found a bug in the source code of Vref setting, we had fixed that bug since last commit.

Install the development framework via git.

Thank You, now works fine :slight_smile: