AI GPT Code Copilot etc and Arduino programming

Warning: Not for the Arduino Code Purists out there :slight_smile:
I've been using GPT along with Code Copilot for about a month now. My programming level is very, very basic with only general knowledge of code and concepts surrounding it. I found the experience quite similar to working with a human programmer but with some pitfalls as well.

Some of my experience so far... Most important thing I have learned is for anything beyond simple sketches with only an .ino file, (i.e. multiple .h's) ask AI to put 5 character checksums at the bottom of each file it sends to you. I keep a version list in excel to keep track of each change with the checksum of the changed .ino or .h file.. This allows me to easily search the chat to find the code for the correct version. For example:

           case SystemState::Shutdown: return "Shutdown";
            case SystemState::ColdStart: return "ColdStart";
            default: return "Unknown";
        }
    }
};

#endif // SYSTEMSTATES_H

// Checksum: 9D4F1

The second most important thing is when AI sends new code to implement, always ask for it to send a full and complete version based on the last version as a baseline. Here an example:

AI: Let me know if further adjustments are needed!
Me: after compiling now more copile errors. use Checksum: B97C2 as codebaseline

or even better, just send the full code of the last file discussed and ask AI to use it as a baseline when making changes.

AI (at least GPT and Code Copilot) is able to understand the purpose of checksums and can find them in the chat, or retrieve a particular piece of code that has the requested checksum.

I learned the hard way that AI often forgets previous features when creating new script versions and lots of rabbit holes. Using the checksum and keeping a version list really helps...

I'll add more as I continue, but would be interested if anyone else using AI to program Arduino have any experiences and tips to share.

Bottom line for me is that using AI has allowed me to create quite large and complex projects for Arduino, far far beyond my programming skill level.

Thx all!

1 Like

If you do it to learn new things and improve your programming skills for the next time, it's a good way to do it (provided if you don't have any other source like a teacher, or a skilled friend/colleague).
But if you're using AI just to be able to build code you don't and won't ever understand, I'm sorry to say it's called "the Gundam syndrome", and my advise is you should stop it and start studying more. Otherwise it's like saying you know how to fly real jet airplanes but only know how to fly in Flight Simulator. :wink:

5 Likes

Hi docdoc! thanks for your message. well received.

I found that working on the projects I do pick up a lot of little code snippets along the way and am understanding their purpose, structure and where they are in the code etc. Its much the same way I learned multiple languages by deep immersion instead of books and courses. Instead of trying to speak, read and write perfectly, I learn from my mistakes along the way and improve.

I fully agree with you from the context of someone wanting to learn programming, but this is a hobby for me and I'm too old to become a true programmer :slight_smile:

Still a work in progress, but I would never have been able to build this from scratch in such a short time without outside assistance, AI or human...


1 Like

I've never used GPT and/or Copilot and don't understand a thing you are saying. Can you describe a little more in detail how I would use these programs?

Hi Jim,

just gotto chatgpt.com and let it know what you are doing, that you are using Arduino, goals of your project and ask for the the code you need.

there are some addons like code copilot that you can turn on. google code copilot and you should be able to set it up and it works inside chatgpt. You can work with GPT without it as well. Here's a screenshot just to give an idea.

GPT also explains what it is doing and why so it helps me learn and understand a good bit as well..

It spits out code very fast but really doesn't explain how it works and the wiring diagrams leave much to be desired. Seems to deal with generalities rather than specific details that I need.

I don't recommend its use by newcomers to the Arduino world.

I happened across this video on using Deepseek R1 with Arduino. R1 like some other newer models like ChatGpt o1 has "reasoning" capability, but unlike o1 presents you with it's "reasoning".

"For entertainment and amusement only."

Even so, it is quite impressive. In the hands of someone who knows what they are doing it has given a 90% plus solution and saved a lot of typing. Obviously it has limitations and, like any assistant, it has to be given tasks within its capabilities and maybe some of its work has to be corrected.

2 Likes

I am still pondering about the "true usefulness", and how AI would fit into a workflow. It's notable that the user gave very detailed requirements, and didn't understand the code generated, tried hacking it, then told the AI to use a library.

Bearing in mind that an LED flasher is very different than real world tasks, and something that could be accomplished by a high school student. Tbh, I would want the AI to nail that 100%.

I can't really assess whether it is useful for beginners, because I am so far from that. However, tutorials often have errors, and all code needs a test and debugging process, something for beginners to learn early. But the AI method seems to teach a "roll the dice again, and maybe you get a better answer" method.

My experience: Yes, it can be helpful. It does require you to understand code. You can become lazy, let it write code, not understand and not learn from it.

I have used AI to help write C# programs. It has cut down the time to write the program. You must understand the code because it will generate code with compile errors. I find I have to ask multiple times to get the features I want.

I haven't tried it with Arudino, which is the reason I found this article to see if it understood the library.

I will have to try the checksum trick because it forgets the fixes it already put into the code. I have also found that it likes to rename variables and remove comments that I have put into the code. The queries get longer telling it not to rename variables and keep my comments.

