BPI-STEAM / BPI-Leaf-S3-Doc

MIT License
7 stars 6 forks source link

battery voltage #2

Open rigr opened 1 year ago

rigr commented 1 year ago

Please help me writing a small arduino sketch that monitors the voltage of the battery connected to the bpi-leaf-s3. I'd like to see he voltage on a small oled and when the voltage is below a certain value (for example 3.7V) the leaf should go into deep sleep. What pin should be read? what multiplication is needed to give a good value? I tried A13 but am not happy yet. :) And if there is a better place to ask - please let me know. Thank you and best regards!

Wind-stormger commented 1 year ago

https://github.com/nlamprian/LiFuelGauge

rigr commented 1 year ago

thanks for your reply. Is there a on-board way to measure the voltage without using external hardware?

rigr commented 1 year ago

TTGO-T-display for example allows monitoring the voltage using float measurement = (float)analogRead(34); float battery_voltage = (measurement / 4095.0) * 7.26; So is there a pin on bpi-leaf-s3 that allows the same?

Wind-stormger commented 1 year ago

Different lithium batteries have different characteristics.

You can do a statistical experiment, record the histogram of your battery voltage and power, and then design a function that meets your needs.

I can't give you the answer directly.

You have found a suitable example.

How to do it depends on you.

Enjoy development 👍

rigr commented 1 year ago

:) well, thanks for your reply. All I wanted to know was what pin to monitor for the battery voltage, but it's ok, if you can't tell me. I can use two 100k resistors and build a voltage divider, and connect + from the battery, but it would be nice if no external parts were needed.

Wind-stormger commented 1 year ago

https://github.com/BPI-STEAM/BPI-Leaf-S3-Doc/blob/main/sch/BPI-Leaf-S3-Chip-V0.1A.pdf

GPIO14

rigr commented 1 year ago
rigr commented 1 year ago

I still have issues measuring the voltage. Here is my code. Strange thing happens: If I use it as displayd below I get reading of 2320 to 2395 without a battery attached. If I have both serial.println - statements, the first is about 2200 while the other one is higher and if I comment out the first measurement the serail shows values of about 1900-2050.

With a battery atached and both readings I get values like:

2032.00 2381.00

2036.00 2386.00

2032.00 2383.00

2037.00 2383.00

2036.00 2379.00

2033.00 2379.00

2031.00 2386.00

It looks strange that analogRead(14) in a double is so much lower than (float)analogRead(14).

Is there an explanation or am I doing something wrong?

Thank you!

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:
  double reading = analogRead(14);  
  // Serial.println(reading);
  Serial.println(String((float)analogRead(14)));
  Serial.println(" ");
  delay(2000);
}
rigr commented 1 year ago

Reopened because of strange readings.