Skip to content

Latest commit

 

History

History
63 lines (39 loc) · 1.36 KB

README.md

File metadata and controls

63 lines (39 loc) · 1.36 KB

Read Data from Temperature Sensor on Raspberry Pi Pico

Prerequisites

Before diving into code, you need to install prerequisites. You can see it from here

The Code

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);
    }

}

Compiling The Code

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

Uploading The Code

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>