setting pins high

22 views
Skip to first unread message

Luke Sjulson

unread,
Nov 5, 2020, 12:00:20 PM11/5/20
to autopilot-users
This is a very simple question, but I can't figure it out. If I'm running a task (e.g. free water), how can I set several GPIO output pins to be high for the entire duration of the experiment?

thanks!

Luke

Chris Rodgers

unread,
Nov 5, 2020, 12:25:59 PM11/5/20
to Luke Sjulson, autopilot-users
I'm not sure myself, but in case it is useful, Jonny mentioned something about a "polarity" flag in the hardware params in this previous post. May do what you need?

--
You received this message because you are subscribed to the Google Groups "autopilot-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to autopilot-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/autopilot-users/34cd6aab-52b5-43ae-aca2-3fe298bf6dddn%40googlegroups.com.

Luke Sjulson

unread,
Nov 5, 2020, 12:38:37 PM11/5/20
to autopilot-users
Thanks - I think that controls whether the "high" logic state corresponds to a physical voltage of 0 or 3.3V on the pin. I tried it, but unfortunately it doesn't help, so I think the problem is that I have to specify what state the pin is supposed to be in.

Luke

jlsaun...@gmail.com

unread,
Nov 17, 2020, 2:40:21 AM11/17/20
to autopilot-users
Sorry for the delay, time is scarce!


Yes 'polarity' determines whether something like `led.set(1)` or led.set(True)` corresponds to 3.3V (polarity=1/True) or 0V (polarity=0/False). If you set the 'pull' parameter that sets the internal pull-up/down resistor you can cause a GPIO to be in a predictable state, or else yes you can just explicitly set the pin to be in a particular state within the task description.

I'm wondering, for the purposes of further development of the stimulus_manager classes which should handle non-task-related hardware operation (eg. being able to use lasers & sounds as stimuli without needing to alter the base task which just requires stimuli"), if it would be useful to be able to declare logic states of individual pins specifically for the duration of a single *task* rather than for the entire runtime of a pilot as with the PULLUPS/PULLDOWNS prefs fields?

sorry my grammar is probably terrible, its late and i've been writing for many hours.

Luke Sjulson

unread,
Nov 18, 2020, 11:37:18 AM11/18/20
to autopilot-users
Oops, I applied to Jonny directly and not the list:

As far as I can tell, the pullups and pulldowns are for setting the internal pullup/pulldown resistors, which isn't the same as setting the pins high or low: https://raspi.tv/2013/rpi-gpio-basics-6-using-inputs-and-outputs-together-with-rpi-gpio-pull-ups-and-pull-downs

If I actually want to source current from the pins, e.g. to drive an LED, the pullup resistor isn't sufficient. At least this was what my testing found when I compared the autopilot code to my own simple python script that just manually sets the gpio pins high.

But yes, it would definitely be useful for me if I could specify the logic states of individual pins for the duration of the task!

Luke

--
Lucas L. Sjulson, MD, PhD
Assistant Professor
Department of Psychiatry and Behavioral Sciences
Dominick P. Purpura Department of Neuroscience
Albert Einstein College of Medicine
Rose F. Kennedy Center, Room 227
1410 Pelham Parkway South, Bronx, NY 10461
office: 718-430-2453, lab: 718-430-4271


jlsaun...@gmail.com

unread,
Nov 20, 2020, 6:38:38 PM11/20/20
to autopilot-users
Ah yes, wasn't sure if it was for just setting predictable state vs. sourcing current. The PULLUPS and PULLDOWNS flags are useful for eg. if you have a component attached that needs a pin to be predictable, like board pin # 7 needs to be pulled up with the hifiberry because it's a "mute" button.

Digital_Out objects set themselves in their "off" state when instantiated, which depends on the polarity flag. If you wanted to set something 'on' or 'off' for the duration of a task I would recommend subclassing the task, adding the pin to the HARDWARE declaration, and then setting in the state you want in the __init__ method (after calling the superclass __init__). I can help draft that if directions unclear! Planning an update to include a user directory where people can more easily subclass tasks to do minor modifications like these, but if you have a way you'd rather have it work lmk or PR an idea <3
Reply all
Reply to author
Forward
0 new messages