Programming

I wrote the code for the MusicBox project in my favorite programming language: Rust!

Rust Logo

Writing programs for microcontrollers is often called embedded development because microcontroller chips are embedded in other devices such as microwave ovens, watches, clocks, refrigerators, automobiles, airplanes, tractors, drones, and just about any other machine made in the past 20 years.

See: Embedded development with Rust

The MusicBox project uses the RP2040 microcontroller chip in the Raspberry Pi Pico board.

Software I wrote for MusicBox

Sequence diagram showing driver initialization and startup

sequenceDiagram
    pico-rtic-sound-effects->>sonic_ng: init_pacer
    pico-rtic-sound-effects->>sonic_ng: init_driver_t4_voice1
    create participant T4AudioDriver
    sonic_ng ->> T4AudioDriver: new
    sonic_ng -->> pico-rtic-sound-effects: T4SonicVoice
    pico-rtic-sound-effects->>sonic_ng: start
    activate T4AudioDriver

wavegen16 is a Rust module I wrote to efficiently generate audio samples with different waveforms (square, triangle, sine). It takes the sample rate as a generic compile-time parameter and produces 16-bit signed amplitude values.

sonic_ng is a Rust module I wrote to take 16-bit signed audio samples and turn them into PWM driving signals that control my custom A/D converter and audio amplifier.

pico-rtic-sound-effects is a program I wrote to showcase the abilities of my MusicBox device. It builds on my wavegen16 and sonic_ng modules. Connect it to a terminal program running on a PC and press keys, and it makes sounds!

Screenshot of pico-rtic-sound-effects

Here is a 25-second recording of my sound effects demo in action: sound effects demo

Credits

Open-source software libraries I used for my MusicBox project:

  • rp-hal is an open-source project with APIs for accessing the RP2040 peripherals (UART, I2C, SPI, ADC, etc) from Rust.
  • RTIC Real-Time Interrupt-Driven Concurrency - kind of like a real-time OS in Rust for embedded systems.