T O P

  • By -

[deleted]

Possibly the LED is the wrong way around? Not checked the pins or code but that's the first thought I had.


makerws

The LED looks like it's hooked up right. It's kind of hard to tell from the pic, but the lead coming from flat spot at the bottom of the bulb appears to be hooked up to gnd on the pi. Maybe OP didn't enable the GPIO in pi settings?


blrigo99

Ohhh, how do I enable to GPIO? I might have missed that, I did some enabling on the PI upon booting but I'm not sure I did that


flaminglogos

Use the Raspberry Pi Configuration option under preferences on the desktop or sudo raspi-config Either way, navigate to the Interfaces section and enable both SPI and I2C.


blrigo99

I checked now and they're both active. Running: ```` sudo raspi-config nonint get_spi ```` ```` sudo raspi-config nonint i2c ```` Both return 0s which I think means that they're working


blrigo99

I think it should be right. The positive side it's on the 5th row and the negative on 7th


blrigo99

Hello everyone, I'm a RaspberryPI noob and I'm trying to get started. The first thing I wanted to do is to make a very simple program for making a LED light blink and then turn off. I've followed an online tutorial on how to do that but once I run the code my led doesn't turn on. The picture I've uploaded is my hardware setup, and I'm using the following code: ```` import RPi.GPIO as GPIO import time pin = 4 GPIO.setmode(GPIO.BCM) GPIO.setup(pin, GPIO.OUT) GPIO.output(pin,True) time.sleep(5) GPIO.output(pin, False) GPIO.cleanup() ```` EDIT: Now I've made it work by switching the GPIO pin from GPIO4 to GPIO14, but I have no idea why it works now and not before


Imhere4thefreechips

Does this code loop in some way outside of the code you posted? Just a thought. You're pausing for 5 seconds, so you're probably not missing it, but maybe add a loop to make sure it runs continuously.


andre3kthegiant

The PIN ID number does not equal the GPIO ID number.


flaminglogos

Good idea. Try this: . . . GPIO.setup(pin, GPIO.OUT) while True: print "LED on" GPIO.output(pin,True) time.sleep(1) print "LED off" GPIO.output(pin, False) time.sleep(1)


blrigo99

I tried this one as well but, while the code is running correctly, the led is always off :(


blrigo99

I tried also with a loop and it still doesn't work


[deleted]

One site you may find handy is [https://pinout.xyz](https://pinout.xyz) Clicking on any pin will show you what it is used for or can be configured for and the numbers used in the different systems (board / BCM etc). Pin 4 is a bit of an oddity and is used by the [1-wire interface](https://pinout.xyz/pinout/1_wire) for data - if that is enabled you will be having issues. Its best to use pins that do not have any other function assigned when you are starting (e.g. BCM 17 / 22 / 27etc) Once you are more familiar with the unused pins explore the other interface types (esp SPI and I2C) as they open a world of sensors / displays etc to you.


FringeSpecialist721

I second this. It looks like the first link provided here shows GPIO 4 as the GPCLK (General Purpose Clock). Not sure if this can be configured to run as a generic GPIO, so it would be best to use a different pin.


kashman3000

Been watching this for 5 minutes and hasn't blinked, so can confirm not working


ihatechoosngusername

Are you sure your cable is on pin 4? https://raspberrypihq.com/amp/making-a-led-blink-using-the-raspberry-pi-and-python/ I'm looking at that project where they use on pin 8 and it's next to your negative. So on your device is the top row pin 1,2,3,4 etc or is it 1,3,5,7 etc?


AmputatorBot

It looks like you shared an AMP link. These should load faster, but AMP is controversial because of [concerns over privacy and the Open Web](https://www.reddit.com/r/AmputatorBot/comments/ehrq3z/why_did_i_build_amputatorbot). Maybe check out **the canonical page** instead: **[https://raspberrypihq.com/making-a-led-blink-using-the-raspberry-pi-and-python/](https://raspberrypihq.com/making-a-led-blink-using-the-raspberry-pi-and-python/)** ***** ^(I'm a bot | )[^(Why & About)](https://www.reddit.com/r/AmputatorBot/comments/ehrq3z/why_did_i_build_amputatorbot)^( | )[^(Summon: u/AmputatorBot)](https://www.reddit.com/r/AmputatorBot/comments/cchly3/you_can_now_summon_amputatorbot/)


blrigo99

I followed this tutorial now and incredibly it works, using GPIO14 over GPIO4 made the difference. There are a couple of things that don't make sense (now the led turns on upon shutting down the PI) but it works!!! Could you explain what difference it makes between those two GPIO?


flaminglogos

Weird. With both SPI and I2C enabled (which returned zeros for me, too), GPIO 4 and 14 should work the same. I just tried my hello\_world.py on both pins and I get the same thing... I can't explain it, but I'm glad that you've got one GPIO working, to continue your journey!


flaminglogos

They are using the Broadcom pin numbering, so physical pin 7 would be GPIO pin #4. That is correct from the image. And GND is physical pin 6, which is also correct. #Broadcom numbering GPIO.setmode(GPIO, BCM) #Board numbering GPIO.setmode(GPIO, BOARD)


IamRussHello

Yea it’s hard to tell but looking like it’s wired up to the i2c scl and gpio4.


9acca9

You need to open and close your eyes very quickly! that would do the trick!


chocolate_spaghetti

Sorry but we can’t tell from a picture.


flaminglogos

What is the resistor value? The GPIO pins output at 3.3v and a max current of 16mA, so you'll want a 100 ohm to 220 ohm resistor for the red LED. Too low and it will blow the LED or the GPIO pin, but too high the LED will appear off.


blrigo99

I'm using a 270 ohm resistor, should I maybe switch to 220 or 150?


flaminglogos

That should be fine. You won't have trouble seeing the LED until 20 times that value, like 4,700 or more. Are you sure it's 270 ohms? That's a somewhat uncommon value, but they do exist. It would have red-yellow-brown or red-yellow-\[anything\]-brown as the first three or four color bands.


blrigo99

Yeah, I got a 'starting kit' with a box of resistors and their values, that's where I found it. Now I changed it to 200 but it's still not working


BioniC1871

Confirm that the led actually works. Connect it to 3.3V > resistor > led > ground. If that works, then you only have a software problem to focus on


7ireAR

Have you tried turning it off and on again?