EasyManua.ls Logo

Raspberry Pi Pico Series - Use the CLI to Blink an LED in C; Building Blink

Raspberry Pi Pico Series
54 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Use the CLI to Blink an LED in C
When you’re writing software for hardware, turning an LED on, off, and then on again, is typically the first program that
gets run in a new programming environment. Learning how to blink an LED gets you half way to anywhere.
So let’s blink the LED on a Pico-series device.
This code shown here for the Raspberry Pi Pico and Pico 2 blinks the LED connected to pin 25 of the device.
Pico Examples: https://github.com/raspberrypi/pico-examples/blob/master/blink_simple/blink_simple.c Lines 31 - 39
31 int main() {
32 pico_led_init();
33 while (true) {
34 pico_set_led(true);
35 sleep_ms(LED_DELAY_MS);
36 pico_set_led(false);
37 sleep_ms(LED_DELAY_MS);
38 }
39 }
The actual code for the "blink" example is slightly complicated as it also supports blinking the LED connected to the
Infineon 43439 wireless chip on the Pico W. The full code can be found here sdkexampleref::blink/blink.c
Building "Blink"
From the pico directory we created earlier, navigate into pico-examples and create a build directory:
$ cd pico-examples
$ mkdir build
$ cd build
Then, set the PICO_SDK_PATH, assuming you cloned the pico-sdk and pico-examples repositories into the same directory:
$ export PICO_SDK_PATH=../../pico-sdk
TIP
Throughout this book we use the relative path ../../pico-sdk to the SDK repository for PICO_SDK_PATH. Depending on
the location of your repository, you could replace this with an absolute path.
Build "Blink"
Prepare your cmake build directory by running the following command:
$ cmake ..
Using PICO_SDK_PATH from environment ('../../pico-sdk')
PICO_SDK_PATH is /home/pi/pico/pico-sdk
Ê .
Ê .
Ê .
Getting started with Raspberry Pi Pico-series
Use the CLI to Blink an LED in C 35

Table of Contents

Related product manuals