Getting Started With Raspberry Pi Pico on macOS
The modern Mac platform makes a great development environment for embedded programming. The Raspberry Pi is a very inexpensive, and even in 2023, relatively available embedded board. It’s very easy to interface it with other devices. And there are many language options. The Arduino, µPython, or the native C development tools all great options that work well on macOS.
The Arduino and µPython environment are simple and straight forward to get working.
The C development tools for the Raspberry Pi Pico work fairly well on macOS. However, it does take a bit to everything set up. It seems there are different sets of instructions, some work, some don’t works so well. I used a mixture of things and figured some stuff out myself So I provide what I did to get everything to work under macOS 13 on a Mac Studio with an M1 Max processor.
All 3 provide powerful tools to develop software for the Raspberry Pi Pico SBC.
Setting up macOS
Introduction & Basic tools
For starters, you want to have the Xcode tools, Xcode command line tools and brew installed and working. I’m going to assume you have installed, or know how to install those tools and how to connect the Pico to the Mac and use BOOTSEL mode on the Pico. I also only use CLI tools and vi as my editor of choice. So all instructions here will be for CLI tools.
You can use brew to install most of the other tools you’ll need as noted below. If something needs to be downloaded or installed with Pip, it will be so noted.
Serial Communication with the Pico
You’ll need a serial communications program. I use minicom available from brew
brew install minicom
It’s a simple CLI program that reminds me of an old DOS program. The interface is a bit clunky, but it works well enough.
You can get the device with
ls -lrt /dev/tty.*
It will be something like /dev/tty.usbmodem8334401
Then connect with minicom:
minicom -D /dev/tty.usbmodem8334401
Arduino
The Arduino IDE, or CLI tools can be installed either from downloading them from Arduino’s site or via Brew. Just make sure you have the latest version.
If you are familiar with the Arduino environment, this is literally as easy as booting the Pico into BOOTSEL mode, and in IDE, selecting the Pico in the boards. Use as normal after that. After each upload, the Pico will have to be power cycled before the next upload can occur. And it will auto run whatever the last program was.
It’s really that easy.
µPython
set up
While µPython is almost as easy as the Arduino, it has some set up and you’ll need a couple things
First is to install rshell with pip
pip install rshell
Download the µPython
Boot the Pico into BOOTSEL mode and copy the µPython run-time .uf2 file to it.
Connecting to the Pico
After it boots, find the board
rshell -l
As noted, the device will be something like /dev/tty.usbmodem8334401
rshell -p /dev/cu.usbmodem8334401
Once connected, you can list the Python programs on the Pico
ls /pyboard/
To copy files to the Pico
cp /tmp/test.py /pyboard
To copy files off of the Pico
cp /pyboard/test.py /tmp
To delete files from the Pic
rm /pyboard/test.py
To edit files on the Pico
edit /pyboard/test.py
repl
With repl, you can run µPython programs on the Pico
This assumes /pyboard/test.py exists
# repl
>>> import test
NOTE: If there is a file called /pyboard/main.py, it will run when the Pico first starts.
Reference
https://www.raspberrypi.com/documentation/microcontrollers/micropython.html
The C SDK
Pre-requisites
Using brew, install the tools needed for the build environment
brew install cmake libtool automake libusb wget pkg-config gcc texinfo automake autoconf pkg-config libtool texinfo wget gcc
On my set up, I have my files in $HOME/Code/pico. This is the working directory and all paths relative paths referenced from now on will be relative to that.
mkdir -p $HOME/Code/pico
cd $HOME/Code/pico
Set up
First install compiler
brew tap ArmMbed/homebrew-formulae
brew install arm-none-eabi-gcc
As a side note, I find it rather funny that I have install an Intel binary on an ARM based computer to compile for an ARM based computer.
Anyway next step is to clone the repos
git clone -b master https://github.com/raspberrypi/pico-sdk.git
cd pico-sdk
git submodule update --init
cd ..
git clone -b master https://github.com/raspberrypi/pico-examples.git
Add the PICO_SDK_PATH to your .zprofile
echo 'export PICO_SDK_PATH="$HOME/code/pico/pico-sdk"' >> $HOME/.zprofile
And start a new terminal window to work in.
Building the example C programs
First set up the directory.
cd pico-examples/
mkdir build
cd build
cmake ..
Now individual programs can be compiled
cd blink
make -j 8
Now blink.uf2 can be drag and dropped to the Pico when it’s connected to the Mac and in BOOTSEL mode.
Building your own C programs
Make a working directory and copy the cmake file
mkdir -p test/build
cp pico-sdk/external/pico_sdk_import.cmake test
cd test
Next create a CmakeLists.txt
# What CMake to start at
cmake_minimum_required( VERSION 3.12 )
# Pull in SDK (must be before project)
include( pico_sdk_import.cmake )
# Initialize the SDK
pico_sdk_init()
# Set the name and version of the project
project( test VERSION 1.0.0 )
# the executable
add_executable( test test.c )
# pull in common dependencies
target_link_libraries( test pico_stdlib )
# create map/bin/hex file etc.
pico_add_extra_outputs( test )
Make test.c
#include "pico/stdlib.h"
int main() {
#ifndef PICO_DEFAULT_LED_PIN
#warning blink example requires a board with a regular LED
#else
const uint LED_PIN = PICO_DEFAULT_LED_PIN;
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
while (true) {
gpio_put(LED_PIN, 1);
sleep_ms(500);
gpio_put(LED_PIN, 0);
sleep_ms(500);
}
#endif
}
And build it
cd build
cmake ..
make
And the test.uf2 file in the build directory can be copied to the Pico in BOOTSEL mode.
References
https://www.raspberrypi.com/documentation/microcontrollers/c_sdk.html https://wellys.com/posts/rp2040_c_macos/ https://blog.smittytone.net/2021/02/02/program-raspberry-pi-pico-c-mac/