1

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.

The code for the project is here: https://github.com/Freenove/Freenove_Ultimate_Starter_Kit_for_Raspberry_Pi/blob/master/Code/Python_Code/03.1.1_LightWater/LightWater.py

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.

3
  • take an LED and connect both leads to the positive terminal of a battery ... does it light?
    – jsotola
    Jan 1 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
    – jsotola
    Jan 1 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?
    – samvoit4
    Jan 1 at 21:59

3 Answers 3

1

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.

2

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.

1

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).

5
  • 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?
    – samvoit4
    Jan 1 at 22:05
  • There is a Gnd connection. It is provided by the GPIO pin.
    – Milliways
    Jan 1 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?
    – samvoit4
    Jan 1 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.
    – Milliways
    Jan 1 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.
    – Seamus
    Jan 1 at 23:53

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.