Week 9
Output Devices
This week I was working on part 2 of my banana detector. I wanted to add a speaker to say "banana" when a banana is identified. I had planned for this last week and left space for a lrc filter and a n-fet on my board. The plan was to turn the digital pwm to analog using the filter, and then use the n-mosfet for amplification. This worked for playing notes, but just sounded like noise when I tried to do anything else. It turns out the mosfet was clipping my values making the quality really bad. I tried adjusting the values so they wouldn't be as clipped and it sounded a bit better but still not great.
Since I knew I would have to remake my board entirely, I decided to pivot to using a MAX98357A I2S DAC/amplifier. This was a bit of a challenge to figure out how to program. I tried a couple libraries and it took a bit of debugging to get sound, but once I got it working it sounded really good. (It seems Neil uploaded example code to the website shortly after my struggle)
I frist got the speaker working with a mess of soldered wires. But once the speaker working, I remade my board, and got it working on the new board. I somehow forgot to hook up ground so I had to add a little wire.
I also wanted to circle back to my banana detection algorithm. Having to always connect to WiFi was annoying so I wanted to try TinyML. I followed along with this tutorial I first tried with an online dataset I found for fruit object detection. This did not produce any positive results so I scrapped it. I'm guessing it's because the pictures taken with the xiao are a bit discolored and blurry so the training data was not close enough. Then I tried taking my own pictures. I took over 100 pictures with the xiao and classified them into "banana" and "not banana"
This worked better. It's still not perfect. I think this has more false positives than my detection algorithm from last week, but it works well enough, and I like not relying on WiFi connection.
Now it came time to integrate my speaker with my detection system. I found some audio files I wanted to use and since the xiao camera module has a space for an SD card, I figured I could use the SD card to store the audio and not have to worry about its size. Then things stopped working. I spent a long time messing around with things, but it was all being wonky. Then I backed tracked and the speaker and classifier worked separately so there was something wrong with using them together. Turns out the three pins I chose for my speaker were the exact three pins needed for the SD. I decided to cut the copper traces and rewire the speaker to other pins.
Then after a little more debugging, it worked! I added some randomization so it chooses between 6 different audio clips when it sees a banana
I also 3D printed a case for it. I wanted it to be yellow and luckily EDS had some unused yellow PLA lying around. Even though the filament was ~7 years old, I had no issues!