While playing with ADC to read the Lipo voltage from my expansion board, I experience strange behavior with the modulus operator on ADC readout.
Try the following :
If in the REPL I type 3601%4095 several times, no surprise I always get 3601.>>> from machine import ADC
>>> adc = ADC()
>>> lipo = adc.channel(pin='GP3')
>>> lipo()
3594
>>> lipo()
3603
>>> lipo()
3601
>>> lipo(),lipo()%4095
(3600, 3603)
>>> lipo(),lipo()%4095
(3601, 3603) <----
>>> lipo(),lipo()%4095
(3601, 3607) <----
>>> lipo(),lipo()%4095
(3602, 3602)
>>> lipo(),lipo()%4095
(3601, 3601) <----
>>> lipo(),lipo()%4095
(3602, 3602)
>>> lipo(),lipo()%4095
(3601, 3602) <----
>>> lipo(),lipo()%4095
(3602, 3600)
>>>
If I readout ADC value, the modulus to 4095 of same readout does not return the same value. See example here above.
Any thought ?
Olivier