6

I am using this tutorial: https://www.youtube.com/watch?v=b6ZagKRnRdM to connect that relay board to my PI, everything works fine, but I have noticed that till the GPIOs are set to out the 2 smd leds are on (lower light), after boot the GPIOs used are set to OUT then the smd leds are off, after that everything works as expected, when I turn on relays the leds are on glowing, and when I turn off relays leds are off. My question is if that behaviour is normal ( ...2 smd leds are on (lower light)... )?

The connection is made as shown in the video at 9:08. Pins used for IN1, IN2 are GPIO 27 and GPIO 22.

OK! My question is... Is that normal to have leds on (low light) on above GPIOs while they are configured to be IN? ( After the system boots and I set the pins as OUT then everything is good. )

Blue
  • 69
  • 2

3 Answers3

5

On many electronics boards, GPIO pins are set to a "floating voltage" (not on, not off, just somewhere in the middle) until the pin actually gets initialized or used for the first time.

Remember, when you turn the Pi on, it has to load a bunch of kernel modules and drivers, including the ones to use the GPIO pins. The pins are part of an electrical circuit, so unless and until the controls for that service are in place, their behavior can be "random".

It sounds like this is what you are describing.

tlhIngan
  • 3,342
  • 5
  • 18
  • 33
  • So... as I understand that is because the pins are "random" till they are initialized? Also now I have tested if the relay board is connected, but the GPIO is set to in as default the smd led is on (low light). – Blue Dec 24 '16 at 06:55
  • This suggests otherwise: http://raspberrypi.stackexchange.com/a/32643/19949 However on other places it is descibed that most pins are inputs upon boot with only some pins being outputs and some being in their alternate function (like I2C). – Ghanima Dec 24 '16 at 07:50
  • @Blue The Pins are **NOT** random see answer below. – Milliways Dec 24 '16 at 07:57
  • That they aren't floating presumes the OS leaves them in the "power down" state from the data sheet. However, if they are floating and they light an led, it will be dimly because they won't float that high. I've noticed this before, although not in a while. – goldilocks Dec 24 '16 at 10:00
5

Most of the pins are configured as inputs. This is normal, and usually the safest option.

All of these inputs are put into a defined state with either a pullup or pulldown. The normal values are shown in http://elinux.org/RPi_BCM2835_GPIOs These are quite high impedance ~50kΩ.

The only pins set as output are those specifically configured as such e.g. TxD. Inputs can also have their pull changed in Device Tree.

When you connect external circuitry to the Pi any pins on a well designed board which are being used as inputs should normally have a pullup or pulldown, however if the Pi has a pullup and the external circuit has a pulldown, the state will depend on the actual resistors used.

Milliways
  • 54,718
  • 26
  • 92
  • 182
  • Ok, my question, is normal that when a pin is by default IN I connect the 2 channel relay board and the 2 smd leds are on (low light), when I configure the pins to be out then those leds are off. – Blue Dec 24 '16 at 08:08
  • @Blue I am unsure is you are asking for further information, but as you have not specified what device you are using, or which pins you are using no one can give other than generic responses. – Milliways Dec 24 '16 at 08:38
  • Raspberry Pi 3 GPIO 27, GPIO 22, PIN 2 -> JD VCC (Relay Board), PIN 17 -> VCC ( Relay Board ) – Blue Dec 24 '16 at 08:46
4

The programmable pins (General Purpose Input/Output) can be used in a variety of ways - but not all at the same time. Before the point where power is applied to the RPi's Systen-on-Chip (Soc) AND it has performed a reset the state of those pins is entirely dependent on the design of the circuity inside the SoC - it is likely (I haven't checked the information {that is available}) that most I/O pins adopt a high-impedance input state as that is the most likely to be "safe" until things can be configured. In that situation external pull-up or pull-down resistors will establish a level that anything else connected to the pins will "see".

During the reset process a SoC will then set each GPIO to a "reset" state that will also be defined somewhere, in the RPi's case, Broadcomm's "datasheets" for the Soc before moving into the "booting" phase which, for the Raspberry Pi has a late stage that involves reading the config.txt and that is the first point where some pins state/function can be configured by the user, this is where the device_tree is initially determined by the VPU and some pins configured to allow the rest of the system to boot-up.

I suspect, but haven't yet found out how, that the "device-tree" will ultimately offer the ability to configure GPIO pins in the manner that the user wants as soon as possible after the RPi is powered up. For example, this Foundation's Forum post shows how one or two pins were "reprogrammed" to work with an external power control system (or rather a control chip as part of a power supply regulation module) and how the default configuration was tweaked to work with the different conditions that were wanted for it.

Once the OS is fully up and running then the GPIO pins can be reconfigured via the "normal" means that software libraries for the task, such as pigpio provide.

Over on Stack Overflow someone seems to be asking about the GPIO pins and the device_tree on an RPi the links in the answer there could be of assistance I think if you want to investigate this further.

EDIT: As to whether it is normal to have odd behaviour like this during the start-up process I have to say it is not an uncommon 'gotcha' when using microprocessor/microcontrollers. The question "what is the power on state of the GPIOs?" has a link to a forum post "Power on behaviour" which was discussing a problem back in the early history of the RPi when the all the GPIO pins were apparently set to be outputs for a short time! That was, fortunately, revised, but it does highlight the need to check before committing a hardware design to production and also to consider transient behaviour under abnormal conditions such as power up/down or if the end user does something unexpected like pressing all the buttons down when they are only supposed to press one!

I am still working on a system that will use an RPi to unlock my house's front door - and in consideration of this sort of issues I am using not one but two GPIO pins and both of them have to go to the opposite state from that which they have during start-up simply to avoid the issue of a power glitch leaving my house unlocked when not expected {and I'm using a RPi UPS system that will keep the RPi running for several days even if the Mains power does go off...!}

SlySven
  • 3,581
  • 1
  • 15
  • 44
  • That is ok, but my question is... Is that normal to have leds on (low light) on above GPIOs while they are configured to be IN? ( After the system boots and I set the pins as OUT then everything is good. ) – Blue Dec 24 '16 at 12:29
  • And the answer is... probably yes! – SlySven Jan 07 '17 at 04:50