Hey guys! I have been relying on chatGPT for code a while now, and sometimes he messes up.... a lot.... any recommendations to where I should go?
Try your local university. There are also on line courses. Here is one I like: https://www.youtube.com/watch?v=GQp1zzTwrIg
This will not be a weekend project.
The way you learn how to write software is by writing software.
- Look at this post.
If there are topics at a higher level than you are right now, go on to those that are less involved.
Hardware
- Schematic diagrams are the universal language of electronics.
- We use schematics to communicate hardware design. All components and connections are illustrated.
- As always, show us a good schematic of your proposed circuit. Hand drawn schematics are acceptable.
- Show us several good image views of your actual wiring.
Suggestions of things you need to master
-
Always start a project with a circuit schematic showing all the components and their interconnections.
-
Code “must” be written in a non blocking fashion.
-
To keep code organized and easy to follow, the State Machine technique needs to be adhered to.
-
Using HIGH or LOW does not explain what is happening, use names like: LEDon, RELAYon, ENABLED, CLOSED etc.
-
Avoid magic numbers. Use names that describe the value.
Instead of: 60ul * 1000, use sixtySecInterval. -
Let the compiler do the math for you, for 15 minutes,
instead of 900000 use 15ul * 60 * 1000 -
Keep version backups so you can always go back to the last working version.
-
Do not use delay(…) as it will stop code execution during this delay interval.
-
Avoid using while( ) if there is any chance it significantly blocks normal code execution.
-
Use non blocking TIMERs based on the millis() or micros() functions.
-
Write your code in a neat easy to read style, use white space, add meaningful comments throughout.
-
Use the Arduino onboard LED on pin 13 as a heartbeat LED to show code is running and code is not stuttering.
-
For mechanical switches avoid looking at digital input levels, instead, look at digital input “changes in state”.
-
Place braces, { and }, on separate lines so they don’t get lost in the other text.
-
Use one code statement per line.
-
LEDs displaying the current state in a State Machine, can be used to diagnose problems.
-
For diagnosing problems, use serial monitor print statements to confirm variables are what you think they are.
-
Write only small blocks of code at a time. Prove the new code block works 100% before proceeding.
Make this commitment to yourself.
- Before wiring and turning on the power to a circuit, I will always draw a schematic showing how I will connect the components in my project; this schematic is exactly how I will wire things.
- I will double check that power connections are correct.
- I will always use a series resistor of 220Ω on both Inputs and Outputs to protect my controller’s GPIO pins from my blunders.
- I will never re-wire a circuit when power is applied.
learn to code arduino fast?
Quickly learn to code arduino?
Learn to code quicly?
Learn to code arduino to run something faster?
It depends on how much you want to learn. Nobody knows everything about all of the Arduino's and all of the additional-optional libraries.
Asking chatGTP (or another person) to write a program for you isn't usually a good way to learn.
...And if there's a bug it's usually harder to fix someone else's code that you don't fully understand. It's usually easier to start-over and do it yourself.
I assume the problem with chatGTP is that it doesn't (yet) understand schematics. And of course, you need to describe EXACTLY how you want your program to behave. Accurately describing/defining the program can be a major task and you might need to include a lot of detail.
And the Arduino (and any additional hardware) has to be capable of doing what you ask.
The Arduino is one of the easiest ways to get started with programming and it doesn't take long to get a handle on the "basic" Arduino Lanuage.
But with the Arduino you generally need to know at-least some electronics.
Whenever you do a new project, you'll probably have to do some research, including studying whatever additional hardware you're using.
Most books & tutorials (and some classes) teach the programming language and skip-over the basic concepts of what programming is all about. I was pretty-lost when I took my 1st programming class, although it didn't seem "hard".
Note that it's different from standard C/C++. If you open a regular C or C++ book the 1st example will be "Hello World" which won't run on an Arduino because there is no standard display. Standard C/C++ expects a standard keyboard, display, and file storage and operating system.
You can add a display or keyboard, etc., to the Arduino, but usually they are not "standardized" to work with standard C/C++. On a regular computer all of that stuff goes through drivers and the operating system.
And, standard C/C++ doesn't have analogWrite() or any way of reading a button or turning-on an LED. These are special Arduino functions.
With the Arduino, "Blink" is the equivalent of "Hello World", and of course "Blink" won't run on your computer... It only runs on the Arduino.
Windows/GUI programming also goes beyond ANSI/ISO C or C++. The mouse, graphics, and even color, requires additional libraries.
If you major in electronics you wouldn't study microprocessors/microcontrollers until the 3rd or 4th year. If you major in computer science you might not study them at all or it might be an elective.
Another free way to learn is to find forum posts from people asking for help with their program. Download their program to your PC and work with it to fix their problem.
Learn from other peoples mistakes - you don't have time to make them all yourself.
I used to tell students the quickest way to learn to program is to write programs
You should apply your first rule…
constexpr unsigned long oneSecond = 1000; // 1000 ms in one second
constexpr unsigned long oneMinute = 60 * oneSecond;
constexpr unsigned long oneHour = 60 * oneMinute;
constexpr unsigned long oneDay = 24 * oneHour;
You probably mean one expression (you don’t want a compound statement {…} on one line as per your previous rule)