User avatar
RDK
Posts: 175
Joined: Wed Aug 13, 2014 10:19 am
Location: Wyoming and France

What is the path to GPIO?

Wed May 11, 2016 5:27 pm

I'm setting up a 2 channel relay using the GPIO pins 5 and 6. I have a working Python program which turns those pins on and off and is successfully controlling the relay.

In reading the web about GPIO settings, I have discovered that the pin settings at "time zero", ie boot up, are not always the same and vary between versions of Raspbian/Linux.

I found this code to set the pins at boot up. It needs to be included in the /etc/rc.local

Code: Select all

/usr/local/bin/gpio write 5 1
/usr/local/bin/gpio mode 5 out
However, it fails as the path to GPIO is not correct. Can anyone provide me with the correct path to the GPIO for Jessie running on a Raspberry Pi V2? As I will be porting this function to a Raspberry Pi B+ Wheezy, I would also like to know the path for that OS.

Thanks.....RDK

User avatar
joan
Posts: 13346
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: What is the path to GPIO?

Wed May 11, 2016 5:49 pm

Linux is case sensitive. GPIO is not the same as gpio.

To locate an executable you can use the which command.

On jessie

$ which gpio
/usr/local/bin/gpio

User avatar
RDK
Posts: 175
Joined: Wed Aug 13, 2014 10:19 am
Location: Wyoming and France

Re: What is the path to GPIO?

Thu May 12, 2016 4:58 am

Thanks, that worked.....RDK

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: What is the path to GPIO?

Thu May 12, 2016 5:24 am

RDK wrote: In reading the web about GPIO settings, I have discovered that the pin settings at "time zero", ie boot up, are not always the same and vary between versions of Raspbian/Linux.
The above is not true. The pinblock will be set to input on bootup; and that is the safe option, by the way! If anything, your rc.local code should make sure that the pinblock is set to inputs by default-- if anything!

The reason for this is that if you accidentally short two inputs together its harmless... but if you have stray outputs holding a 3v3 signal on them... and one of those is accidentally shorted, its sayonara PI !

Also, if you set the pinblock channel at bootup and then you run code which tries to setup the pinblock you'll get channel already in use errors (unless you do the wrong thing and quiet the error messages)!

The best thing to do is leave the pinblock alone at bootup (or set it to inputs, and cleanup() ) and then do all of your allocating to the gpio within your py code, or pigpio whatever.

do what you want, just saying...
marcus
:ugeek:

User avatar
RDK
Posts: 175
Joined: Wed Aug 13, 2014 10:19 am
Location: Wyoming and France

Re: What is the path to GPIO?

Thu May 12, 2016 4:34 pm

Marcus.....OK, thanks for your comments. I'm VERY new to the idea of using the GPOI pins on my Raspberry Pi v2. I could have started with a simple LED project, but as I had this 2 channel relay here I decided to try to do something which might eventually be useful.

At time zero, ie boot up, I want the BCM pins 5 and 6 to be "low" state which I assume means no voltage. That way there is no way the relay will be activated until I run my Python program.

So, what is your recommendation? Do nothing and always assume they will be in the "low" state? Or add some code to the rc.local to make sure? I'm kind of a "belts & suspenders" person so I probably would probably add something to the rc.local. Assuming that I do add some code to the rc.local, what would you suggest?

While I have your attention, is there a difference in the BCM, GPIO and physical numbers between the B+ and V2? My cheat sheet for the GPIO pins does not at all agree with the output from

Code: Select all

gpio readall outputs
on my Raspberry Pi V2.

Thanks in advance for any help and clarifications.....RDK

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

Re: What is the path to GPIO?

Thu May 12, 2016 4:40 pm

RDK wrote:At time zero, ie boot up, I want the BCM pins 5 and 6 to be "low" state which I assume means no voltage.
You probably want to use a Device Tree Overlay to set the GPIO state as soon as possible after booting. What state you need will depend on what hardware you have attached.

You might need pull-up or pull-down resistors as well to keep the signals as desired until the SoC has initialised the GPIO pins.

If the pins have pull-up or pull-downs, are initialised as inputs by default, you probably won't need to use a Device Tree Overlay.

dhawal
Posts: 8
Joined: Wed Sep 07, 2016 9:32 pm

Re: What is the path to GPIO?

Thu Sep 15, 2016 12:55 am

Can someone give an example of how a code would be written for an led including declaring the pins because I can't get my pi to work and I was wondering if Jessie has a different way of declaring pins than wheezy

Mension1234
Posts: 27
Joined: Wed Jul 13, 2016 8:19 pm

Re: What is the path to GPIO?

Thu Sep 15, 2016 1:27 am

It might be easier to control GPIO pins using python. For example:

Code: Select all

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(5, GPIO.OUT) #initialize GPIO pin 5

GPIO.output(5, GPIO.HIGH)
time.sleep(2)
GPIO.output(5, GPIO.LOW)
This would turn on GPIO pin 5 for 2 seconds.

alexjoei
Posts: 1
Joined: Tue Feb 13, 2018 2:48 pm

Re: What is the path to GPIO?

Tue Feb 13, 2018 3:04 pm

Hello,

Maybe that topic is resolved in another thread but I have not been able to find it. Which folders uses w10 iot on a raspberry pi 3 B to manage GPIO. I know that for Linux distribution is /sys/class/gpio/, but no idea about windows. Anyone Knows? If also anyone can tell me some library to use(I'm using .Net Core 2 C#) to manage GPIO thats works properly it would be nice. Thanks

Return to “Windows 10 for IoT”

Who is online

Users browsing this forum: No registered users and 1 guest