4

I was following this tutorial on connecting an external LED to a Pico W, but I've had no luck getting it to work.

This is the code I've been using:

import machine
from machine import Pin, Timer
timer = Timer()

led = Pin("LED", Pin.OUT)

def blink(timer):
    led.toggle()
    
timer.init(freq = 1, mode = Timer.PERIODIC, callback = blink)

Here's a picture of what I have on the breadboard: [

I've tried swapping out the resistor, the LED, the jumpers, and trying all of the GPIO pins 7-15. Forgive the lousy soldering job, I'm quite new at this. My hunch is that the header pins aren't quite on there right, but want to know if there's something else I'm missing. Appreciate any help or ideas.

4
  • 2
    "Forgive the lousy soldering job" this is the most likely cause of any problems. Resolder all the dry joints, check for shorts. WHY have you soldered a resistor to the Pico?
    – Milliways
    Dec 27, 2022 at 2:20
  • 2
    "LED" is NOT a pin. Try one of the standard beginner tutorials. This should have generated an error.
    – Milliways
    Dec 27, 2022 at 2:22
  • 2
    Using “LED” should flash the onboard led. Use a pin number instead of “LED” to specify your required pin.
    – CoderMike
    Dec 27, 2022 at 9:10
  • 2
    "LED" (with quotes) looks wrong. I'd expect the on-board LED to be named LED (without quotes).
    – joan
    Dec 27, 2022 at 10:39

3 Answers 3

5

Your LED is wired to the GP13. So try Pin(13, Pin.OUT) instead of Pin("LED", Pin.OUT) GP13

2

A 10k resistor will not make the led light up! 10k is way to high!

Change it to a 100 ohm resistor if you have a red LED.

2

Question

The OP follows this blink LED tutorial but has no luck. How to debug his code?


Answer

Update 2022dec30hkt1534 - Part 3 Concurrently blink 2 Leds Appendix F, G


Part 1 - Try to first blink the onboard LED to make sure the basic pico W hardware/software setup is working OK. If blinking onboard OK, then we can move on checking an external LED connected to a GPIO pin (Appendix A).


Part 2 - Blink GPIO Pin 15 Led

Now that basic Pico hardware/software looks OK, next step is to blink GPIO pin 15 Led. (Appendix C, D)


Appendxi A - Rpi Pico W pinout

picow pinout


Appendix B - Blinking onboard LED

(1) For Pico W, the pin number for on board Led is "WL_GPIO0".

Yes, no longer number 25 for Pico.

(2) The following program blinks onboard LED. The correct statement to initialize the Led should be:

LED = Pin("WL_GPIO0", Pin.OUT)

Update: The following also looks OK:

LED = Pin("LED", Pin.OUT)

There is some confusion here: the first LED is an object, the second is the pin number for the onboard pin (same of WL+GPIO0) (Appendix H)

(3) Full listing of the folly debugged program:


# Name      - Rpi Pico W onboard LED v4.3  tlfong01  2022dec29hkt1502
# Function  - Blink onboard LED
# References -
#   (1) Blink onboard LED  https://projects.raspberrypi.org/en/projects/getting-started-with-the-pico/5
#   (2) Onboard LED pinout https://core-electronics.com.au/guides/raspberry-pi-pico/raspberry-pi-pico-w-overview-features-specs/

import machine
from machine import Pin, Timer
timer = Timer()

LED = Pin("WL_GPIO0", Pin.OUT)

def blink(timer):
    LED.toggle()
    
timer.init(freq = 1, mode = Timer.PERIODIC, callback = blink)

Appendix C - Blink GPIO Pin 15 Led

# Rpi Pico W Blink GPIO 15 LED v8.0  tlfong01  2022dec29hkt2022

# *** Import modules ***
import machine
from machine import Pin, Timer

# *** Create objects ***
timer02    = Timer()
gp15LedPin = Pin(15, Pin.OUT)

# *** Define functions ***
def blinkGp15Led(dummy):
    gp15LedPin.toggle()
    return

# *** Blink GP15 Led ***

timer02.init(freq = 2, mode = Timer.PERIODIC, callback = blinkGp15Led)

# *** End of program ***

Appendix D - Blink GPIO Pin 15

enter Blink GPIO Pin 15


Appendix E - Pico W GPIO LED Blink

https://youtu.be/IhIeiG9_RWg


Appendix F - PicoW Concurrently Blink 2 LEDs

https://youtu.be/60gnZ8px3vg


picow blink 2 leds


Appendix G - PicoW Concurrently Blink 2 LEDs Complete Program Listing

# Pico W Concurrently Blink Two LEDs - tlfong01 2022dec30hkt1350

# *** Modules ***
import machine
from machine import Pin, Timer

# *** Objects ***
redTimer    = Timer()
redLed      = Pin(15, Pin.OUT)

greenTimer  = Timer()
greenLed    = Pin(0, Pin.OUT)

# *** Callback Functions ***
def blinkRedLed(dummy):
    redLed.toggle()
    return

def blinkGreenLed(dummy):
    greenLed.toggle()
    return

# *** Main Functions***
redTimer.init(freq = 2, mode = Timer.PERIODIC, callback = blinkRedLed)
greenTimer.init(freq = 4, mode = Timer.PERIODIC, callback = blinkGreenLed)

# *** End of program ***

Appendix H - "LED" as pin number for onboard LED pin

The following code works OK.

# Name      - Rpi Pico W onboard LED v4.3  tlfong01  2022dec29hkt1502
# Function  - Blink onboard LED
# References -
#   (1) Blink onboard LED  https://projects.raspberrypi.org/en/projects/getting-started-with-the-pico/5
#   (2) Onboard LED pinout https://core-electronics.com.au/guides/raspberry-pi-pico/raspberry-pi-pico-w-overview-features-specs/

import machine
from machine import Pin, Timer
timer = Timer()

#LED = Pin("WL_GPIO0", Pin.OUT)
LED = Pin("LED", Pin.OUT)

def blink(timer):
    LED.toggle()
    
timer.init(freq = 2, mode = Timer.PERIODIC, callback = blink)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.