Conclusion Single-board computers have become quite popular in the past decades due to their ability to be used in the development and learning process for beginners.
I like playing with my Arduino Uno board and its graphical development environment. I felt the urge to work closer to the hardware, stepping away from the default library and the Java IDE and using the compiler directly from the command line.
In particular, using C to program the Arduino means usually being able to create smaller programs, and with more fine grained control of what happens. So if you find that Arduino language creates programs that are too big or too slow but you want to squeeze the performance out of your board, or you want a more modular approach, moving to C could be the right choice.
Fortunately all the tools are there, because the Arduino IDE uses them under the hood. In my particular case, since I develop on a Linux machine, Arduino uses the avr-gcc compiler and the avrdude uploading tool.
I can use these tools to develop a program with pure C code, instead of the Arduino language, and upload that program on the board. The Arduino IDE preferences contains verbosity options that have the effect of printing the commands that are run while the program is compiled and uploaded.
We cam mimic this flow, build our program from C calling the avr-gcc command with the right options and upload it running avrdude with the right options.
From C code to Arduino board with avr-gcc To make it simple I implemented the classic blink program that toggles the output pin connected to the on-board LED.
Now we need to write the code that toggles the PB5 pin. The AVR compiler is complemented with a C library: It also makes it easy to write complete C programs without using assembly language. The compiler is able to create an ELF executable program that contain machine code and other information such as program section memory layout and debug information.
Fuses OK avrdude done. The first command line takes the C source file and compiles it into an object file.
The second commands links the object file together with system libraries that are linked implicitly as needed into an ELF program. After the commands are done the code is uploaded and the led starts blinking.
That went well at the first try, mostly due to the fact that the tools have good support for the Arduino. In particular the compilation that builds the ELF program file should be roughly the same, but the upload part could be very different.Get inspired by a variety of tutorials, getting started guides, showcases and pro tips.
Learn Teach Projects Stats Help Us About. Create Sign in. Course Catalog. Projects. Report bug. Help and support. Learn. Teach. Educator Overview.
Elementary School. Middle School Join millions of students and teachers in over countries starting with an Hour of Code. The code you learn to write for Arduino will be very similar to the code you write in any other computer language – all the basic concepts remain the same – it is just a matter of learning a new dialect should you pursue other programming languages.