Vibe coding the MMM
Measuring munchkins is time consuming and tedious work. Nobody wants to do it. So let’s put on our tech-bro hat and automate it!
This week, I played around with vibe coding. For those of you who don’t know, vibe coding is the process of using AI to help create software code. It enables idiots like me to write code that works pretty well!
In my case, it took the weekend of noodling and arguing with an AI to get a fully functioning measurement device up and running - and it was pretty eye opening! Let’s first start with the MMM (munchkin measuring machine) hardware and then we’ll dive into the software.
The MMM
If you recall from my deep dive on munchkins, I am simplifying the donut shape to an ellipsoid since they’re basically oblong spheres. The purpose of the MMM is to capture the dimensions of the three axes that make up an ellipsoid.
I also wanted to start capturing the weight of each donut because it might help me dial in the dropstopper and trigger forces later. It’s always easier to capture too much data than to go back and do it again! My goal was to have all of this data entered into a spreadsheet automatically when I pressed a button that corresponded to the donut type - yeasted or cake.
I wanted to simply drop donuts into the fixture and have a non-contact method of reading their dimensions so that I could keep cleaning to a minimum and allow me to eat them or use them for testing later. I settled on these nifty time of flight sensors from Adafruit since they’re fairly low cost, easy to implement, and are cool as hell. This technology works by measuring distance based on the time a pulse of light takes to reflect off a surface. It is used in everything from cars to smart home speakers, so it should be good enough for a donut!
Check out this demo from the adafruit site to see it in action:
I used a simple load cell to measure the weight. A load cell is basically a block of metal that deforms every so slightly when weight is added to it. A sensor called a strain gauge measures how much the metal deforms and a microcontroller can then determine how much weight is on the sensor. This is the same technology used on most scales and it’s accurate, reliable and cheap!
Lastly, I needed a way to interact with the fixture. I am using three colored buttons here, one for measuring the cake donuts, one for measuring the yeasted donuts, and one to calibrate the fixture. I wanted to add enough buttons for every donut type, but that got a bit complicated due to the number of communication pins available on my microcontroller - I can add that later if I’m feeling spicy.
Here’s a terrible drawing of everything that goes into this device:
Some custom 3D printed parts hold everything together and I wired it all up to an Adafruit QT Py microcontroller. The next step was to program all of the logic- and that is exactly when I stepped out of my comfort zone.
Programming
It’s easy to buy these sensors and microcontrollers and set them up on a 3d printed fixture. It’s much harder to get them to talk to each other and do my bidding reliably. For that, I need to write code and program the boards.
I suck at programming. It confuses me and I don’t have the patience to figure it out. I can make a light blink and do simple stuff, but reading 3 sensors and a load cell and doing calibration on the sensors is beyond my capabilities.
I’ve been hearing more and more about vibe coding and how it’s what all the cool kids do, so I decided to try my hand at it. I simply opened up google Gemini and began talking to it. I started by listing out the sensors and microcontrollers I planned to use, and the desired outcome. Gemini was very congratulatory on my selection and made me feel like this would be an easy thing to do.
Google Gemini is a liar.
Vibe Coding
Using AI to code is similar to trying to get your drunk genius friend to do something intelligent. Most of the time, you’re arguing with them and keeping them from throwing up garbage. But occasionally, magic happens and everything works perfectly.
My job in this process was to write out my desired outcome to the AI chatbot, paste the generated code into the Arduino development environment, and then copy back error messages. Gemini would then say something like “this is a common error that can occur” then provide an explanation of the fix it is implementing and the new code. I would upload the new code and paste the new error message. I was making slow and steady progress, but it felt very silly.
These AI assistants are great at looking up existing code and hacking together that should theoretically work. They are not great at lateral thinking or troubleshooting. Luckily, I am!
One issue I ran into was around the communication protocol used between the sensors and the microcontroller, called I2C. I was able to read the value of one time of flight sensor fine, but if I connected the other two time of flight sensors to my system everything would crash. It turns out that each sensor had an address that was hardcoded on it, kind of like its name. My microcontroller was basically asking “hey, Albert, what distance are you reading?” and all three sensors thought they were Albert and talked over each other, resulting in a failure to get any readings at all.
One way to overcome this issue is to boot up everything, then shut down each sensor individually and give it a new name (like Annabelle or Pat). Gemini was insistent on doing this one time at the beginning of my program, but in testing it was not working correctly. I had to convince it to please rename the sensors each time I asked for readings instead of one time at the beginning. It was very hesitant to make this change, and even recommended another approach instead. After about an hour of troubleshooting, I had to put my foot down here and push for it to try my hacky way instead.
And it worked! I was smarter than the AI since I could think up “wrong” or non-traditional ways to solve the problem. Gemini was great when it could follow logical steps, but had absolutely no street smarts or improvisational abilities.
Other fun little issues I ran into included
Gemini insisted that one issue was due to a typo that didn’t exist, but then added that specific typo into the code as a solution, causing it to not work. Then, it realized there was a typo in the code and it fixed it. Neat.
It would not, for some reason, accept my request to change which pin to send a command to even after multiple requests. It would say “yeah I’ll do that” and just... not do it. :I had to change this one line of code each and every time :)
The occasional need for me to say “let’s start completely from scratch” and wipe its brain clean of weird preconceived notions on what I was doing. Each time I did this, it began by basically telling me this was a great idea.
Gemini creating a very complicated calibration process that left me with 5 seconds to add a calibrated weight to the sensor without any notice.
But, one weekend worth of vibe coding later and I had 273 lines of code working. Not too shabby! The code is probably laughable by anyone who knows anything about programming, but it works for my needs and that is all that matters!
Here’s the system in action:
Recap and my take
So - what did we learn here and why did I do all this? Mostly for fun and to make something new. But also to learn how new tools can be used to augment my capabilities and let me do things that I usually couldn’t do! Plus now I can measure a ton more donuts.
Overall I think it probably took the same amount of time as an expert, but we got closer faster and then struggled for a while. This is my official graph showing how I think vibe coding stacks up to experts.
If you’re going to tell me that I wasted a bunch of time and could have measured hundreds of donuts by now if I just did it the old fashioned way, my reply is that you’ve come to the wrong place. This is not a project that involves rational decision making, and that’s not really why any of this is happening anyways.
Now that the haters are gone, we can discuss what I’m doing with this data. As you know, munchkins vary in size and it is my life’s mission to try and catch them all (all rights reserved Pokemon). The more data I have, the better I can design my device to hold the most variety of donuts possible. I am currently aiming to work with 75% of the donuts we encounter, if not a bit more.
What’s next?
Oh, cool, you read all of that? Nice.
I think the design is completed! I had a lingering issue with the trigger and dropstopper where you could press too hard and overextend the spring, requiring some finagling to get things to work correctly again. The new design is far more robust, so I feel really good about that! I also changed around the snap position on the cap to be a bit more intuitive to open and close.
The patent process is ongoing and I’ll make sure to share updates as the arrive!
I also updated the website with a cool falling munchkin animation and a new render of the device. I added an FAQ page and made it easier to email me (I’m looking at you - dunkin’).
My interview with Jay Sugarman on NewTV is also up! It went much better than I remembered, even though I dropped a donut like a fool. Checkkit out here
How you can help
As always, please share this with anyone you think may find it interesting to read how I waste spend my incredibly precious time.
I’m ready to make a handful of units for beta testing too! If you’re looking to test this device out, please shoot me an email about why I should choose you. I’m looking for a wide variety of munchkin preferences here (even blueberry!).
I appreciate you for reading along!
💗 Sam