-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Don't reset GPIO4 on the MagTag (used for voltage monitoring) #6246
Conversation
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 - thanks!
I'm happy if this fixes a problem .. but .. it would also be interesting to know what's different about ADC on a pin that has been 'reset', because if we understood that maybe we'd get better ADC behavior on all pins. |
I am working on a different fix with the same effect. |
I think there are two problems here:
Here is a test program running on CircuitPython 7.2.3, with no fixes. Notice the voltage is wrong to begin with, moves down, and then stabilizes. But it takes almost a second for that. import analogio, board, time
elapsed_msecs = 0
a = analogio.AnalogIn(board.BATTERY)
while True:
print(elapsed_msecs / 1000, a.value / 65535 * 3.3 * 2)
time.sleep(0.1)
elapsed_msecs += 100
So it is not stuck, but it is wrong for a while. Removing the reset works because it takes a while for CircuitPython to start up from a hard reset (when the pin is initially pulled up to high by the ESP-IDF reset (see I tried disabling the pullup in the So the fix in this PR works because the pin never gets the pull-up set on it. It is a bit accidental. If the ESP-IDF startup reset the pin using its own reset routine (which sets the pullup), we'd have the same problem. I'm not sure whether to keep this or to simply document that you should wait at least a second after the program starts to read @DavePutz, did you already come to this conclusion? @jepler what do you think? |
@danh, I was wondering if pins other than the GPIO4 used for the voltage monitor would have similar issues when used for ADC readings. If so, then disabling the pullup in the AnalogIn constructor might be the only solution. Also, would boards other than the Espressif boards have the same problem? |
[btw @ danh on GitHub is someone else, not me; I am @dhalbert]
I tested other
Espressif is unique in saying that enabling the pull-up causes lower power consumption. On all the other boards, we reset pins to floating with no pulls in either direction. |
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 talked with @jepler about this, and we decided to disable the pull-up( I added 99dc402), and we'll also keep your no-reset change, so that one need not wait to read the battery voltage. We can change this in the future, but for now, this is the easiest for the end user. Thanks for your work on this.
Fixes #6148. Since the re-doing of Espressif GPIO resets done as part of PR #5892 the voltage monitoring done on the MagTag by pin GPIO4 has been always returning high values. This fix avoids resetting that pin on the MagTag and allows correct readings of the voltage.