Skip to content

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

Merged
merged 2 commits into from
Dec 2, 2022
Merged

Conversation

tannewt
Copy link
Member

@tannewt tannewt commented Dec 2, 2022

  • 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 #7226

* 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
@tannewt tannewt added this to the 8.0.0 milestone Dec 2, 2022
@tannewt tannewt requested a review from dhalbert December 2, 2022 01:47
@tannewt
Copy link
Member Author

tannewt commented Dec 2, 2022

@latkinso42 Please review as well.

Copy link
Collaborator

@dhalbert dhalbert left a 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.

@tannewt
Copy link
Member Author

tannewt commented Dec 2, 2022

Ok, I've made the changes.

@tannewt tannewt requested a review from dhalbert December 2, 2022 18:21
@dhalbert
Copy link
Collaborator

dhalbert commented Dec 2, 2022

Thanks, will test on hw now.

Copy link
Collaborator

@dhalbert dhalbert left a 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!

@tannewt tannewt merged commit 4c064c2 into adafruit:main Dec 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refine analogbufio API
2 participants