Before diving into code, you need to install prerequisites. You can see it from here
The code below initializes the internal temperature sensor and UART, prepares them for use. The while loop read data from sensor and write it to the UART once per seconds.
int main() {
UART_Init();
TEMPERATURE_Init();
while (1) {
float fTemperatureC = TEMPERATURE_Read();
printf("Temperature: %0.2f \n", fTemperatureC);
sleep_ms(1000);
}
}
To compile the source code we need to create a CMake file to automate the process. CMake files allow us to easily build source files into one easy to use file.
Firstly we need to create folder that name is build.
mkdir build
cd build
Then, we need to import essential pico-sdk-libraries
cmake ..
Now, we can compile source files
cd ..
cmake --build build
Now that we compiled the code we can deploy to our microcontroller.
Note !: To upload the compiled code, you need to start your Raspberry Pi Pico in flash mode. To start in flash mode you need to press bootsel button before plug in cable.
cp build/main.uf2 <your-rasp-pi-pico-path>