If I setup a pin's output to HIGH
or LOW
, would current flow through it or not?
In this example, when I set output to HIGH then the LED turns off. I expected the other way around.
The python
code I have written is
import RPi.GPIO as GPIO
import time
try:
outputPins = [11,12,15,16,18,22,3,5,24]
GPIO.setmode(GPIO.BOARD)
for pin in outputPins:
print('setting output mode for pin',pin)
GPIO.setup(pin,GPIO.OUT)
while True:
for pin in outputPins:
#print('turning ON pin ',pin)
GPIO.output(pin,GPIO.LOW) <-- I expected that HIGH will turn the LED ON
time.sleep(0.1)
#print('turning OFF pin ',pin)
GPIO.output(pin,GPIO.HIGH) <-- I expected low to turn LED off
time.sleep(0.1)
#print('out of loop')
#time.sleep(10)
#GPIO.cleanup()
except KeyboardInterrupt:
GPIO.cleanup()
Reason I expected LOW to turn off LED is because in this diagram, LOW turns off LED
The code is
import time
ledPin = 11 # define ledPin
def setup():
GPIO.setmode(GPIO.BOARD) # use PHYSICAL GPIO Numbering
GPIO.setup(ledPin, GPIO.OUT) # set the ledPin to OUTPUT mode
GPIO.output(ledPin, GPIO.LOW) # make ledPin output LOW level
print ('using pin%d'%ledPin)
def loop():
while True:
GPIO.output(ledPin, GPIO.HIGH) # make ledPin output HIGH level to turn on led - Here HIGH TURNS ON LED
print ('led turned on >>>') # print information on terminal
time.sleep(1) # Wait for 3 second
GPIO.output(ledPin, GPIO.LOW) # make ledPin output LOW level to turn off led
print ('led turned off <<<')
time.sleep(1) # Wait for 3 second
def destroy():
GPIO.cleanup() # Release all GPIO
What am I missing? Has it got to do something with serial or parallel connections? Why does the first circuit doesn't use GND
?
I can see differences in the circuits (eg. 1st one is connect to 3V while second one is not). But I can't figure how internally with RPI, things are getting controlled