Digital In/Out

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
ctmorrison
 
Posts: 75
Joined: Tue Jan 10, 2012 12:18 pm

Digital In/Out

Post by ctmorrison »

If I want to use A2 on a QT PY as a digital input, do I merely need to set it up as follows:

Code: Select all

switch = DigitalInOut(board.A2)
switch.direction = Direction.INPUT
switch.pull = Pull.UP
?

I'm also wanting to use A0 and A1 as digital output, so I'm assuming it would be similar to the above.

User avatar
adafruit_support_carter
 
Posts: 29467
Joined: Tue Nov 29, 2016 2:45 pm

Re: Digital In/Out

Post by adafruit_support_carter »

Yep. Should work.

User avatar
ctmorrison
 
Posts: 75
Joined: Tue Jan 10, 2012 12:18 pm

Re: Digital In/Out

Post by ctmorrison »

I'm getting an error on

Code: Select all

switch.pull = Pull.UP
Perhaps that's not supported on the QT PY A2 port?

User avatar
adafruit_support_carter
 
Posts: 29467
Joined: Tue Nov 29, 2016 2:45 pm

Re: Digital In/Out

Post by adafruit_support_carter »

OK, that can happen. Internal pull ups are something that not all microcontrollers provide on their digital pins. Which QT PY are you using?

User avatar
ctmorrison
 
Posts: 75
Joined: Tue Jan 10, 2012 12:18 pm

Re: Digital In/Out

Post by ctmorrison »

ESP32-S2

User avatar
ctmorrison
 
Posts: 75
Joined: Tue Jan 10, 2012 12:18 pm

Re: Digital In/Out

Post by ctmorrison »

Also, if I want to use SDA as a digital input, do I simply declare it using something like

Code: Select all

relayStatus = DigitalInOut(board.SDA)

User avatar
neradoc
 
Posts: 542
Joined: Wed Apr 27, 2016 2:38 pm

Re: Digital In/Out

Post by neradoc »

What error ? Did you import Pull ?
Please give us the full error.
Are your imports like this ?

Code: Select all

from digitalio import DigitalInOut, Pull, Direction
ctmorrison wrote:Also, if I want to use SDA as a digital input, do I simply declare it using something like
Yes, it's just the pin name, it can be used for anything you want to do with the pin.

User avatar
ctmorrison
 
Posts: 75
Joined: Tue Jan 10, 2012 12:18 pm

Re: Digital In/Out

Post by ctmorrison »

So...the pull error was my fault. I had previously done a

Code: Select all

from digital import DigitalInOut, Direction, Pull
but had subsequently removed the Pull was it wasn't being used and threw an error (in Mu).

I ended up simply adding an external pulldown resistor.

Thanks for the assist.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”