0

I am using Raspberry Pi 3 B+ with

Linux raspberrypi 5.4.83-v7+ #1379 SMP Mon Dec 14 13:08:57 GMT 2020 armv7l GNU/Linux

to control a set of relays. I set:

gpio mode 7 output
gpio mode 0 output
gpio mode 2 output
gpio mode 3 output
gpio mode 21 output
gpio mode 22 output

and then I am able to

gpio toggle <pin_number>

The relay closes if the pin value is 1 and opens if it is 0.

However, if I reboot, I have to set the above pins as output again, before being able to use them and, when the RPi boots or makes shutdown, the relays always close, as if pins were set to 1.

  1. Is it possible to permanently set the above pins as output?
  2. Is it possible to have them always set as 0, unless I explicitly write a 1 on them (or toggle them)?
1

No. The GPIO are set to default values at power-down by the hardware. Those are the values that are set when the power is restored.

At power-up all GPIO are set as inputs. GPIO 0-8 have weak internal pull-ups enabled. The other GPIO have weak internal pull-downs enabled.

These settings may be overridden by software during boot.

If you want to defeat the weak internal settings you will need to use stronger external pulls.

0

As a general rule, bidirectional GPIO pins will default to being inputs when the chip is reset or power is first applied.

It would help if you included a schematic for your connections to the relays, but if you want the pins to default to a low voltage then you probably need to add pulldown resistors to those pins.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.