Using AI to generate complex Arduino sketches – Grok, Copilot and ChatGPT tested.

I recently made a video about using Grok AI to generate me a simple kitchen timer using an Arduino and a 4 digit 7 segment display. After about an hour Grok was successful but using any kind of AI you need to give an accurate prompt describing your hardware, what pins are used and what type of display you have. In the example I asked Grok I used simple shift registers so the prompt I gave it was:-

Write me an Arduino sketch that makes a kitchen timer which can count up and down on a 4 digit 7 segment display. The timer should be adjustable so it can count up to 99 mins and 60 seconds and also count down up to 99 mins. There are 4 buttons which can be used to set the time to count down from and also to set mode (count up or count down) and to select the minutes and seconds to count down from.

The 4 buttons are connected to pins 2,3,4,5 and are active low. The data to the display is via hardware SPI. Digit layout is g,f,e,d,c,b,a,decimal point with segment G being the least significant bit. I can provide an example of the segment layout if required.

This produced a working sketch but the display was reversed so that it displayed seconds, minutes and hours. A quick prompt later this was fixed but the buttons didn’t work. After some troubleshooting – Grok added serial output diagnostics we found the buttons do work but the display wasn’t updating. That took lots more prompts but in the end it all worked. Here is the video if you want to take a look.

That got me thinking, what about something more complex?Mvimg 20200530 171357 Well I made a dot matrix scrolling message display a few years ago pictured to the right so what about making a dot matrix clock using this display? Well to cut a long story short writing this from scratch resulted in several hours of frustration so having run out of my AI quota for the day I tried again and asked Grok to make a clock using the existing scrolling message display as a template. Eventually I managed to get an inverted display but again ran out of credits for the day. I also tried ChatGPT but it kept forgetting my program and earlier conversation and supplying generic answers. After 2 hours I gave up. So I tried copilot. That got me a working clock almost immediately but the display was back to front and shifted down a row. After explaining the shift register connections and a few more prompts it was working. But like ChatGPT it kept forgetting and providing generic answers. But I got there in the end. I would have demonstrated it but copilot then crashed and when loading that conversation it just crashed again. But I have my code which works; Ill provide it below if anyone wants to give it a try.

LED Matrix Clock with Copilot

Web based simulation of the LED matrix clock

So I’m going to do a few summaries I found with the three big AI’s that claim to write code. I honestly recommend Copilot which is built into Windows 11 or on the web for those who are still on earlier versions of windows or on Linux / Mac. All three AI’s were given the scrolling message display program as a template and asked to turn it into a clock which used 3 buttons to set the time.

Grok (V3)

Able to write complete sketches from a prompt and will provide an updated sketch based on prompts and comments made. Falls flat with more complex code and often puts random spelling mistakes in the middle of the code. Does not appear to actually figure out why the code does not work and gets it information from the web which may be wrong. Although it made a program that compiled it failed to generate fixed code from a description of the error. It did attempt to fix the issue and gives clear, concise information as to what it found wrong, what the proposed fix is and a fixed version of the code segment that causes the error. Seems more suitable for assisting with snippets of code that does not work rather than writing large programs from scratch or diagnosing complete programs.

ChatGPT (GPT-5)

As above this AI is more of an assistant. Very painful and frustrating to use and forgets what you said earlier reverting back to generic examples when asked to fix a non functional program. It then offered to fix my program then dumped a generic MAX7219 clock project as the solution – mine uses shift registers for columns and row scanning. I told it 4 times that was not my program but ChatGPT insisted it was and when told to use my original program, it had forgotten requiring me to re-upload it. It then started suggesting fixes to things it had already done… Very annoying. It also does not explain things well like Grok can and needs several reminders to generate an uploadable sketch then it provides a generic sketch obviously pulled from the internet. Was going round and round in circles and not getting anywhere. Instantly forgets an uploaded file and changes pin definitions even though it was told not to. Often programs it generates will not compile.

Microsoft Copilot (GPT-4)

This is absolutely brilliant – got exactly what I wanted on the first prompt. Just needed a few more prompts to fix issues like display shifted to the left, back to front etc. Behaves like a human and remembers past conversations. Gives clear concise information like Grok does but does not generate a complete fixed sketch unless asked to. Instead it will provide fixed code snippets for you to paste into your program however it will sometimes revert to generic examples instead of giving fixes based on your uploaded code. Unfortunately this has a major flaw – when conversations get too long particularly when posting large code samples it will crash and loose your information. It’s a known issue so best use web version to avoid this.

Completed clock made with Copilot

So to close out, I’d recommend Copilot over the others at this moment. I’ve noticed that Copilot has now got a GPT-5 mode but I didn’t use this.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.