Updated: Apr 29, 2020
The other day I was helping a kid finish off their Titanfall 2 cosplay helmet they made during this quarantine of 2020 with some LED's that would add that finishing touch, activated by a push button.
I decided I wanted the LED's to flash on and off a few times then glow to life with the press of the button.
The second button press would fade them until they were off.
I wrote my first version of that C program which was very basic and just turned the LED's on and off, which is the way I recommend you start coding projects. Go slow, make it simple, then add and make changes one step at a time. This way you can know what works, what doesn't and you will eventually be able to find out WHY something isn't working.
Surprisingly, it had been a while since I had coded an electronic project and similar to speaking a foreign language, you use it or you lose it.
I had to review my favorite book I always recommend because it has all the foundational coding and projects that most other projects need. I suggest you pick it up if you need a book to program Arduino in C or want to program just the Atmega AVR chip on the Arduino in C.
It turned out to be incredibly simple. My code was good. I had all of my include files, my variables and functions were all spelled out correctly. What happened was I forgot one crucial step when saving the code.
Solution: I had not saved my files with a ' .c '
These simple errors will happen to you too, over and over.
Go through the code.
Look through spelling mistakes.
Compare similar working code to your current code that isn't working.
Go through the steps again.
Make sure your wiring is good.
When dealing with complex programming and coding of hardware you must apply Occam's Razor. If nothing is working, start problem solving with the simplest explanations and solutions first. I can tell you from experience that 50% of my problems come from loose connections or bad wires on my breadboard and the other 50% come from small user errors like this one (not saving the file correctly, not including a Makefile, spelling errors, etc.)
Over time, you will develop a sort of checklist for reducing the number of times this happens to you. Notice how I didn't say it will never happen.
Now that you have solved your problem with crtatmega328p.o:(.init9+0x0): undefined reference to “main” Error you are going to need a lot more help from someone who ISN'T an engineer by trade. You need someone who understands how to explain things simply, in layman's terms. You need someone who isn't completely dry and boring. The good news is, I am here to help! I made this site as a free reference for all of the information I wish I had when I first started out.
Let me show you how to understand, code and program electronics and robots in a simpler, easier way using less components, saving more money and still making those amazing dreams you have come to life.