Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

battery voltage #2

Open
rigr opened this issue Feb 19, 2023 · 9 comments
Open

battery voltage #2

rigr opened this issue Feb 19, 2023 · 9 comments

Comments

@rigr
Copy link

rigr commented Feb 19, 2023

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
Copy link
Contributor

@rigr
Copy link
Author

rigr commented Feb 20, 2023

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

@rigr
Copy link
Author

rigr commented Feb 20, 2023

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
Copy link
Contributor

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
Copy link
Author

rigr commented Feb 21, 2023

:) 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
Copy link
Contributor

@rigr
Copy link
Author

rigr commented Feb 21, 2023

  • thank you! I finally spotted it in this plan in the lower left corner D1. 470k to + batt and 470k to GND.
    batt

@rigr rigr closed this as completed Feb 21, 2023
@rigr
Copy link
Author

rigr commented Mar 6, 2023

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
Copy link
Author

rigr commented Mar 6, 2023

Reopened because of strange readings.

@rigr rigr reopened this Mar 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants