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

Very basic Heltec V3 battery support #30

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

macvenez
Copy link

@macvenez macvenez commented Sep 2, 2024

It should be more readable now.
Thanks.

In case you haven't read from the other pull request before closing it:
Offtopic: is there any way to debug through serial console (for example read battery voltage and serial messages)?
I read from the code that the default baudrate for serial should be 115200 but doing screen /dev/ttyUSB0 115200 only spits out wrong characters.

@jacobeva
Copy link

jacobeva commented Sep 3, 2024

We will have to wait for someone to volunteer to test this, at present. Could you also please undo your last commit in this PR? One feature per PR please :)

@macvenez
Copy link
Author

macvenez commented Sep 3, 2024

Thanks for understanting, I removed the wrong commit 👍
Please let me know if I have to completely remove the commit or if it's fine like this.
Sorry, I'm starting to use git basically now

@jeremybox
Copy link

How would you like me to test? I have this device and some free time.

@macvenez
Copy link
Author

macvenez commented Sep 3, 2024

Hi, I started on mine, but without a serial output for debug is quite difficult to understand wether it's working or not (I actually don't know how to accomplish it as it only has kiss messages over serial and I jave to decode them by hand).

When battery is connected and charging it shows not all bars, while when connected to USB shows full bars.
I'd like to have some more indications on serial debug in order to calibrate and map voltage and percentage correctly.

If you want, in the mean time you can check if it's at least reading different states (indicated by battery bars on the screen) when battery is connected or not.

Thanks!

@jacobeva
Copy link

jacobeva commented Sep 4, 2024

Sorry, I'm starting to use git basically now

That's totally fine :) I will probably just squash the commits when I merge anyway.

You could always add a simple print statement to your code which prints out the percentage for you to read. Don't commit that change, though. That will let you check if it functions correctly. If you have a multimeter to hand, you can calculate the percentage yourself by measuring the battery voltage and then see if the device matches :)

I can see an issue in the implementation. Basically, when a battery is charging, the voltage that's fed into it is actually fed in on the same line that you're reading from to check the voltage. This obviously creates a problem, because the value you're reading when charging is useless for telling the battery percentage.

If you have a look here, I added the functionality on the RAK4631 to check if it's currently charging to fix this behaviour, as has been done on most of the previous boards as well. So, your next task is to figure out what you can check on the board to see if you're connected to USB power or not :)

@macvenez
Copy link
Author

macvenez commented Sep 4, 2024

Hi, I managed to get the factory calibrated ADC results instead of the raw ones and they're much better.

Now it should show the "plug" icon only when the battery is disconnected.
Unfortunately (as far as I know) there's no way to get whether the device has USB plugged in or not.
Furthermore the device ADC is not precise enough (at least on my board) to get stable and consistent readings and check if the battery is charging or not by simply reading the ADC and checking if the voltage is rising or falling (as I understand correctly that's what your code for the RAK is doing).

On the other hand this device has an onboard LED that lights up when the device is charging so if it's not a problem for you I'll leave battery_state = BATTERY_STATE_DISCHARGING so it always shows the current battery percentage (and plug icon when no battery connected) and the charging process would be indicated only by the onboard charging LED.

If that's fine all add this commit containing all these changes

@jacobeva
Copy link

jacobeva commented Sep 5, 2024 via email

@macvenez
Copy link
Author

macvenez commented Sep 5, 2024

Actually the device only "pmu" is the battery charging circuit and a voltage divider on battery to measure voltage through and ADC (which could be enabled by closing a mosfet).
If you have time you can look at the schematic here. I couldn't find any other way do check if power is coming through USB or battery as they both are connected to the same 3.3v LDO regulator and selected through an ideal diode...

@jacobeva
Copy link

I will take a look into this myself soon when I have time. Thanks for your work on this thus far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants