Part 5 - char
Today we will begin our coverage of the C data types. We will start with char. A char is the smallest addressable unit of the machine that can contain basic character set. It is an integer type and can be either can be either signed or unsigned.
Let's make a new dir 0x03_char and add our CMakeLists.txt file in it.
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(0x03_char 0x03_char.c ) pico_enable_stdio_usb(0x03_char 1) pico_add_extra_outputs(0x03_char) target_link_libraries(0x03_char pico_stdlib)
Next we need to copy the pico_sdk_import.cmake file from the external folder in the pico-sdk installation to the 0x03_char project folder.
cp ../pico-sdk/external/pico_sdk_import.cmake .
Let's create our C file 0x03_char.c and roll...
#include <stdio.h> #include "pico/stdlib.h" int main() { stdio_init_all(); while(1) { char x = 'x'; printf("%c\n", x); sleep_ms(1000); } return 0; }
Finally we are ready to build.
mkdir build cd build export PICO_SDK_PATH=../../pico-sdk cmake .. make
Then simply copy the .uf2 file to the drive.
cp 0x03_char.uf2 /Volumes/RPI-RP2
Then we need to locate the USB drive so you can do the following.
ls /dev/tty.
Press tab to find the drive and then in my case I will use screen to connect.
screen /dev/tty.usbmodem0000000000001
You should see a an "x" being printed every second.
x x x x x x
Next lesson we will debug char.