# Constant 3V3 to GPIO output behavior

I am new to circuit design, and I have some questions about a circuit I'm seeing in a raspberry pi starter kit. I think my questions is elementary, but I am having trouble finding an answer due to my limited knowledge of what keywords to search.

The starter kit I am using proposes a circuit in which a series of LEDs will turn on and off in sequence. The circuit design as well as a description of the project can be found on page 72 of this document: https://github.com/Freenove/Freenove_Ultimate_Starter_Kit_for_Raspberry_Pi/blob/master/Tutorial.pdf

Note that power flows from one of the constant 3V3 pins to the 220 Ohm resistors, the LEDs, and finally the IO pins.

In the `setup` function of the python script, the GPIO pins are initialized as output pins in HIGH mode which defaults to the LEDs being off. I do not understand this behavior. Why does sending constant 3V3 power to a pin in output mode (specifically set to HIGH) result in the LED not turning on? It seems to me that this would not work or could even potentially be dangerous to the components as the code appears to be demanding conflicting behavior. However, the code and circuit does indeed work. When the led output is set to low the light comes on. How can I understand this behavior?

Additionally, why is there no need to include a ground wire in the circuit? My design for a circuit that accomplishes the same task would go from each IO pin in output mode to a resistor and LED and then to a common wire that leads to ground. I would initialize each pin as an output pin in LOW mode. Then changing the output to HIGH would turn on the LED.

I have used both their method and mine. Both methods appear to work, but I do not understand why theirs works.

Apologies for lack of clarity or abuses of terminology.

• take an LED and connect both leads to the positive terminal of a battery ... does it light? Commented Jan 1, 2022 at 21:49
• you are forgetting that the LED lights up when a voltage difference is applied across the LED ... think about an LED, a switch and a battery ... your method connects the LED to the negative terminal and switches the positive terminal connection ... their method connects the LED to the positive terminal and switches the negative terminal connection ... either way, the LED is across the battery when the switch is closed Commented Jan 1, 2022 at 21:56
• @jsotola I don't think it will light as there is no circuit? Are you trying to imply that the constant 3V3 in conjunction with GPIO outputting HIGH is analogous to the LED being attached to only the positive terminal of a battery? And that switching to LOW is analogous to moving the connection to the positive and negative terminals instead? Why is the pin being in LOW mode similar to a negative end of the battery instead of being something more like a dead battery? Commented Jan 1, 2022 at 21:59

### Q1:

In the setup function of the python script, the GPIO pins are initialized as output pins in HIGH mode which defaults to the LEDs being off. I do not understand this behavior. Why does sending constant 3V3 power to a pin in output mode (specifically set to HIGH) result in the LED not turning on?

### A1:

Looking "inside" a GPIO pin reveals a transistor (and supporting circuitry) connected to that pin. This transistor circuitry may be used as a switch - vaguely similar to the way a light switch works: Closing a switch is a means to complete the circuit, thereby allowing electrical current to flow from the source, through the load, and return to ground. Setting a GPIO pin to a HIGH state (in the case of RPi's GPIO) may seem illogical, but it's only engineer-speak for placing this switch in a state that inhibits the flow of electrical current; it only seems illogical because you are unfamiliar with how electronic circuits operate.

### Q2:

Additionally, why is there no need to include a ground wire in the circuit?

### A2:

In general, schematics are often drawn without showing all ground connections for simplicity - or laziness - or ignorance... take your choice. You only need remember this "one thing": When electrical current flows, there is always a ground.

In the case of the figure you referenced on Page 72: The ground (GND) connection is "inside" the GPIO pin. Referring to the A1 above, each of those transistors does, in fact, have one of its terminals connected to GND. I'm sure you can see that in a busy schematic, showing each individual GND connection might make it harder to read. In addition, the individual GPIO GND connections are ganged together on the silicon substrate, and need not be brought out to a pin individually. Thus, you can properly ground every GPIO pin on a Raspberry Pi simply by connecting to a single GND pin on the header.

There are two ways to connect a LED to light it with a GPIO.

1. connect the anode to a GPIO and the cathode to ground. The LED will light when the GPIO is high and go off when the GPIO is low.
2. connect the cathode to a GPIO and the anode to 3V3. The LED will light when the GPIO is low and go off when the GPIO is high.

I am ignoring the resistor which will be in series to limit the power flow through the LED.

Your question is not Pi specific; indeed it is a general EE question.

This circuit 3.3V - resistor - LED - GPIO is the normal (and recommended) method which would be used by most engineers.

You appear to have a common misconception that there is something magical about positive voltages.

The LED will light whenever there is a potential difference across it; you need to consider the voltage at both ends.

See CMOS for GPIO output circuit.

When the output is set HIGH the GPIO pin is connected to 3.3V.
When the output is set LOW the GPIO pin is connected to Gnd (0V).

• I think I am beginning to understand what is happening here. However, why is there not a need for a ground in their version of the circuit? Commented Jan 1, 2022 at 22:05
• There is a Gnd connection. It is provided by the GPIO pin. Commented Jan 1, 2022 at 22:21
• One final follow-up: is there a component within the raspberry pi that allows the GPIO pin to be the Gnd connection, or is it simply the Gnd connection because it is no longer positive? Commented Jan 1, 2022 at 22:47
• @samvoit4 each GPIO has 2 MOSFET; one connected to 3.3V the other to Gnd (actually common 0V). Only 1 of these can be ON as a time. When ON they provide a low resistance path. Commented Jan 1, 2022 at 23:21
• The LED will light when there is a current flowing from the anode to the cathode. The voltage drop across the LED terminals is a function of the construction of the LED. Commented Jan 1, 2022 at 23:53