project ideation

Week 2 - Program (almost) anything embedded

For this week's assignment, I wanted to work on building a device that I understand conceptually but had never made physically - a microphone. I began by looking for guidance, and after reading through the types of microphones I could build, I settled on a moving coil microphone. I then began by building a coil out of a cardboard tube with a copper wire coiled around it a few hundred times.

I attached the tube to a flexible piece of tape, acting as a diaphragm, and cut a cardboard ring to mount the coil to.

I then made a base from some scrap wood so that I could position the diagram over magnets in order to induce the current. I then attached the copper wire to the XIAO RP2040, loaded the arduino compiler, and attempted to process the signal into something usable. I was able to get a signal in the monitor, but it was very noisy, and I was unable to get a clean signal. I then tried to use a preamp, but this did not help.

Next, I tried to connect the RP2040 to a speaker. The goal that I first had in mind was to enable the microphone and speaker to communicate wirelessly, but I was unable to get the two to communicate. I then tried to use the speaker to instead to play music. I connected one of the speaker's pins to the RP2040's 1st digital output pin, and the other to ground, and then wrote a program to play a melody.

I began with a function to write an oscillating High and Low digital signal to the speaker, with a parameter for the delay in milliseconds. I then wrote a function to play any frequency, but I quickly ran into problems. I could not create every needed tone if I was constrained to 1ms steps in frequency, so I wrote a new delay function that printed an empty lines an arbitrary number of times to achieve a nanosecond delay. Using this, I could then create a function to play any frequency, and using this I defined a set of functions to play particular notes for a specified length of time, and then I wrote a short melody that is played repeatedly by the while loop.

Files

scroll-up