nick8967
Posts: 114
Joined: Fri Mar 25, 2016 11:02 pm

GPIOs working in parallel

Wed Nov 06, 2019 10:27 pm

Hello,
Can I have different GPIOs working in parallel.
For example can I have
GPIO 17 -----> working as input
GIPO 27 -----> working as input
GPIO 22 -----> working as output
at the same code? and nearly at the same time?

dickon
Posts: 631
Joined: Sun Dec 09, 2012 3:54 pm
Location: Home, just outside Reading

Re: GPIOs working in parallel

Wed Nov 06, 2019 10:33 pm

It would be pretty useless if you couldn't...

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 5260
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: GPIOs working in parallel

Wed Nov 06, 2019 10:43 pm

nick8967 wrote: Hello,
Can I have different GPIOs working in parallel.
...
Yes! FWIW here's an example: http://www.cpmspectrepi.uk/raspberry_pi ... alLCD.html
Trev.
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, B2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, A+ and a B2) but Buster on the P4B's. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

User avatar
HermannSW
Posts: 1758
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: GPIOs working in parallel

Thu Nov 07, 2019 2:56 pm

nick8967 wrote:
Wed Nov 06, 2019 10:27 pm
Can I have different GPIOs working in parallel.
For example can I have
GPIO 17 -----> working as input
GIPO 27 -----> working as input
GPIO 22 -----> working as output
at the same code?
Yes, you can use C interface for pigpio library, you just register the same alert function for the GPIOs:
http://abyz.me.uk/rpi/pigpio/cif.html#gpioSetAlertFunc
and nearly at the same time?
In case every millisecond is "nearly the same time" for you, the yes. From above pigpio page:
The thread which calls the alert functions is triggered nominally 1000 times per second.
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

PiGraham
Posts: 3678
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: GPIOs working in parallel

Thu Nov 07, 2019 3:12 pm

nick8967 wrote:
Wed Nov 06, 2019 10:27 pm
Hello,
Can I have different GPIOs working in parallel.
For example can I have
GPIO 17 -----> working as input
GIPO 27 -----> working as input
GPIO 22 -----> working as output
at the same code? and nearly at the same time?
You can certainly set au gpios as a mix of inputs and outputs.
What do you mean by "nearly at the same tme?
I should think any gpio library could configure three gpio in less than a millisecond.

It would be a very unusual application where normal methods are not adequate.
Why can't you configure step bu step as input, input, output?

If you need it faster than that I think GPIO are configured in banks by writing to control registers. Using that method all gpio pins controlled by the register are configured at the same time and discrepancies are probably in the nanosecond range.
Some libraries may allow register control from user code otherwise you may need to get low level to write the registers.
See:
https://elinux.org/RPi_GPIO_Code_Sample ... ter_access

hippy
Posts: 6491
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: GPIOs working in parallel

Thu Nov 07, 2019 5:05 pm

nick8967 wrote:
Wed Nov 06, 2019 10:27 pm
and nearly at the same time?
Yes, very nearly at the same time.

The only things one cannot do simultaneously, because of the internal architecture of the chip, is simultaneously turning on a pin while turning another off, or reading the pins while turning others on or off, or vice-versa, but all those things can be done separately in incredibly fast succession.

The programming language and libraries you use will likely dictate just how quickly you can do things in succession, but in most cases, if just talking about 'can I make a LED turn on and off when I push and release a button', the answer is yes.

Return to “General discussion”