I’ve spent the last week putting together the rudiments of my midterm project.
To recap:
The project involves a balloon that inflates as one speaks to it, and in doing so, records one’s voice. As the balloon deflates, the voice is played back to the speaker.
All in all I feel this week has been successful. I began working with an Adafruit QTPY (RP2040) and ran into a lot of issues around communicating with the SAMD Microphone breakout board via I2C. Luckily someone had published an example library for a similar RP2040 board. With some hacking I managed to get the microphone to work.
The next issue was to get workable sound data - volume was enough for now. In order to do this I used a basic sample buffer that was averaged out in order to get peaks of volume, but this proved somewhat ineffective given the speed of data transmission, and the fact that the microphone is very “noisy” regardless.
I found a smoothing library that was pretty “plug and play”, which seems to run an averaging algorithm without having to result to an array, and is modifiable according to sample size. After integrating it, I was able to get sensible volume data.
// find the 'peak to peak' max
float maxsample, minsample, pmv;
minsample = 100000;
maxsample = -100000;
for (int i=0; i<SAMPLES; i++) {
minsample = min(minsample, samples[i]);
maxsample = max(maxsample, samples[i]);
}
int peakVol = (maxsample - minsample) / 10000000;
average.add(peakVol);
int volume = average.get_avg();
//Serial.printf("peak: %d\\n", volume);
Serial.println(volume);
if (volume > 8 && inflationState == 0) {
inflate();
inflationState = 1;
millisInflated = millis();
} else if (volume < 8 && inflationState == 1) {
deflate();
inflationState = 0;
}
The smoothed microphone output:
I set about constructing the rest of the circuit. I had some difficulties with the motor driver board which were resolved after centralizing all power to the entire circuit - I used my variable power supply to provide 5v, and installed a rectifier to 3.3v in order to power the QTPY, this seemed to do the trick.
The issue I ran into was that the motor driver required 3 pins for each motor (6 in total). Along with these 6, I had to provide an enable pin, as well as another pin for the air valve that allowed switching between the motors. This left me with precious little pins for the QTPY, particularly given the fact that I needed two specific I2C pin sets in order to interface with the microphone and eventually the SD card breakout.