1

I have the following code on the RPi Pico W:

include "pico/stdlib.h"

#define LED 25

int main()
{
    gpio_init(LED);
    gpio_set_dir(LED, GPIO_OUT);
    while (true)
    {
        gpio_put(LED, 1);
        sleep_ms(250);
        gpio_put(LED, 0);
        sleep_ms(250);
    }
}

I'm using CMake and pico-sdk to compile it, and the code compiles with no issues. When I put the code on the Pico the led doesn't blink, I tried changing the GPIO output to other pins and connecting them to an external LEDs, but it didn't work either.

Anyone has any Idea on how to fix it?

PS: I'm using an M1 macbook to compile.

1
  • 2
    I suggest you read the documentation again. This is a Pico program NOT PicoW - the LED is accessed differently.
    – Milliways
    Sep 19, 2022 at 3:17

1 Answer 1

0

N.B. I haven't tested this myself in C/C++ but have done so in MicroPython and TinyGo :)

The LED is no longer connected to pin 25 on the Pico W - so you have to access it 'indirectly' - this page gives details - https://www.electromaker.io/blog/article/getting-started-with-the-raspberry-pi-pico-w-cc-sdk

Search for CYW43_WL_GPIO_LED_PIN to see the code - you will also need to follow preceding instructions to setup your tool chain.

For interest - here is a TinyGo blink - which compiles to a 17KB UF2 - which might interest you if you're looking for a compiled alternative to C...

package main

import (
    "machine"
    "time"
)

func main() {
    led := machine.LED
    led.Configure(machine.PinConfig{Mode: machine.PinOutput})

    for {
        led.Set(!led.Get()) // toggle LED

        time.Sleep(time.Second / 4)
    }
}

Your Answer

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

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