Raspberry Pi Pico with C/C++
Introduction
Raspberry Pi Pico is a 4$ (300₹) microcontroller board built by the Raspberry Pi foundation. Unlike the Arduino microcontroller board, Pi Pico has built-in support for MicroPython and C/C++. Pi Pico is using an RP2040 microcontroller chip designed by Raspberry Pi in the United Kingdom. Pi-Pico is more powerful compared to many other microcontroller boards available in the market at this price range. Pi Pico is suitable for many small projects which do not use WIFI or Bluetooth.
To program Pi Pico in Python check the Article
Getting started
1. With C/C++
Programming Pi Pico in C/C++ is not as simple as programming with MicroPython or CircuitPython. For this to work you must download a couple of applications. (this may not work as intended)
- Python 3.6+ installed. If not, you can find it Here
- ARM-GCC-compiler
- CMake cross-platform automation tool
- Build-tools for VS Code 2019
- VS-Code text editor
- Pico-SDK tools
While installing make sure that you have selected the following:
- Python — Add Python, Install PATH
- AGM GCC compiler — Add path to environment variable
- CMake — Add Path
- Build Tools for Visual Studio — Install C++ with default options
- Pico-SDK — Download the zip and extract it to a folder directory of your choice. Add the path to User Variable
Next install C/C++, CMake tools extensions in Vscode
Configure CMake tools: Extension Settings
- Cmake Path: cmake
- Configure Environment: Item = PICO_SDK_PATH, Value = Pico_SDK directory
- Generator: NMake Makefiles
Restart the VScode, now you can see GCC for arm-none-eabi 10.x at the bottom.
Congratulations now you are ready to go
There are 3 important files you need to have program.c , pico_sdk_import.cmake , CMakeLists.txt
- You can download example programs from Here
Blink LED
Open a folder(test) as a project, inside that create 3 files as shown above. Once you have done that press the Build
button
Once the build is finished with exit code 0
, go to the build file and find for test.uf2
file.
Now set the Pi Pico to boot mode using the BOOTSEL
button (press hold the button and connect the USB cable to the PC)
Drag and drop the test.uf2
file in RPI-RP2 drive and restart the Pi Pico
If you see led blinking, congratulations you have done a great job 😊
Conclusion
Programming Raspberry Pi Pico is easy in MicroPython and CircuitPython compared to C/C++. Python being the most used and easy language anyone can learn and experiment with hardware. Programming hardware was never been this much easier. Compared to other microcontrollers Pi Pico is better and easy, good for small prototypes and projects. Right now, there is not support from PlatformIO, I hope they will come up with a better solution for programming Pi Pico with C/C++ which will make over lives easier. Raspberry Pi and Adafruit being a very large community you can do wonderful things using this powerful and microcontroller board Raspberry Pi Pico.
Reference
https://www.raspberrypi.org/documentation/rp2040/getting-started
https://youtu.be/5l3W-brnO7E
https://www.arduino.cc
https://micropython.org/download/rp2-pico