Loading README.md +27 −1 Original line number Diff line number Diff line Loading @@ -8,7 +8,33 @@ This repo shows how to use the Raspberry Pi Pico SDK. [Raspberry Pi Pico Quick Start][2] [Raspberry Pi Pico W (WiFi) Quick start][3] ## Install SDK ## Toolchain A docker image containing all the tools is available. You can build it with the following command. ```bash docker build -t pico-dev . ``` Alternatively you can pull the image from GitLab. TODO: push image to gitlab To run the image you can use the run script: ```bash ./run ``` or ```bash docker run --rm -it --name pico-env -v $PWD:/mnt/ pico-dev ``` ## Projects [SHT30 sensor](sht30/README.md) [1]:https://datasheets.raspberrypi.com/pico/raspberry-pi-pico-c-sdk.pdf?_gl=1*155jvvo*_ga*MTk5NjQ0ODQwNy4xNzAyNjI5NzEx*_ga_22FD70LWDS*MTcwNDI5MDg1OS4zLjEuMTcwNDI5MTA0Ny4wLjAuMA.. Loading run.sh +2 −2 Original line number Diff line number Diff line Loading @@ -2,7 +2,7 @@ SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" MOUNTPOINT=$SCRIPTPATH IMAGE_NAME=pico-sdk-dev CONTAINER_NAME=pico-sdk-env IMAGE_NAME=pico-dev CONTAINER_NAME=pico-env docker run --rm -it --name $CONTAINER_NAME -v $MOUNTPOINT:/mnt/ $IMAGE_NAME sht30/README.md 0 → 100644 +62 −0 Original line number Diff line number Diff line # SHT30 sensor example This project contains an application that uses the SHT30 Temperature and Humidity sensor and broadcast their values over UDP. ## Application The Raspberry Pi Pico expect to connect to an WiFi network with the following characteristics: | | | |------|-----------| | SSID | pico_wifi | | Password | 1234567890 | Once connected to the network it will start a loop that send UDP packages at regular intervals. A led flashes to indicate that everything is running correctly. If it doesn't (either always on or off) something is wrong. ## Hardware connection The application expect to find the SHT30 on the *I2C0* channel. Some messages are printed on the *UART0* port and can be used for debug (Baud 115200). ## Compile Pico W code Run the docker container and navigate to the *sht30/pico_w* folder. Create a *build* folder and navigate to it: ```bash mkdir build && cd build ``` Inside the *build* folder you will setup the **Cmake** environnement. ```bash cmake -DPICO_BOARD=grove_pico_w .. ``` This will initialize **CMake** and generate a Makefile. To build the project simply run: ```bash make ``` ## Deploy code on the Raspberry Pi Pico ### Deploy UF2 (USB Flashing Format) You can flash the Pico via USB using the *.uf2* file. 1. Power up the Pico while pressing the **BOOTSEL** button 2. You Pico should show up as a drive. 3. Copy the *pico_w/build/sht30.uf2* onto the Pico. 1. Linux: ```bash cp pico_w/build/sht30.uf2 /media/$USER/RPI-RP2 ``` 2. Windows: Drag and drop the file ### Deploy flash TODO ## UDP client No newline at end of file sht30/main.cppdeleted 100644 → 0 +0 −91 Original line number Diff line number Diff line /** * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. * * SPDX-License-Identifier: BSD-3-Clause */ // Sweep through all 7-bit I2C addresses, to see if any slaves are present on // the I2C bus. Print out a table that looks like this: // // I2C Bus Scan // 0 1 2 3 4 5 6 7 8 9 A B C D E F // 0 // 1 @ // 2 // 3 @ // 4 // 5 // 6 // 7 // // E.g. if slave addresses 0x12 and 0x34 were acknowledged. #include <stdio.h> #include "pico/stdlib.h" #include "pico/cyw43_arch.h" #include "pico/binary_info.h" #include "hardware/i2c.h" #include "sht30.h" volatile bool error = false; bool callback(struct repeating_timer *t) { SHT30 *sht = (SHT30*)t->user_data; SHT30::measure mes = {0, 0}; if (!sht->single_measure(SHT30::HIGH, mes)) { error = true; return false; } printf("Temperature: %f, Humidity: %f %\n", mes.temperature, mes.humidity); return true; } int main() { struct repeating_timer timer; SHT30::measure mes = {0, 0}; stdio_init_all(); printf("\n*** Init SHT30 sensor ***\n"); SHT30 sht; if (!sht.is_connected()) { printf("Error: SHT30 is not connected\n"); return -1; } printf("SHT30 connected\n"); if (!sht.read_serial_number()) goto end; // if (!sht.single_measure(SHT30::HIGH, mes)) // goto end; // printf("Temperature: %f, Humidity: %f %\n", mes.temperature, mes.humidity); // add_repeating_timer_ms(2000, callback, &sht, &timer); while(!error) { if (!sht.single_measure(SHT30::HIGH, mes)) goto end; printf("Temperature: %f, Humidity: %f %\n", mes.temperature, mes.humidity); sleep_ms(1000); } printf("An error occurred stopping\n"); uint16_t status_reg; if (sht.read_status_reg(status_reg)) printf("Status reg: 0x%04X\n", status_reg); end: printf("Exiting\n"); return 1; } No newline at end of file sht30/CMakeLists.txt→sht30/pico_w/CMakeLists.txt +0 −0 File moved. View file Loading
README.md +27 −1 Original line number Diff line number Diff line Loading @@ -8,7 +8,33 @@ This repo shows how to use the Raspberry Pi Pico SDK. [Raspberry Pi Pico Quick Start][2] [Raspberry Pi Pico W (WiFi) Quick start][3] ## Install SDK ## Toolchain A docker image containing all the tools is available. You can build it with the following command. ```bash docker build -t pico-dev . ``` Alternatively you can pull the image from GitLab. TODO: push image to gitlab To run the image you can use the run script: ```bash ./run ``` or ```bash docker run --rm -it --name pico-env -v $PWD:/mnt/ pico-dev ``` ## Projects [SHT30 sensor](sht30/README.md) [1]:https://datasheets.raspberrypi.com/pico/raspberry-pi-pico-c-sdk.pdf?_gl=1*155jvvo*_ga*MTk5NjQ0ODQwNy4xNzAyNjI5NzEx*_ga_22FD70LWDS*MTcwNDI5MDg1OS4zLjEuMTcwNDI5MTA0Ny4wLjAuMA.. Loading
run.sh +2 −2 Original line number Diff line number Diff line Loading @@ -2,7 +2,7 @@ SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" MOUNTPOINT=$SCRIPTPATH IMAGE_NAME=pico-sdk-dev CONTAINER_NAME=pico-sdk-env IMAGE_NAME=pico-dev CONTAINER_NAME=pico-env docker run --rm -it --name $CONTAINER_NAME -v $MOUNTPOINT:/mnt/ $IMAGE_NAME
sht30/README.md 0 → 100644 +62 −0 Original line number Diff line number Diff line # SHT30 sensor example This project contains an application that uses the SHT30 Temperature and Humidity sensor and broadcast their values over UDP. ## Application The Raspberry Pi Pico expect to connect to an WiFi network with the following characteristics: | | | |------|-----------| | SSID | pico_wifi | | Password | 1234567890 | Once connected to the network it will start a loop that send UDP packages at regular intervals. A led flashes to indicate that everything is running correctly. If it doesn't (either always on or off) something is wrong. ## Hardware connection The application expect to find the SHT30 on the *I2C0* channel. Some messages are printed on the *UART0* port and can be used for debug (Baud 115200). ## Compile Pico W code Run the docker container and navigate to the *sht30/pico_w* folder. Create a *build* folder and navigate to it: ```bash mkdir build && cd build ``` Inside the *build* folder you will setup the **Cmake** environnement. ```bash cmake -DPICO_BOARD=grove_pico_w .. ``` This will initialize **CMake** and generate a Makefile. To build the project simply run: ```bash make ``` ## Deploy code on the Raspberry Pi Pico ### Deploy UF2 (USB Flashing Format) You can flash the Pico via USB using the *.uf2* file. 1. Power up the Pico while pressing the **BOOTSEL** button 2. You Pico should show up as a drive. 3. Copy the *pico_w/build/sht30.uf2* onto the Pico. 1. Linux: ```bash cp pico_w/build/sht30.uf2 /media/$USER/RPI-RP2 ``` 2. Windows: Drag and drop the file ### Deploy flash TODO ## UDP client No newline at end of file
sht30/main.cppdeleted 100644 → 0 +0 −91 Original line number Diff line number Diff line /** * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. * * SPDX-License-Identifier: BSD-3-Clause */ // Sweep through all 7-bit I2C addresses, to see if any slaves are present on // the I2C bus. Print out a table that looks like this: // // I2C Bus Scan // 0 1 2 3 4 5 6 7 8 9 A B C D E F // 0 // 1 @ // 2 // 3 @ // 4 // 5 // 6 // 7 // // E.g. if slave addresses 0x12 and 0x34 were acknowledged. #include <stdio.h> #include "pico/stdlib.h" #include "pico/cyw43_arch.h" #include "pico/binary_info.h" #include "hardware/i2c.h" #include "sht30.h" volatile bool error = false; bool callback(struct repeating_timer *t) { SHT30 *sht = (SHT30*)t->user_data; SHT30::measure mes = {0, 0}; if (!sht->single_measure(SHT30::HIGH, mes)) { error = true; return false; } printf("Temperature: %f, Humidity: %f %\n", mes.temperature, mes.humidity); return true; } int main() { struct repeating_timer timer; SHT30::measure mes = {0, 0}; stdio_init_all(); printf("\n*** Init SHT30 sensor ***\n"); SHT30 sht; if (!sht.is_connected()) { printf("Error: SHT30 is not connected\n"); return -1; } printf("SHT30 connected\n"); if (!sht.read_serial_number()) goto end; // if (!sht.single_measure(SHT30::HIGH, mes)) // goto end; // printf("Temperature: %f, Humidity: %f %\n", mes.temperature, mes.humidity); // add_repeating_timer_ms(2000, callback, &sht, &timer); while(!error) { if (!sht.single_measure(SHT30::HIGH, mes)) goto end; printf("Temperature: %f, Humidity: %f %\n", mes.temperature, mes.humidity); sleep_ms(1000); } printf("An error occurred stopping\n"); uint16_t status_reg; if (sht.read_status_reg(status_reg)) printf("Status reg: 0x%04X\n", status_reg); end: printf("Exiting\n"); return 1; } No newline at end of file