"Vibe coding" Spin with Gemini

I've been working with LLMs out there in my regular work, and since the Open House is coming, I thought it might be fun to try working with Spin and seeing what one of them can do. Since Spin has been out a long time and the OBEX is up on GitHub, I figured that everything in it has been absorbed. On the other hand, I've also found that projects not using common web languages run into all kinds of problems pretty quickly.
My demo idea was to use an ultrasonic distance sensor, and a strip of Neopixels. The Neopixels start out all lit up, and as you move your hand closer to the sensor, they turn off - kind of a manually controlled bar graph.
First I tried Claude. Ugh, it had a hard time getting Spin right. Eventually it got late and I gave up.
A couple of nights later I tried Google's Gemini in Google AI Studio. It also struggled, but was much better about understanding its errors and fixing them. I started with having it read the ultrasonic sensor and display the distance. It had to fix three bugs, like this one:
Error: Expected a constant, unary operator, or "("
On this line: US_PER_TICK = 1_000_000 / clkfreq
It did it pretty fast and then the code worked - the ultrasonic sensor shows the distance on the PST.
So it was onto the Neopixels. It struggled with getting it right - until I gave it the current version of jm_ws2812b.spin from the Obex by pasting it into the chat. Then it analyzed it and did a new version of the Neopixels, and got it right.
Finally I asked to combine the two:
Use the Ultrasonic sensor to read the distance and light up the string of 8 Neopixel LEDs. The ultrasonic sensor should read a hand at 1 meter, and light up the entire string of Neopixels. As you move your hand closer to the ultrasonic sensor, the Neopixels follow it and turn off from the farthest point. So the effect is that the line of lit Neopixels gets shorter as you move your hand closer to the ultrasonic sensor.
And it got that right.
This is currently sitting on my desk and is fun to play with. Anyone want me to bring it to the Open House?
Comments
Yes! I haven't exactly welcomed our AI overlords, but I'd like to see what you've done
I liked this part;
"So it was onto the Neopixels. It struggled with getting it right - until I gave it the current version of jm_ws2812b.spin from the Obex by pasting it into the chat. Then it analyzed it and did a new version of the Neopixels, and got it right."
The AI just needed some jm_ code to put it right!
Follow-up to my talk at Propeller Day...
I picked up a Laser PING in the giveaway bin (version A, the old one) and decided to see how quickly I could get Google Gemini to convert the code from an ultrasonic sensor to the PING code.
It took very little time. I followed my own tips! (See the next post.)
These were the prompts:
[Pasted working code]
[Pasted the PING library for Spin]
[Pasted the demo code from the Ping download]
Note that all of the above was done as one big prompt, before I hit CTRL - Enter to make Gemini read it and go to work.
It came back with code that added a reference to a method that doesn't exist in Jon's driver. Whoops! Here was my next prompt:
[Pasted jm_ws2812b.spin]
However...then Gemini replied:
So I said:
Then it said:
It updated the code. And the code worked.
Total time: About 6 minutes.
Tips for working with LLMs:
You guide the LLM through the process of helping you code.
Know your fundamentals. You should be familiar with the parts of the project before starting.
Plan the project in steps.
Build the project in pieces.
Feed clear information back to the AI when you get an error message.
Provide specific code you want used, such as a library.
And also pay the actual electricity costs. Once the real costs are transferred, plus some profit, people aren't going to be so enamoured I don't think.
Honestly though, all that work to coax an unreliable output seems more like a burden than a benefit.
I guess that's what I've been saying all along though. Unless the LLM has already been fed all the examples you're wanting it to regurgitate, then it won't be any use.