Skip to content
README.md 3.4 KiB
Newer Older
Gallacchi Mattia's avatar
Gallacchi Mattia committed
# Raspberry Pi Pico

Gallacchi Mattia's avatar
Gallacchi Mattia committed
This repo shows how to use the Raspberry Pi Pico SDK.
Gallacchi Mattia's avatar
Gallacchi Mattia committed

Gallacchi Mattia's avatar
Gallacchi Mattia committed
## Raspberry Pi Documentation
Gallacchi Mattia's avatar
Gallacchi Mattia committed

Gallacchi Mattia's avatar
Gallacchi Mattia committed
[Raspberry Pi Pico C/C++ SDK][1]
[Raspberry Pi Pico Quick Start][2]
[Raspberry Pi Pico W (WiFi) Quick start][3]
Gallacchi Mattia's avatar
Gallacchi Mattia committed

Gallacchi Mattia's avatar
Gallacchi Mattia committed
## Tools

**This guide as been tested for Ubuntu 22.04**

### Toolchain
Gallacchi Mattia's avatar
Gallacchi Mattia committed

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
```

Gallacchi Mattia's avatar
Gallacchi Mattia committed
### Flash and debug

You can use the Raspberry Pi Debug probe to flash and debug applications. To use it you must first install OpenOCD.
Download and install the OpenOCD dependencies:

```bash
sudo apt install automake autoconf build-essential texinfo libtool libftdi-dev libusb-1.0-0-dev
```

Clone, build and install OpenOCD:

```bash
cd ~
git clone https://github.com/raspberrypi/openocd.git --branch rp2040-v0.12.0 --depth=1 --no-single-branch
cd openocd
./bootstrap
./configure
make -j4
sudo make install
```

Check OpenOCD version:

```bash
openocd --version
```

Output: 

```bash
Open On-Chip Debugger 0.12.0-g4d87f6d (2024-01-08-14:31)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html

```

Create a file with any name (ex. pico_openocd.rules) under /etc/udev/rules.d and put this line inside.

```bash
ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="000c", MODE="660", GROUP="plugdev", TAG+="uaccess"
```

## 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
```

Alternatively you can run the *build.sh* script from the top folder. 

1. Setup project folder and board type (run only once)

```bash
./build.sh -p sht30/pico_w/ -t grove_pico_w
```

2. Compile

```bash
./build.sh -b
```

## Deploy application on the Raspberry Pi Pico

### Flash using 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

### Flash using debug probe and OpenOCD

Run the build script with the *-f* option:

```bash
./build.sh -f
```

> :warning: This command must be performed on your host machine not in a running docker container

Gallacchi Mattia's avatar
Gallacchi Mattia committed
## Projects

[SHT30 sensor](sht30/README.md)
Gallacchi Mattia's avatar
Gallacchi Mattia committed
[1]:https://datasheets.raspberrypi.com/pico/raspberry-pi-pico-c-sdk.pdf?_gl=1*155jvvo*_ga*MTk5NjQ0ODQwNy4xNzAyNjI5NzEx*_ga_22FD70LWDS*MTcwNDI5MDg1OS4zLjEuMTcwNDI5MTA0Ny4wLjAuMA..
[2]:https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf?_gl=1*i8b34r*_ga*MTk5NjQ0ODQwNy4xNzAyNjI5NzEx*_ga_22FD70LWDS*MTcwNDI5MDg1OS4zLjEuMTcwNDI5MTEzNy4wLjAuMA..
[3]:https://datasheets.raspberrypi.com/picow/connecting-to-the-internet-with-pico-w.pdf?_gl=1*19f24rw*_ga*MTk5NjQ0ODQwNy4xNzAyNjI5NzEx*_ga_22FD70LWDS*MTcwNDI5MDg1OS4zLjEuMTcwNDI5MTA0OS4wLjAuMA..