0

Setting Pull Up/Down state for SAMD21
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Setting Pull Up/Down state for SAMD21

by jerryn on Mon Jan 16, 2017 1:01 pm

I am trying to test using the buttons on the Feather OLED connect to a Feather M0 AdaLogger.
From the Docs - Button A is on GPIO9, Button B is on 6 and Button C is on 5
Button B has a 100k Pullup installed on the board
Button A is on GPIO 9 which is also used to read the Vbat and sits between 2 100K resistors from Vbat to Ground, so it is essentially Pulled up, I think.
Button C has nothing so it needs to be set.
Can anyone give me an example of how to set the Pull Up/Down state? I am not getting very far via the docs.
I think it should be settable at the time buttonX.switch_to_input is set, but I'm not having any success with the syntax.
Here is the code I am running but all the inputs are left to their defaults.
This works for A an B (B exits the program) but C is just floating.
If anyone know how to set the Button C to Pull Up, please let me know.

Code: Select all | TOGGLE FULL SIZE
import nativeio
from board import *
import time

buttonA = nativeio.DigitalInOut(D9)
buttonB = nativeio.DigitalInOut(D6)
buttonC = nativeio.DigitalInOut(D5)

buttonA.switch_to_input()
buttonB.switch_to_input()
buttonC.switch_to_input()

while (buttonB.value):
    print(buttonA.value,buttonB.value,buttonC.value)
    time.sleep(.1)

buttonA.deinit()
buttonB.deinit()
buttonC.deinit()


Thanks!

jerryn
 
Posts: 1501
Joined: Sat Sep 14, 2013 9:05 am

Re: Setting Pull Up/Down state for SAMD21

by tannewt on Mon Jan 16, 2017 2:30 pm

jerryn, Congrats! You found a bug! I'll fix it shortly in master. The gist is that the pull parameter is incorrectly still called value internally. So, in 0.8.2 you can do:

Code: Select all | TOGGLE FULL SIZE
buttonC.switch_to_input()
buttonC.pull = nativeio.DigitalInOut.Pull.up

# Or leverage the bug
buttonC.switch_to_input(value=native.DigitalInOut.Pull.up)


Thanks again for trying CircuitPython! We are making it better with your help.

tannewt
 
Posts: 2496
Joined: Thu Oct 06, 2016 8:48 pm

Re: Setting Pull Up/Down state for SAMD21

by tannewt on Mon Jan 16, 2017 3:13 pm

And now the fix is checked in and the docs updated.

tannewt
 
Posts: 2496
Joined: Thu Oct 06, 2016 8:48 pm

Re: Setting Pull Up/Down state for SAMD21

by jerryn on Mon Jan 16, 2017 3:14 pm

Whew! I feel much better ;-)
I tried
buttonC.pull = nativeio.DigitalInOut.Pull.up
and the syntax works so the script runs, bit I am not seeing gate expected effect.
I would expect buttonC.value to go to True unless the button is pressed, correct?
Instead, it still reads False unless I manually connect 3.3V to the Pin.

Is this a hardware issue with the pull_up or an implementation issue in CircuitPython?

jerryn
 
Posts: 1501
Joined: Sat Sep 14, 2013 9:05 am

Re: Setting Pull Up/Down state for SAMD21

by jerryn on Mon Jan 16, 2017 3:17 pm

Thanks for the quick update I'll try the new version and let you know how it works.

jerryn
 
Posts: 1501
Joined: Sat Sep 14, 2013 9:05 am

Re: Setting Pull Up/Down state for SAMD21

by jerryn on Mon Jan 16, 2017 3:34 pm

OK the the new 0.8.2-2 version this works fine:
Code: Select all | TOGGLE FULL SIZE
import nativeio
from board import *
import time

buttonA = nativeio.DigitalInOut(D9)
buttonB = nativeio.DigitalInOut(D6)
buttonC = nativeio.DigitalInOut(D5)

buttonA.switch_to_input()
buttonB.switch_to_input()
buttonC.switch_to_input(pull=nativeio.DigitalInOut.Pull.up)
while (buttonB.value):
    print(buttonA.value,buttonB.value,buttonC.value)
    time.sleep(.1)

buttonA.deinit()
buttonB.deinit()
buttonC.deinit()


but the alternate method of using:
Code: Select all | TOGGLE FULL SIZE
buttonC.pull = nativeio.DigitalInOut.Pull.up

is not working for me. ...yet.

jerryn
 
Posts: 1501
Joined: Sat Sep 14, 2013 9:05 am

Re: Setting Pull Up/Down state for SAMD21

by tannewt on Mon Jan 16, 2017 7:34 pm

Yup, you are right again! I just pushed a fix for .pull which fixes both setting it and reading it back from the registers. Thanks!

tannewt
 
Posts: 2496
Joined: Thu Oct 06, 2016 8:48 pm

Re: Setting Pull Up/Down state for SAMD21

by jerryn on Mon Jan 16, 2017 10:31 pm

Thanks again for the quick response. It'll be tomorrow evening before I can test the update. I'll let you know how it goes.
This has been fun!

jerryn
 
Posts: 1501
Joined: Sat Sep 14, 2013 9:05 am

Re: Setting Pull Up/Down state for SAMD21

by tannewt on Mon Jan 16, 2017 10:34 pm

No problem! Your help is appreciated.

tannewt
 
Posts: 2496
Joined: Thu Oct 06, 2016 8:48 pm

Re: Setting Pull Up/Down state for SAMD21

by jerryn on Tue Jan 17, 2017 5:41 pm

I updated to 0.8.2-3 and both of the pull options now are working.
Thanks for the quick fix.

jerryn
 
Posts: 1501
Joined: Sat Sep 14, 2013 9:05 am

Re: Setting Pull Up/Down state for SAMD21

by tannewt on Tue Jan 17, 2017 6:04 pm

No problem. Thanks for finding the bugs!

tannewt
 
Posts: 2496
Joined: Thu Oct 06, 2016 8:48 pm

Please be positive and constructive with your questions and comments.