From Ideas to Code: Enhancing Arduino Programming with chatGPT!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
write five simple sentences in simple words which will be the intro to my YouTube video about the fact that the AI is all around us AI generated images kids using AI to do their homework can I use AI for something I do can AI help me write Arduino programs or maybe it can outright replace me do not number sentences welcome to my YouTube video today we are going to explore the fascinating world of AI and how it's becoming increasingly integrated into our daily lives from AI generated images to Kits using AI to tackle their homework this technology is all around us but have you ever wondered if you personally can benefit from using AI can it assist you in writing Arduino code or replace you entirely let's dive in and find out together [Applause] [Music] so how did you like my charge GPT generated intro it was not too bad right in this video we are putting Arduino GPT to the test we'll ask it to write few Arduino programs we'll start with a very simple sketch and then move to the more complex ones we'll not only check if the code works but in one particular case we'll compare it with my own code should be interesting we'll start with a simple code to control few LEDs for the purpose of this challenge I build this simple circuit where you have five LEDs connected to digital pins from two to five I'll ask chargpt to write LED Chaser program to make it slightly more difficult we will request the interval in between each state to gradually change from 10 milliseconds to 150 milliseconds and gradually to shrink back to 10 milliseconds okay I'm ready I'm hitting enter and the magic begins this is freaking insane right this code looks legitimate and also charge GPT generates short documentation you can hit regenerate code and believe me the code and the documentation would be slightly or sometimes entirely different each time you do it let's paste the code to Arduino IDE and have a look at it we have led pens nicely declared and set as output and in Loop function we have a simple for Loop which goes through all LEDs litting each one for the interval duration and then turning it off and moving to the next one then you have a code section that's increasing or decreasing interval as per my request let's power Arduino and compile the code so far so good loading it to the boat and LED Chaser program works fine and you can clearly see interval changes I'm impressed so the first challenge is completed successfully the program was generated and I did not have to change a single thing moving to the next challenge this time we will see if charted GPT is aware of specialized libraries we may need in some programs so in this case we want to use OLED display I'm going to request chartered GPT to draw a large Circle in the center of the screen and inside that Circle I would like chartered GPT to count from 0 to 9 using size to font generating started nice AI declared the right libraries and set the right display Dimensions code is ready and you also see a short documentation let's move it to Arduino IDE and load it to microcontroller it works but the circle is not in the center let's complain to AI about it and ask it for a fix as always AI is very apologetic and regenerates a code for us let's try it it fixed the circle issue but changed the digit placement which I did not ask for let's be persistent and ask AI to get the code right and now it looks better not perfect but it shows you can actually have a dialog with AI to perfect the code and fix potential issues in the next challenge we also would use OLED display when I was at the University we used to write Pascal code to generate fractal images I think it's a perfect idea for challenging tasks for AI I will ask chatgpt to generate visually stunning fractal image on a tiny OLED display Ready Set Go that looks like a complex piece of code oh look we are there for a treat it is actually mandelbrot set fractal one of the most stunning ones you actually can see it in the intro to that challenge it will not be as colorful and pretty on this tiny display but let's have a look wonderful I had fun with chart GPT and regenerated this request dozens of times majority sketches I got were no good they showed either nothing or complete gibberish but I got few amazing ones here is the different representation of mandelbrot set this one is beautiful and I identified it as core curve fractal I have no clue what that one is this one I think is Julia set fractal but then I also got some messy ones like this or even this one which is not visually stunning at all time for the last challenge I'll ask Chad GPT to count from 0 to 9 on a seven segment display connected to shift register I have wrote Such program before so I will be able to compare results generating started looking good finished I copied the code but before I run it let's compare it with the sketch I wrote in one of my last videos let's look first at declarations and setup function here is Mario's IDs code and here is the one generated by chat GPT first you see the section to the clear shift register pins no real differences here AI version has comments which is nice as it helps others to understand your code I sometimes get too lazy to do that next you have a section where you define bit sequences for each digit AI version is much more optimal from memory consumption standpoint in my defense objective of my code was not to optimize memory but still my table occupies eight times more memory than chat gpt1 in setup we set all shift register pins as output and those sections are pretty much the same moving on to Loop and to custom function which exists in both codes used to display individual digits here is my code and here is the one from chapter GPT Loop function is virtually identical but you do see some differences in custom function it is cool that AI chose nearly the same name for it there is a difference in the way I push the bits into the register I do it by sending in turn high or low signals to clock pin feeding the bit sequence one bit at a time in between the changes actually I fit inverted values as the display I'm using is common anode so 0 lets a segment and one turns it off AI is using shift out method which does the same thing it takes the bit sequence for a digit and in this case it loads it to shift register starting with most significant bit first the large pin actions are pretty much the same in both programs so all in all AI code looks more tidy and it is definitely more optimal on paper let's load it to Arduino and see if it actually works and it does not there is some data reaching the display so that means the data pin is okay we do not see changes in one second intervals so I suspect clock and large pins are incorrectly declared let's swap them around okay we see some improvement but still digits are not displayed properly it is tricky to troubleshoot something like this I'll pick one digit and comment out the counting routine in the main Loop and display just this one selected digit for one we should see just two segments of it and that is not the case six lit segments indicate that AI code is for common cathode display we can fix it by inverting all the bits sent to shift out method reloading the code again we see some improvement but the one is still incorrectly displayed I suspect the bits were pushed to the shift register in reverse order we can easily change that by changing the bit order in shift out method to list significant bit first let's reload getting closer but still no joy I notice in the AI table that the last bit is always the same zero so it would most likely represent the decimal point but in my circuit setup decimal point should be first not last let's update the AI table and see if this fixes the issue and it does let's uncomment counting routine in Loop function and see if we can count from 0 to 9. how about that so AI came up with a working code I had issues but keep in mind that AI didn't know the exact wiring of my setup if the code was generated first and then based on it the circuit was built I wouldn't have those issues you probably wonder why I did not have a dialog with AI like I had in OLED display case unfortunately I did but with multiple suggestions I was not able to help chat GPT to fix all problems the decimal point 1 seemed like the hurdle it couldn't jump over we completed four challenges and they all finished with success but it doesn't necessarily have to always be that way let me give you a non-aruino example some time ago I asked charge GPT to update me on a cast of one of my favorite polish movies from the 80s it provided the correct list of actors that played in that movie but it got the casting wrong it assigned actors to the wrong roles and also it included one fairly popular polish actor who was not in that movie and it also provided information that that actor passed away in 2017 and he is still alive so that didn't go down well so I'm sure that if I ask chargpt to write a complex Arduino program it might potentially provide faulty results so who knows maybe in the fractal challenge certain sketches that didn't work they didn't work because they were too complex and they couldn't fit into the OLED display maybe it was a bogus code to start with the problem with chat GPT is that very rarely it answers I don't know I don't have enough information most of the times it has some information if that information is not sufficient it mushes it up with some other information which might not be true and provides unreliable information sometimes you may ask artificial intelligence for something and you get this which is exactly what you ask for but other times you get confusing over complicated and sometimes even downright scary respond like this and you never know so is AI going to replace us I don't think that's going to happen anytime soon and on this positive note I am finishing this video thank you to all my patrons especially the new one as always like and share my videos subscribe to my channel if you are not already a subscriber and I will hopefully see you in my next video ciao [Applause] [Music] [Applause]
Info
Channel: Mario's Ideas
Views: 5,465
Rating: undefined out of 5
Keywords: AI, OpenAI, chatGPT, arduino, generated code, fractals, mandelbrot set, koch curve, julia set, tutorial, instructable, oled, 7 segment display, 7 segments, 7-seg, shift register, led chaser, fractal, easy project, how to, adafruit
Id: S6ClV3dWiT4
Channel Id: undefined
Length: 13min 47sec (827 seconds)
Published: Fri Jun 09 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.