ayoy / upython-aq-monitor

Air Quality monitor using PMS5003 sensor and WiPy development board implemented in MicroPython
MIT License
27 stars 10 forks source link

Document how one needs to plug ADC to get power measurments #1

Closed arthurlutz closed 6 years ago

arthurlutz commented 6 years ago

I have a wipy2.0 without the dev prototype board and would like to do the "measure the available battery level" that you implement in your project. Do you have an idea on how the power needs to be connected to measure the ADC ?

ayoy commented 6 years ago

Good point re: documentation, I should write some proper readme file for the project.

As it comes to the ADC circuit, have a look at the Pycom Expansion Board pinout. They're using a voltage divider with 56k and 115k resistors. The equivalent circuit looks like this:

screen shot 2018-01-15 at 17 05 06

This way the voltage at P16 pin is equal to:

V_batt * 56/(115+56) = 0.3274 * V_batt

and for 4250mV (the maximum voltage I was able to measure with a voltmeter for my battery) it would be around 1390mV. Then the ADC, as per documentation, accepts at most 1.1V, this is with 0dB attenuation. If you use 2.5dB attenuation (like I did in the example), the maximum voltage recognized by ADC would equal:

1100*(10^(2.5/20)) = 1467mV

In other words, your goal is to adjust the resistors values so that the voltage divider outputs ~1400mV and you could use the ADC with 2.5dB attenuation. You can also adjust them so that the voltage divider is always below 1100mV and use the ADC without attenuation.

Be sure to use big resistor values (hundreds of kiloohms preferably), or the battery voltage measurement circuit would drain significant current.

And, since the documentation may become outdated (the attenuation used to be 3dB earlier on, and that's how I overlooked my batteries and broke them after flashing new firmware), verify the actual maximum voltage measured by ADC using adcchannel.value_to_voltage(4095) (for 12-bit accuracy).

Let me know if anything is unclear.

ayoy commented 6 years ago

I believe this answers your problem, so let me close the issue, but feel free to reopen if you still can't get it to work.