Skip to content
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

espressif: Validate sample rate #9563

Merged
merged 1 commit into from
Aug 27, 2024
Merged

espressif: Validate sample rate #9563

merged 1 commit into from
Aug 27, 2024

Conversation

jepler
Copy link
Member

@jepler jepler commented Aug 27, 2024

The reported code used an invalid sample rate. This improves the error message so that it is not a generic IDFError.

The new error message says:

ValueError: sample_rate must be 20000-2000000

I verified at a sample rate of 20000 that I could read both 0 and 65535 using a jumper wire to another GPIO pin configured as a digital output.

My test code, run on a feather esp32 v2:

import digitalio, board, analogbufio, array

N = 30
rate = 20000

buffer = array.array("H", [0x0000] * N)
with digitalio.DigitalInOut(board.MISO) as d, analogbufio.BufferedIn(board.A3, sample_rate=rate) as adc:
    for v in (0, 1):
        d.switch_to_output(v)
        adc.readinto(buffer)
        for i in range(N):
            print(i, buffer[i])

Closes #9504

The reported code used an invalid sample rate. This improves
the error message so that it is not a generic IDFError.

The new error message says:
```
ValueError: sample_rate must be 20000-2000000
```

I verified at a sample rate of 20000 that I could read both 0
and 65535 using a jumper wire to another GPIO pin configured as a
digital output.
Closes adafruit#9504
@jepler
Copy link
Member Author

jepler commented Aug 27, 2024

(the rate range is a bit different for each microcontroller, so esp32s3 for instance might display a different range in its error message)

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@tannewt tannewt merged commit 30a4bd1 into adafruit:main Aug 27, 2024
210 checks passed
@graeme-winter
Copy link

Yes thank you for the fix 👍

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.

analogbufio.BufferedIn fails on ItsyBitsy esp32
3 participants