Having Fun with the Raspberry Pi Pico
About a month ago I got curious to know where it all started, at least where modern programming started. I did some digging and one way or the other most roads lead to K&R and 1978. For anyone who’s unfamiliar with this, that’s the year when Brian W. Kernighan and Dennis M. Ritchie published The C Programming Language book.
Lucky for me, my favorite Computer Science teacher, Dr. Chuck, is in the process of building his new Massive Online Open Course (MOOC) focused on the C language: C Programming for Everybody (CC4E). Armed with his course and with the 1978 book, I took my first baby steps. And what a journey this is! The K&R book is pure gold. It felt like it was written yesterday, very engaging and filled with fun challenges. It kinda reminded me of my first ever encounter with coding. I was 10 or so and my dad brought home a CIP-03, a Romanian made computer. It’s a 1988 copy of the Sinclair ZX Spectrum and it runs the BASIC interpreter. It can do math, circles, squares and even some simple games. I still remember the sound it made when it read and wrote data to audio tapes for storage; just imagine the sound of a 56kbps dial-up modem to the power of 2, that’s how loud it was.
Unlike 30 years ago, I am now armed with the internet, a proper keyboard, a mouse, fast and quiet storage galore and impressive computing power. Mind you, this doesn’t make it any easier, but it’s certainly more enjoyable. I went through the first C chapter just like riding a bicycle. On the following chapter I struggled with some exercises, especially with the hexadecimal to decimal script; I had to learn the hard way that C manipulates characters using their ASCII representation. Oh, the joy I felt after getting my program to work after four days of struggle.
In the meantime, Andrei, a friend of mine, heard of my adventure in the world of C and made me an offer I couldn’t refuse: a microcontroller! He gave me a Raspberry Pi Pico with WiFi (RPi Pico W), a touch-button, a couple of wires and a job to do: program the LED on-board the Pico W to blink using C, the Pico SDK and CMake. Like stealing candy from a child, right? On the contrary! This task took me 3 weeks. I struggled to setup CMake and the Pico SDK under Windows 11. I struggled to understand how CMake works, what’s a CMakeLists.txt file, how a compiler and a builder work, and finally I struggled some more to piece together the code from the SDK examples and adapt it to run on my Pico W using its dedicated libraries, its General Purpose Input Outputs (GPIOs), Ground and 3V3Out. It didn’t make it any easier that the Pico W is a tad different from the older Pico without WiFi that’s alot more popular. You should’ve seen my satisfaction when that Pico W on-board LED ran my code and finally blinked. Some things money just can’t buy! Since then I completed a few more projects with my Pico, got myself 2 breadboards and 2 more Picos, a bunch of parts, ranging from resistors, diodes, jumper cables, LEDs, buzzers, proximity sensors, and so on, and even managed to run text messages on a 16x2 LCD display using the Pico W. To make my life easier, I switched to the Thonny IDE and MicroPython and put C and CMake on hold for now. I find it easier to learn and prototype with these tools since I’m more familiarized with Python.
I’m full of ideas of how I could use microcontrollers to build an alarm, an automatic feeder for my three cats, signaling lights for my road bike, a big scrolling LCD display - like those seen on Wall Street - to place in my living room, and many more. I find that Andrei’s idea of mixing electronics with coding really worked, it added lots of fun to this learning journey and opened my eyes to endless new possibilities. For a device that costs no more than 2-3 coffees I’d say it’s worth every penny. Please do yourself a favor and get a Microcontroller Unit, be it a RPi Pico, an Arduino or whatever you feel like. You won’t regret it!