Are you really so offended by people who take time to learn and employ good programming practices, that you suggest they not read your praise of a crutch, which is your only means of progress - anything but your own knowledge? I can't imagine the desire to never learn what you are making others use. Sounds like a liability about to happen.

I don't think the comparison is that good. A more accurate one is to say that you know how to fly an airplane while having a veteran pilot next to you.

Plus, from my one experience, as a beginner in Arduino coding (so I understand some basic staff), I was able, with the help of ChatGBT to resolve some complex problems for which I got versos suggestions software and hardware. And the biggest advantage is TIME. When you go to a forum with a problem usually it takes some time to get someone to suggest a solution, sometimes it has not work, and you have to do some back and forth to get to the desire result.
I will give you an example. I have a sensor for light intensity and at a certain intensity I wanted to turn on/off a bulb. The problem was that there were some noise in the reading and at a point the on/off switching was very fast. I try versos things that were suggested by some people, but nothing worked. Then I had an idea. What I want is when the sensor first reaches the target value to turn on the bulb and then wait a wiled so the noise stabilizes. And that was what I asked ChatGBT. And it gives me a code with a "delay". I told it that I don't want to use delays so it gives me a code with a "return" function in the main loop. So because I had some other code in the loop, I told it to put it all in a speared function. And voilĂ , in 10 minutes I have resolved a problem that took me several weeks of trail and error to resolve.

So in conclusion, if you have some basic knowledge of coding ChatGBT will help you to resolve some very complex problems.

1 Like

Do you object to solving the complex problem without using a crutch to have a scapegoat? If you can't do the complex stuff, and verify the complex stuff, you should not be there.

Heh true, but more realistic description is: "you know how to fly an airplane while having a drunk retired pilot next to you, survived to a couple of plane crashes" :smiling_face_with_halo: :smiling_face_with_sunglasses:

I want this item keeping alive because it’s more then worth reading. For me : 2 good advices to know about them. I’ve been project manager for decades. I can understand most of code. But no daily experience with several kinds (Arduino, OPenSCAD, WebDevelopment etc.) of programming. When you are not a real developer but want to get things done in for example IOT it helps me a lot getting things done. Be it after several attemps and wrong understanding from AI and repeating my wishes AI solved it sooner then I ever good do myself because of lacking enough experiences to generated new (complex) code. Of course not every AI gives you the same answers so use more kinds of to find the one which fittest you the best and keep on trying depending on you project which one fits the best in that case. For me it’s like a experienced developer is always nearby who I can ask a advice how to give a tip how to solve the challenge.

I use chatGTP often and it helps me.

But the most importaint think is, that it cannot be trusted.

I do not believe anything it say, I verify everything from other sources. It halucinate often, does not get the right idea, forget what was said, nearly every code it gave me had some (sometimes hidden) problems …

Still (keeping this in mind), it may really help, if used carefully.

It had read the whole internet (probabely) and can gave usefull names and phrases from vague prompts - like

what is in python the long one-line contruction, which does everything?
ChatGPT said:

You probably mean list comprehensions (or “comprehensions” in general).

and two pages of hot-air. I cannot remeber list comprehensions but I can use it, know it when I see it and can google it (in python documentation), if I have the name.

I need in C local variable in function, which survive between calls and keep its content
ChatGPT:
 blah blah STATIC blah blah

exactly what I need, one word (and two pages of crap, but who cares)

Other use is to generate some code. The code is bad and/or wrong, but it is fast and save a lot of typing and it uses somehow usable variable names too (so I do not need to think about names or use aa,zz,xx everywhere). I take the code, fix (or totally rewrite) what I need, for “features” I do ask separately and I implement them to code on my computer. It is way faster and less error prone, than trying to force AI to edit project to desired state.

it goes like

I: 
I need program for Arduino, which reads Serial, parse single words out and for some recognized commands runs specified actions
ChatGPT:
code, code, code, talk, talk, talk
I:
copy some generic example, change some recognized commands, then ask again
I have 6 Neopixels on this pin, how I can define their colors and show it?
ChapGPT:
here is example of Neopixels ...
I: take and modify the important 5 lines from the two page responce
I have SD card connected here, how I will read file "readme.txt"?
ChatGPT:
code, examples, hot-air ...
I: take the 8 lines I need and modify it to read "leds.cnf" instead.

Also good is Rubber Duck debugging Rubber duck debugging - Wikipedia

I have this problem, it looks like this, happen when this and that, also it goes like that and if I try this, it fails this way and if I try that, it fail that way and ... and ... and, wait, I thing I have the solution already
ChatGPT:
I am happy that you solved it itself.

To me its more like being on the phone with a call handler who is following a script. I think we all know what happens the moment the situation goes off script....

I am not saying that it is useless, but there will be times when YOU will need to troubleshoot and understand and be able to take control of the situation.

So how do you know which answer "fittest you the best" since you asked AI in the first place?

No more than a drunken pilot.