ChatGPT is like the coolest thing ever! It can teach you anything and solve any problem. Let’s see how it can help us write some simple code to make our OSOYOO V2.1 Robot Car move. We’ll compare the code ChatGPT gives us with the code from our Lesson 1 and see if there are any differences.
To use ChatGPT as a beginner, you don’t need to pay anything to chatGPT, you don’t even to have a ChatGPT account either. Simply go to https://chatgpt.com/ , then input your question (prompt) in the text field and click ⇧ button to submit them to the ChatGPT.
The design of a prompt is quite sophisticated. Generally speaking, the more specific your prompt is, the more accurate ChatGPT’s response will be. Take Lesson 1 project for example, you can input your first prompt to ChatGPT as following:
“Please provide me with a piece of code that allows my OSOYOO V2.1 robot car to move forward for 1 second, backward for 1 second, turn right for 1 second, turn left for 1 second, and then stop,”..
The code generated by ChatGPT is quite odd. It’s a Python script that simply won’t run on an Arduino. The reason is that our prompt was too broad. ChatGPT didn’t know the specific hardware you were using for your robot or how it was connected, so it generated code for a Raspberry Pi-based robot based on its understanding. If you provide ChatGPT with more specific details about your hardware setup in the prompt, you’ll get much better code. For instance, you could modify your prompt to say:
I have an OSOYOO V2.1 robot car, the right two motors are connected to Model X board K1 K2 port,the left two wheels are connected to K3/K4 port. Model X ENA connects to D9, IN1 connects to D12, IN2 connects to D11, IN3 connects to D7, IN4 connects to D8, ENB connects to D6, please write Arduino code, make the car move forward for 1 second, then move backward for one second, then turn right for one second , then turn left for one second and then stop.
After you submit above prompt to ChatGPT, you will get some code as following:
// Pin assignments for motor driver connections #define ENA 9 // ENA connected to D9 #define IN1 12 // IN1 connected to D12 #define IN2 11 // IN2 connected to D11 #define IN3 7 // IN3 connected to D7 #define IN4 8 // IN4 connected to D8 #define ENB 6 // ENB connected to D6 void setup() { // Set all motor control pins as outputs pinMode(ENA, OUTPUT); pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT); pinMode(IN3, OUTPUT); pinMode(IN4, OUTPUT); pinMode(ENB, OUTPUT); // Enable the motors digitalWrite(ENA, HIGH); digitalWrite(ENB, HIGH); } void loop() { // Move forward for 1 second moveForward(); delay(1000); // Move backward for 1 second moveBackward(); delay(1000); // Turn right for 1 second turnRight(); delay(1000); // Turn left for 1 second turnLeft(); delay(1000); // Stop the car stopCar(); delay(1000); // Optional: a short delay before the sequence repeats, can be adjusted or removed } // Function to move forward void moveForward() { digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW); digitalWr
The actual code generated by your chatGPT might be slightly different from above, you can compare them to the lesson 1 code and test the running result.
DownLoad Url osoyoo.com