Mar 23, 2017
In this lesson, we're going to do an overview of the Arduino toolchain. The toolchain includes all of the software tools that are between us pressing the Verify/Upload buttons and that code actually getting loaded onto the integrated circuit on the Arduino board.
I definitely want to stress the keyword overview because there is a lot going on behind the scenes that actually makes it happen. In practice for us, though, the entire process is just a matter of pressing a button.
As we start to dig in, it's tempting to want to know every detail. However, remember that our goal in this course is to learn programming and electronics.
If we're not careful, we can get pulled down this huge rabbit hole. That being said, I do think it's important to be familiar with the process.
We don’t need to understand it in depth. I just want you to be able to understand and recognize some of the terms and basic concepts associated with this toolchain.
Specifically, we’ll discuss:
So, what is a toolchain in the first place? In programming, a toolchain is just a series of programming tools that work together in order to complete a task.
If we were cooking something, like carrot soup, the toolchain might include a carrot peeler, a produce knife, a pot, some water, and a stove.
Together, these tools help you create the desired output, carrot soup.
When we're developing programs for Arduino, we'll also be using a toolchain. This all happens behind the scenes. On our end, we literally only have to press a button for the code to get to the board, but it wouldn’t happen without the toolchain.
So, I want to start peeling back the curtain on this Arduino toolchain. Imagine for a moment that you're an author. In fact, you're a New York Times bestselling author... just like me.
What type of toolchain might you use? Maybe you start off with text editing software, just like Microsoft Word, to type your awesome story.
Once you're done with that manuscript, you send it off to a professional editor at a publishing company. That professional editor is part of this toolchain. He will look over your manuscript and point out any errors. He might do some rearranging and other things, as well.
After he sends the suggested edits back to you, you make any necessary corrections. Then, you give the manuscript back to that professional editor to do one last check for errors.
He then hands it off to the office next door at that publishing company. The publishing company can't just take that Microsoft Word file and send it off to a printer. They need a special file type to format the book for how it should look on a physical page when it actually gets printed.
Therefore, they take the manuscript in a Microsoft Word file format, and they turn it into a new file format. Once this is done, the publisher can send it off to be printed.
Luckily, to make the process of printing a whole lot easier, this publisher has an in-house printer. So, he simply needs to just go right down the hall, so to speak. The printer takes that file and prints it onto an actual physical page.
So, let's review this author's toolchain. The author writes with a text editor program. Then, he sends the manuscript to an editor at a publishing company.
That editor reviews the manuscript until it is perfect. He then sends it next door to be formatted.
The manuscript is converted into the proper file format, and it is sent off to the printer to create the physical book. Finally, voilà, somebody buys your book from Amazon to read all about zombies over a warm cup of latte.
Why did I go through that long scenario? Well, the Arduino has a similar toolchain. When we start writing our code, and we become the author.
We do this in the Arduino IDE, which is akin to a text editor. We also write the code in a programming language called C++, with a file type extension of .ino.
The code that we write is called human readable code since it's meant for us to read and, hopefully, understand. However, the Arduino hardware doesn't understand C++ code.
It needs what's called machine code. In order to generate that machine code, we use a software tool called a compiler.
Remember that Verify button in the Arduino IDE that looks like the checkmark?
When you press this button, it compiles the code using compiler software called AVR-GCC. This compiler software does a bunch of stuff.
The main thing it does it rearrange some code and check for errors. This is like the professional editor at the publishing company.
The compiler also translates the human readable code into machine code. There are some in-between file types and other fuzzy things that go on, but the final output of the compiler is a machine language saved as a .hex file.
In order to get this .hex file loaded onto our Arduino's integrated circuit, we need to press the Upload button.
This begins another piece of software called AVRDUDE, which sends the file to the integrated circuit.
Normally, we would have to use some external hardware to load that circuit. However, in Arduino’s infinite wisdom, they loaded a small piece of software onto the integrated circuit that automatically comes with an Arduino board.
That piece of software is called a bootloader. It works with ARVDUDE to take the outputted .hex file and put it onto the flash memory of that Arduino's integrated circuit using only the USB cable.
Again, all we had to do was press the Upload button. This whole process happens behind the scenes.
Now the process is complete. So, what was our toolchain?
We have the Arduino IDE Editor. Then, we have the compiler, which is AVR-GCC. The result is a .hex file.
Next, we have AVRDUDE and the bootloader on the integrated circuit of the Arduino board. These work together to upload the .hex file to the board.
That was a lot of information to absorb. Let’s summarize what we learned in this lesson.
First, we learned that in programming, a toolchain is simply a group of software tools used to complete a task. Then we discussed the book publishing analogy to help illustrate that point.
Lastly, we walked through the Arduino toolchain. As an encore, we’ll go over that toolchain one more time.
We start by writing human-readable C++ code in the Arduino IDE Editor. Then, we click Verify.
The compiler program, called AVR-GCC, checks the code for error and adjusts some of the code for us. The result is machine code in a .hex file.
When we press the Upload button, AVRDUDE takes that .hex file and works with the bootloader. The bootloader is pre-installed on the Arduino's integrated circuit, and it helps get the machine code loaded onto the Arduino's integrated circuit.
Wow, I'm so glad that all happens behind the scenes! Again, this was meant only to be a cursory overview.
I wanted to make sure that if you see AVR-GCC in error message or hear the word compiler or any of the other jargon we discussed here, at least you now have an idea of their significance. You now know where they are in the Arduino toolchain.