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

Implemented battery voltage measurement for Heltec WiFi LoRa 32 V3 #16

Merged
merged 6 commits into from
May 2, 2024

Conversation

matthias-bs
Copy link
Owner

@evon800c
Copy link
Collaborator

Hi @matthias-bs,
i'll try to do some test in the next few days.
If you need specific test, let me know.
Davide

@matthias-bs matthias-bs self-assigned this Apr 29, 2024
@matthias-bs matthias-bs added the enhancement New feature or request label Apr 29, 2024
@matthias-bs
Copy link
Owner Author

@evon800c Could you please check the battery voltage measurement with and without a battery? I'm not sure if VBAT equals VUSB / VDD_5V in the latter case.

@evon800c
Copy link
Collaborator

Hi, @matthias-bs
Could you please tell me the pins and headers (j3/j2) where you want me to take the measurement?
https://resource.heltec.cn/download/WiFi_LoRa_32_V3/HTIT-WB32LA(F)_V3.png
I imagine that the battery is the one connected to the connector below.
davide

@matthias-bs
Copy link
Owner Author

Hi @evon800c ,

the battery connector is a white JST connector on the bottom side of the PCB.

  • If unconnected, the supply voltage from USB should be reported correctly and the device should not enter sleep mode immediately for battery deep-discharge protection.
  • If a battery (or lab power supply with an appropriate voltage) is connected, this should be measured correctly, too.

The second case can only be tested if USB is not connected (otherwise you will still see the voltage coming from USB), which means you cannot check it in the debug output. Instead you have to check the LoRaWAN uplink payload.

I have recently added some documentation and the payload formatters, so you can hopefully use this without too much effort.

Best regards and a happy May Day,
Matthias

@evon800c
Copy link
Collaborator

evon800c commented May 2, 2024

Hi, @matthias-bs

you have perfectly described what i have in mind.

I'll try to explain what is my lab environment at the moment. I have 2 heltec board with the same code, that are in power on. Both of them are receiving data from the same weather station. I'm doing some test to understand the better way to manage the energy... batteries, solar power panel size and and so on.
Both boards are not connected to pc usb, so as you correctly say, i can't see any info from debug side. I observe data only from uplink "supply_v" field.

node 1
is connect with usb to power line, has no battery attached and as you can see from image 1 has more or less the same supply_v value ~ 3.9V, on my tester i see 4118/9mv.

node 2
is connect with jst board connector to a 18650 (3.7V 2600mh), has no other external power atteched. and as you can see from image node 1 the value go down as i expected.
During the night at ~4:00 AM change the sleeping time to 900s.

From my point of view, all is working fine.

At "2024-05-02 11:45:45 GMT+2" the uplink supply_v show 3325, while on tester i can see 3516, i suppose that some adjust is need to be done.

I have attached the usb supply on node 2, also with battery attached (this board can charge the battery when powered with usb)
on tester i can see 3890 in increasing. I'm waiting for other uplink value to read the supply_v value.

At "2024-05-02 12:00:58 GMT+2" the uplink supply_v show 3995, while on tester i can see 4112.
The new voltage level permit to change sleep value and as we can see in the images ... supply_v increase as expected.

At "2024-05-02 13:44:58 GMT+2" the uplink supply_v show 4020, while on tester i can see 4196.

I hope this information can be useful to you. For any other test and/or consideration, i'm here.

Thanks a lot Davide

image 1
01

image 2
02

image 3
03

@matthias-bs matthias-bs merged commit 3d6ee32 into main May 2, 2024
10 checks passed
@matthias-bs matthias-bs deleted the feature-heltec-v3-battery-voltage branch May 2, 2024 17:11
@matthias-bs
Copy link
Owner Author

Hi @evon800c,

thank you very much for testing! The difference in voltage measurements between the ADC readings and your tester is a little bit concerning. 100...200mV difference means a lot when measuring a li-ion battery voltage. I think the usual effects like tolerances and voltage drop across the supply connections are not big enough to cause such a difference.

Maybe this is caused by the weird implementation of the voltage divider as described in #4 (comment). If this is the case, the accuracy could be improved by using a lower attenuation of the ADC input.

Best regards,
Matthias

BTW: You seem to use InfluxDB & Grafana for processing and displaying the data. If you like, you could add a short tutorial on how to set this up to the project...

@matthias-bs matthias-bs linked an issue May 2, 2024 that may be closed by this pull request
@evon800c
Copy link
Collaborator

evon800c commented May 4, 2024

Hi, @matthias-bs

no problem writing something to indicate how to integrate influxdb and / or grafana, let me know what approach to take and I'll try to do something.

Note:
I don't use TTN as a LoRaWAN network, but a personal LoRaWAN network implemented with Chirpstack on my personal lab.

Davide

@evon800c
Copy link
Collaborator

evon800c commented May 4, 2024

Hi @matthias-bs,

I don't know if it can be useful... but I did some tests by varying the attenuation by inserting "analogSetPinAttenuation(ADC_CTRL, ADC_XXdb)" before the "delay (100)" in the reading of the value for the "heltec".

I report the values detected. they are not very precise but they can be a starting point.

ADC_0db    multimeter=4151 supply_v=4065 diff=86
ADC_2_5db  multimeter=4162 supply_v=4088 diff=74
ADC_6db    multimeter=4157 supply_v=3972 diff=185
ADC_11db   multimeter=4157 supply_v=3935 diff=222

cheers, Davide

@matthias-bs
Copy link
Owner Author

Hi @evon800c ,

great finding! I thought it were more complicated. I'll add it in the next release!

Thanks and have a nice evening!
Matthias

@matthias-bs
Copy link
Owner Author

Should be analogSetPinAttenuation(PIN_ADC_IN, ADC_0db), right?

@evon800c
Copy link
Collaborator

evon800c commented May 4, 2024

yes correct,

I set analogSetPinAttenuation(ADC_CTRL, ADC_2_5db); //ADC_2_5db, ADC_6db, ADC_11db to remeber the other possible values.

There is also another command "analogSetAttenuation(ADC_2_5db);" that can be used in the same way, but in that case the attenuation are applied to all pin

@matthias-bs
Copy link
Owner Author

Hmm, I mean it should be applied to the ADC input pin, not the ADC control pin (which is just used as digital output to switch the MOSFET between VBAT and the ADC input).
I just added the line to the main branch.

@evon800c
Copy link
Collaborator

evon800c commented May 4, 2024

mmmm correct

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

Successfully merging this pull request may close these issues.

Request for testing: Heltec WiFi LoRa 32 V3
2 participants