WiPy ADC resolution
-
It seems I'm unable to vary the ADC resolution from 12 bits. The doco says 9, 10, 11 and 12 bits are valid.
import pycom import machine pycom.heartbeat(False) adc = machine.ADC() apin = adc.channel(pin='P13',attn=adc.ATTN_11DB) adc.init(bits=11) print ("Count:",apin()," Voltage:",apin.voltage())The above code gives:
Traceback (most recent call last): File "<stdin>", line 9, in <module> ValueError: invalid argument(s) value >The only value that doesn't give the error is "bits=12".
Is my syntax correct?
-
@Jonno: There is indeed an inconsistency in the code. While the adc instance creating call accepts all values for bits between 9 and 12, the adc.init() call only accepts 12. So you can use for instance:
adc = machine.ADC(bits=11)Edit: Looking at the implementation of adc.init(), it looks like the assignment of the bits value to pyb_adc_obj_t->width is missing. Then, the default value 12 is used. So it may be wrong anyhow.
-
@robert-hh thanks for that. machine.ADC(bits=11) is a better way of defining the resolution anyway.
-
@Jonno I raised an issue about adc.init() which also contains the fixed function code. https://github.com/pycom/pycom-micropython-sigfox/issues/324
I could also make a PR, starting the fight with the git dragon. -
@robert-hh Ok thanks for that. Glad to perhaps make a small contribution to an improvement to the code :-)
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login