Chapter 8. Creating your own Project
Go ahead and create a directory to house your test project sitting alongside the
pico-sdk directory,
$ ls -la
total 16
drwxr-xr-x 7 aa staff 224 6 Apr 10:41 ./
drwx------@ 27 aa staff 864 6 Apr 10:41 ../
drwxr-xr-x 10 aa staff 320 6 Apr 09:29 pico-examples/
drwxr-xr-x 13 aa staff 416 6 Apr 09:22 pico-sdk/
$ mkdir test
$ cd test
and then create a
test.c file in the directory,
Ê1 #include <stdio.h>
Ê2 #include "pico/stdlib.h"
Ê3 #include "hardware/gpio.h"
Ê4 #include "pico/binary_info.h"
Ê5
Ê6
const uint LED_PIN = 25;
Ê7
Ê8
int main() {
Ê9
10 bi_decl(bi_program_description(
"This is a test binary."));①
11 bi_decl(bi_1pin_with_name(LED_PIN, "On-board LED"));
12
13 stdio_init_all();
14
15 gpio_init(LED_PIN);
16 gpio_set_dir(LED_PIN, GPIO_OUT);
17
while (1) {
18 gpio_put(LED_PIN,
0);
19 sleep_ms(
250);
20 gpio_put(LED_PIN,
1);
21 puts(
"Hello World\n");
22 sleep_ms(
1000);
23 }
24 }
①
These lines
will add
strings to the
binary visible
using
picotool,
see
Appendix
B
.
along with a CMakeLists.txt file,
cmake_minimum_required(VERSION 3.13)
include(pico_sdk_import.cmake)
project(test_project C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
pico_sdk_init()
add_executable(test
Ê test.c
)
Getting started with Raspberry Pi Pico
Chapter 8. Creating your own Project 30