-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Rework the analogbufio API. #7294
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
Conversation
* read() is now readinto() and takes the buffer to write into. * readinto() returns the number of valid samples. * readinto() can be interrupted by ctrl-c. * readinto() API doesn't support signed numbers because it never did. * sample_rate is now required in the constructor because supported values will vary per-port. * 16 bit values are full range. 12 bit samples from RP2040 are stretched in the same way they are for AnalogIn. Fixes micropython#7226
@latkinso42 Please review as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! A few changes. Did not test on hardware yet.
Ok, I've made the changes. |
Thanks, will test on hw now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested on a Feather RP2040, connecting A0 and A1 to ground and 3.3V. I tested both 8 and 16-bit reads. The values I read are in the range I expect, but are surprisingly noisy, which is weird. I tried samples rates of 1000-664000. But plain old AnalogIn
also seems to be noisy. So I think the module is working fine, but we might want to look at whether we are setting up the ADC properly in general.
Pinging @latkinso42 here too.
In any case, thanks for the API improvements!
Fixes #7226