
Code: Select all
#!/usr/bin/env python
import RPi.GPIO as gpio, time
gpio.setmode(gpio.BCM)
gpio.cleanup()
gpio.setup(4, gpio.OUT)
while True:
print("Sending Power To LED!!")
gpio.output(4, True)
time.sleep(3)
print("Turning Off LED!!")
gpio.output(4, False)
time.sleep(4)
The cleanup in the beginning is a very good principle. Sometimes we use programs that don't clean the outputs, or we break a program (ctrl+c) before it reaches the clean function, so it's really usefull have that function in the beggining.croston wrote:If you gpio.setmode (gpio.BOARD) you can use the P1 numbers rather than the broadcom numbers. The cleanup function resets every channel used by your program to the system default (input+no pullup/down). It is pointless calling it at the beginning of your script.
The cleanup() function will do nothing at the beginning of your code and is completely pointless. The module remembers which channels you have set up using setup() calls in your script and only cleans those up. Therefore calling cleanup() at the start does nothing. It does this so that any other GPIO processes using other channels are not trampled.canibalimao wrote:The cleanup in the beginning is a very good principle. Sometimes we use programs that don't clean the outputs, or we break a program (ctrl+c) before it reaches the clean function, so it's really usefull have that function in the beggining.croston wrote:If you gpio.setmode (gpio.BOARD) you can use the P1 numbers rather than the broadcom numbers. The cleanup function resets every channel used by your program to the system default (input+no pullup/down). It is pointless calling it at the beginning of your script.
Have you checked that you're really measuring between ground (0v) and the GPIO pins?kirby2ig wrote:I tested every gpio pin and found that the 3.3v line gives 1.8v instead and some gpio pins provide 5v and some provide 1.8v. I don't know what to do. Does anyone know what is wrong with my pi?
There is nothing wrong with your Pi, but the way you are measuring the voltages is incorrect. You jump to conclusions very quickly.kirby2ig wrote:I tested every gpio pin and found that the 3.3v line gives 1.8v instead and some gpio pins provide 5v and some provide 1.8v. I don't know what to do. Does anyone know what is wrong with my pi?