Raspberry Pi Pico with C/C++

How to Raspberry pi pico with C C++

Sanjay TM
3 min readAug 25, 2021
Raspberry pi pico with C C++
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)

While installing make sure that you have selected the following:

  1. Python — Add Python, Install PATH
  2. AGM GCC compiler — Add path to environment variable
  3. CMake — Add Path
  4. Build Tools for Visual Studio — Install C++ with default options
  5. Pico-SDK — Download the zip and extract it to a folder directory of your choice. Add the path to User Variable
Add Path

Next install C/C++, CMake tools extensions in Vscode
Configure CMake tools: Extension Settings

  • Cmake Path: cmake
Cmake tools extension
  • Configure Environment: Item = PICO_SDK_PATH, Value = Pico_SDK directory
  • Generator: NMake Makefiles
NMake Makefiles
Name/path cmake

Restart the VScode, now you can see GCC for arm-none-eabi 10.x at the bottom.

GCC_for ARM

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

blink.c
pico_sdk_import.cmake
CMakeList.txt

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

--

--

Sanjay TM
Sanjay TM

Written by Sanjay TM

I'm an engineer working as an IoT Developer. I work with hardware, software, 3D printing & robotics. Now working with Flutter and Golang

No responses yet