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

ESP32S2: Add AnalogIn #3501

Merged
merged 12 commits into from Oct 9, 2020
Merged

ESP32S2: Add AnalogIn #3501

merged 12 commits into from Oct 9, 2020

Conversation

hierophect
Copy link
Collaborator

@hierophect hierophect commented Oct 1, 2020

This PR adds the AnalogIn module to the ESP32-S2 port. The IDF documentation underlying this module can be found here. The ESP32-S2 has more limited configuration options than the ESP32 for its ADC, so we assume the default settings of 13 bit width for measurements and an attenuation of 11DB for the maximum voltage range.

Also unlike the ESP32, the S2 appears to have a hard cap of 2.6V maximum for ADC readings, even at the max attenuation settings. I've asked Espressif whether this is a hardware limitation, or whether it will be raised as the S2 support matures.

This PR requires #3492 for access to the ESP_ADC_CAL component of the ESP-IDF, so it should not be merged until that is submitted. Reviewers may want to hold off until that PR is complete if they want to avoid viewing duplicate changes.

Tested on a Saola 1 Wrover on a 10k pot with a multimeter control. Accurate to ~0.1V up to the max of 2.6V.

@UnexpectedMaker
Copy link

Oooer, I was about to ask about this today!!!!
I need AnalogIn for my FeatherS2 - as I have the ALP light sensor on board.
Thanks for getting this underway @hierophect !

@anecdata
Copy link
Member

anecdata commented Oct 2, 2020

Unless I'm reading the API Reference wrong, ESP32-S2 ADC1 and ADC2 will allow full-range voltage, but Espressif says most accurate readings at 11dB are between 150 ~ 2600mV (better linearity at the high end than ESP32).

11 dB attenuation (ADC_ATTEN_DB_11) gives full-scale voltage 3.9 V (see note below)
Note
At 11 dB attenuation the maximum voltage is limited by VDDA, not the full scale voltage.
SoC | attenuation | suggested range (mV)
ESP32-S2 | 11  | 150 ~ 2600

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.

Thanks for switching those headers! Just a few questions.

ports/esp32s2/common-hal/analogio/AnalogIn.h Outdated Show resolved Hide resolved
ports/esp32s2/common-hal/analogio/AnalogOut.c Outdated Show resolved Hide resolved
ports/esp32s2/mpconfigport.h Outdated Show resolved Hide resolved
ports/esp32s2/mpconfigport.mk Outdated Show resolved Hide resolved
shared-bindings/socketpool/Socket.c Outdated Show resolved Hide resolved
locale/circuitpython.pot Outdated Show resolved Hide resolved
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.

Replied to the unresolved comments.

@hierophect
Copy link
Collaborator Author

@tannewt I removed the logging from shared-bindings - however, we could alternatively add a common-hal-log function to common-hal/microcontroller and use that, to keep things encapsulated?

@hierophect hierophect mentioned this pull request Oct 6, 2020
@hierophect hierophect added the espressif applies to multiple Espressif chips label Oct 6, 2020
@hierophect
Copy link
Collaborator Author

CI is being flaky, it's failed random boards a couple times in a row now. I don't think there's anything actually wrong with this.

@anecdata
Copy link
Member

anecdata commented Oct 6, 2020

Githib actions degraded https://www.githubstatus.com

@tannewt
Copy link
Member

tannewt commented Oct 6, 2020

Please update this now that the IDF switch is merged.

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.

Looks good overall! Just a couple questions. Thanks!

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 375676f into adafruit:main Oct 9, 2020
@hierophect hierophect deleted the esp32-analogin branch October 9, 2020 21:21
@kevinjwalters
Copy link

kevinjwalters commented Jan 10, 2021

What's the conclusion to all this? I've got a FeatherS2 running 6.1.0-rc0 which can't get above 52149 (0b1100101110110101) on A1. A Feather nRF52840 Express alongside gets to 65520 connected to same pot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
espressif applies to multiple Espressif chips
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants