Pi Pico morse-code converter
I’m stuck in a government-appointed hotel for a mandatory 10 day isolation, following a lengthy trip to Guyana on an isolated drilling ship, and I’m somewhat bored.
Thankfully, my wonderful cousin mailed me a copy of HackSpace magazine, which came with a free Raspberry Pi Pico, the new microcontroller by the Raspberry Pi Foundation.
This new microcontroller uses custom-made silicon, which contains two Arm Cortex M0+ cores, 264kB ram, 26 GPIOs which include two I2C, two SPI, two UART, and three ADC. The Pico has 2MB flash. It also has other stuff, like some fancy new thing called Programmable I/O (PIO) but I’ve no idea what that really does yet.
Well, because I’m stuck in a hotel room, and don’t have access to anything I can connect to the Pico, I was wondering what I could possibly do with just the onboard LED. My cousin jokingly suggested morse code.
The Pico is provided with “getting started” guides for both C++ and Python, and It’s been a while since I did any programming in Python, so thought I would choose that route.
Check out the getting started page by Raspberry Pi https://www.raspberrypi.org/documentation/pico/getting-started/
It details the specs of the microcontroller and shows basic getting started guides for both MicroPython and C++. It explains how to get the Pico running MicroPython, by copying over the .uf2 file.
I used Thonny to interface with the Pico and as an IDE for writing my code. It’s pretty and does the job well. https://thonny.org
Once you’ve installed Thonny, select “Run” menu, then “Select interpreter…”, choose MycroPython (Raspberry Pi Pico) from the drop down.
It should autodetect the Pico.
Basically, what the code does, is take a text string, and outputs it as morse code using the Pico’s onboard LED. It also shows what it’s doing via the serial console.
As for the coding, it’s fairly straight forward and should be easy to follow as I’ve commented most of the code. As it’s been a while since I did much programming in Python, as usual the internet comes in handy. Specifically https://www.w3schools.com/python/default.asp was great for reminding me of the correct syntax.
Code is also published on Github: https://github.com/WarmCatUK/morsepico
My cousin tried it out with a piezo buzzer and it sounds great. Just a case of changing the output pin from 25 to whatever pin you connect your buzzer.
Below is a video of it in action with the LED: