Program the ARM Microcontroller Using ChatGPT: Trial1 #newbiehack #stm32 #chatgpt

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone what would happen if I used chat gbt to help me program the microcontroller in this new series of videos I want to see if chat GPT can help me program the microcontroller and I'm going to go a little bit more complex on each video will I run into challenges along the way this is actually a good way to determine the state-of-the-art of chat GPT and its ability to provide code for the microcontroller in this series I'll be using a GPT that I created that contains the entire reference manual for this particular microcontroller that I'm going to be using and by the way if you think you need the Raspberry Pi or an Arduino to do microcontroller projects you don't you can just use this tiny little chip and start from there and then build up from this chip will the GPT be able to create more complex programs what's the worst that could happen I mean I'm only taking code from chat GPT and putting it onto a microcontroller it's not like chat GPT is smart enough to do anything nefarious okay let's get started you can find my stm32 f030 GPT at this link I'll put the link in the description I'm going to write a simple prompt that only contains the information that's needed for the success of the project we'll need to determine what pin we're going to use on the microcontroller so let's go to nubie hack.com and let's let take a look at the board and see what pin we want to use this diagram on nihack.com allows you to see how the micr controller pins are broken out hovering over the board and the pins you can see what functions each pin has let's go ahead and select the port a pin one in the output chat GPT gives a highlevel description of the code the initialization of the pin and the main Loop that is also referred to as the never-ending Loop or the Loop that runs until the microcontroller is turned off the explanation below the code is more detailed and explains the purpose of the delay to provide the time between the toggling of the led the configuration of the pin and how the pin is toggled in the main Loop I'm going to copy this code to the clipboard and startup STM Cube IDE the integrated development environment for STM microcontrollers I explain this IDE in more depth in my book and in the previous videos I'll leave a link to both of these in the description I'm going to create a new stm32 project this will add all of the libraries that we'll need make sure to select the correct microcontroller from the list by typing in the part number and selecting it from the list press the next at the bottom of the dialogue box when you have finished selecting this will bring you to the project dialogue where you'll need to provide the project name you can select either C or C++ for this project but keep the binary and project type as default after you click finish the IDE will present the chip and pin designations this is part of the cube MX from St micro we will exit this since chat GPT is providing all of the code and initialization for us under the core and SRC folder you will find the main.c file which is where we will insert the copied code from chat GPT double click on the main.c and remove all of the boilerplate code in that file we won't need this let's briefly go over what this code is doing you can find more detailed information and explanations of this in my book this line is simply enabling the gpio general purpose input and output for Port A in this line we're setting the mode for output for pin one of Port A as opposed to input since we are outputting a voltage to an LED this line is setting the type for the pin as Push Pull and not open drain this is a very powerful feature of microcontroller pins enabling flexibility for different Power approaches related to transistor Theory but but that is way outside of this example so I'll leave that alone since we're slowly blinking the LED to relate to the human eye we only need to set this to low and this also saves power if you are wondering the last initialization for the pin is adding no pullup or pull down internal resistor within the NeverEnding Loop the LED or pin we're selecting for output is toggled using this logic operator a call to the delay is added just after the toggling of the LED so we humans can tell it's blinking the function for the delay is just a loop that wastes time using a timer and interrupt to do this is better because it doesn't tie up the microcontroller you can read more about this in my book if you're interested which brings me to the sponsor of this video I wouldn't be able to make these videos without the sales of my book and the kits on nub hack.com the book will prepare you for entry into the world of programming and basic circuit building for our microcontrollers the kits on the website provide the components you'll need for the successful building and programming of arm microcontroller projects the implementation of arm microcontrollers is vast from robotics to Home Appliances to complex Aerospace Systems starting from the bare chip will accelerate your way to making efficient products or working for well-known companies that use these microcontrollers in their products let's add the components to the Circuit we will need an LED and a 330 ohm resistor these will be inserted into the tie strip that connects to pin 15 which is pin pa1 make sure to orient the LED so that the flat is towards the negative rail if you are new to this channel you'll need to know how to program the market controller using the stlink V2 you'll also notice that there are a bunch of red hookup wire and filter capacitors on the breadboard to tie all of the Power pins together to get more information on this see the links in the description or get the book for more details now let's see if chat GPT produced a working program and the output is as we expected let's plug in the St link to the computer press the Run button and okay the launch configuration properties the output window will show you the status of the connection with the market controller and if the download to the market controller was successful if it was successful the green LED should blink like you see here and looks like it works chat GPT was successful in making a simple program on the arm microcontroller now let's ask GPT to give us the code using the Hal Library the Hal library is a library that abstracts the hardware Hardware abstraction layer h from the code so that the same program can work on a variety of arm microcontrollers you can see that the program is generally the same initializing the pin and the port toggling the pin in the never- ending Loop but the main difference is the built-in delay function which is very convenient I did rearrange the program a little from the output of chap GPT there was no need for the initialization to be in a separate function and the system clock config is unnecessary for the blinking LED now the microcontroller can be programmed with this new code let's plug it in download the program to the micr controller and see if it [Music] works again chbt successfully created a program for the stm32 microcontroller in the next video let's get a bit more complex spoiler alert the program's intent is quite simple but the implementation can easily trip up chat GPT I want to thank all of the patreon members and customers that have purchased the book and kits on nub hack.com I'll be adding the names of all of my paid members on my desk I also want to thank xtool for letting me show off their P2 laser I'm using the X tool open plane feature so that I can slide my desk underneath the laser to engrave the patreon members onto the desk this video will appear on my patreon account and in the membership section of this channel one week before making it publicly available so consider becoming a patreon member or a member of this channel to see the videos ahead of time and to support the production of these videos thank you for watching [Music]
Info
Channel: BuildYourCNC
Views: 4,921
Rating: undefined out of 5
Keywords: arm microcontroller tutorial, embedded systems tutorial for beginners, arduino tutorial, arm programming tutorial, embedded systems projects
Id: qt6pnNlAqN4
Channel Id: undefined
Length: 8min 28sec (508 seconds)
Published: Thu Jan 18 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.