My Thoughts on Programming a Raspberry Pi Pico with Rust

Alex Wilson
4 min readApr 4, 2023

--

There are loads of ways to program the Raspberry Pi Pico, and I won’t claim to be purveying the best way. I will definitely say if you’re interested to learn Rust, as well as how to interface with the RP2040 Microcontroller, you’ve stumbled into the right place.

This blog index covers my Pi Pico Development efforts up until this point, and has detailed posts on getting started, implementing controls principles, and using libraries for Rust with the Pico. To get in-depth guides so that you can be up and running, this is a good option.

Here are some recommendations from my experience programming the Pico with Rust

  1. Learning Rust AND learning micro-controller programming at the same time is a tall order. I can say that unless you’re just in a hurry, I don’t recommend learning both at the same time. It’s discouraging to butt heads with the borrow checker in Rust while also facing CPU, Memory, and functionality limitations present on the RP2040 (compared to standard programming)
  2. Know that you don’t have access to the STD crate, but you do have access to both the CORE crate, as well as the Alloc crate, and those will be massively helpful in replacing the wonderful features present in the STD crate. (crates are rusts term for libraries or packages)
  3. Immediately learn how to set up unit tests on your machine, and how to export tested code into a project that will be compiled and translated into something the Raspberry Pi Pico can use. This step will make your life so much easier when you’re trying to understand what your code is doing while running on the controller.
  4. Deeply learn Rust Traits. And use my Traits index to do so! Rust traits are a thing of beauty, and if design elegance is a thing you enjoy, you will be absolutely enamored with traits when you start to understand how intentional and delightful that can make your code. I wish for traits now in my day job using TypeScript.
  5. Know that if you learn to program the Raspberry Pi Pico with Rust, you’re learning 95% or more of what is required to program any microcontroller that is run by the RP2040, which is a quickly growing list that will likely only continue to grow from here!
  6. Taking the time to learn Rust deeply will make you understand more about the languages you already know. This is probably true of learning any new language, but I’ll say that Rust absolutely forces you to think about things from the compiler/interpreter perspective. This is a very valuable skill to develop.

I Won’t Only Evangelize Rust Here Though

I would like to take a second to warn budding programmers about the cost of learning Rust. It’s not cheap when it comes to time investment, but the return on investment is large. If you want to get a project done, and you want it done fast, this is not the way.

If you don’t already have some chops in at least one language and you’re trying to move quickly on a project, this is one of the slower ways of getting this work done.

However, if you succeed, you’ll have fantastically fast code, that is also naturally robust, and you’ll have a great set of tools for getting work done on embedded systems. You’ll also learn quite a lot more about programming in general if you choose to use Rust as opposed to Python. Python’s low curve to adoption allows you to get things done without understanding much about why it works. Rust does not afford anyone this option, it almost requires that you understand exactly what the code is doing unless you’ve found a good source to copy-paste from.

Conclusion

I have deeply enjoyed learning Rust and being able to build my projects for embedded systems. I love working without external dependencies on third-party toolchains, it’s liberating.

And I have become a much more thoughtful programmer in the short time that I have used Rust. I’ve always considered the next human reader of my code, but now I also consider what the intentions of the designers of a language were when they created the bit of their standard I’m using at that moment.

This journey is far from over for me, but even this early on it feels like it was a great choice to have made.

--

--