osmosis311
Posts: 4
Joined: Thu Jun 16, 2016 2:02 am

GPIO Status on Boot

Mon Jul 04, 2016 2:27 am

I have a project I'm working on where I've got a power switch with inputs for a relay controlled by a NodeJS app on my Pi. The relay is triggered by +5V. When my Pi 2 boots, the GPIO's are HIGH, and the relay gets triggered.

Is there any way to get the GPIO pins not to be high when the system boots? How do others get around this issue?

Thanks!

User avatar
rpdom
Posts: 17172
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: GPIO Status on Boot

Mon Jul 04, 2016 7:49 am

Which pins are you using?

Most GPIOs are set to input at boot, but some of them have the pull-up resistors set and some have pull-down. You could put in an external pull-down resistor of your own to override the internal one. Something around 4.7K should do it.

(except pins 3 and 5 GPIO 2 and 3, which have strong external pull-up resistors on the board. 1.8K, IIRC)

gordon77
Posts: 5036
Joined: Sun Aug 05, 2012 3:12 pm

Re: GPIO Status on Boot

Mon Jul 04, 2016 7:53 am

Which relay is it and how is it wired ?. Some relay boards are activated by a low.

User avatar
faramon
Posts: 123
Joined: Sat Jun 11, 2016 8:36 am
Location: Croatia

Re: GPIO Status on Boot

Thu Jul 07, 2016 8:53 am

osmosis311 wrote: Is there any way to get the GPIO pins not to be high when the system boots? How do others get around this issue?
I do autostart with python script.

1. Do DESKTOP script (i name it MyPiAutostart.desktop) with this code into it and put this desktop file into /home/pi/.config/autostart folder:
[Desktop Entry]
Type=Application
Name=MyPiAutostart
Exec=sudo python2 /home/pi/myFolder/checkAndSetGPIO.py # with path you have and yours filename
StartupNotify=false

2. Python script checkAndSetGPIO.py contains:
#!/usr/bin/python

import RPi.GPIO as GPIO
import time

pin1 = 17

GPIO.setmode(GPIO.BCM) # choose BCM or BOARD
GPIO.setwarnings(False)

GPIO.setup(pin1, GPIO.OUT) # set a port/pin as an output
GPIO.output(pin1, GPIO.LOW) # set port/pin value to 1/GPIO.HIGH/True in your case
#time.sleep(0.3) # sleep for 'n' seconds

and that is all. Now, on reboot it will check and set pin gpio 17.

Faramon

Return to “General discussion”