---
# System prepended metadata

title: Toolchain in arduino
tags: [IB, Computer Science, Arduino]

---

# Toolchain in arduino

###### tags: `IB` `Computer Science` `Arduino`

In this note I'm going to talk about of what happens behind the curtains when you upload the program "blink.ino" into your arduino device. 



## A bit of hardware: The programmer

![](https://i.imgur.com/kQPzeMU.png)

When we talked about CPUs we talked about the main chip in arduino uno. And ATMega328P that we checked out the datasheet before. 

But, of course is no the only element on the board. 


![](https://i.imgur.com/P10gv7N.png)

Here the important one is the USB-TTL Converter

My notes:

- [The Poly Fuse](https://forum.arduino.cc/t/to-clarify-about-polyfuses/191142)

But [here we have a more detailed description for each component](https://circuitdigest.com/article/everything-you-need-to-know-about-arduino-uno-board-hardware)

The important part here is what is called the programmer. 

The programmer is a man-in-between the ATmega328P and the USB. You don't have to program it because it's already programmed to be a programmer and modify the flash memory of the ATmega328P. It's already set. 

The model is an ATMega16U. And of course it has its own 330 pages long datasheet! http://ww1.microchip.com/downloads/en/devicedoc/atmel-8154-8-bit-avr-atmega16a_datasheet.pdf

So physically when you program your arduino to do a blink you don't do it directly. You tell the ATMega16U to overwrite the Flash memory of the big ATmega328P. 

And how do you do it? 

Through serial communication. 

## Serial communication 

(page 150 of the book)

When we think about networks and communication we usually think of The Internet or some bluetooth wireless networking that make your headphones go wild. But the basics can be talked about with wires. 

Here we talked about serial communication between 3 parts. The laptop (PC, linux, mac) that has the USB connection, the programmer (ATMega16) and the main microcontroller of the arduino (ATmega328P). How do we do it?

With some _standards_. In this case USB (Universal Serial Bus). And that standard is a bus. And what is a bus?

![](https://i.imgur.com/7uTRO6Z.png)
_(not that bus)_

A bus is, to put it simple, some wires that go together. In the case of USB they are at least 4 of them. But you can have other buses with more cables. 

![](https://i.imgur.com/PVnw2CO.png)
[_(source and explanation in Spanish_)](https://sites.google.com/site/cuesoportetecnicolsc202aal/home/tipos-de-buses-por-su-uso)

But in our case we only have 4 cables (4 pins). If you check any USB you can see that they have some pins that go through the USB

![](https://i.imgur.com/m8aBIJ4.png)

If you have an USB-C they are a little bit more complicated but they have the pins duplicated so they can fit both ways. 

![](https://i.imgur.com/hcxWGzy.png)
They also have more pins in order to be faster.

But the main idea is that you have a a 4 pins

One is 5 V. It's 5 Volts because the standard for USB says so. It could be 3.3V, it could be 12 V but the standard of USB say that for doing that both parties have to have in common that 5 Volts. 

The other one is 0V, Ground, GND. With that we can have the differential of potential so there can be signals. 

The other 2 are transmitters of data. One goes from A to B, the other goes from B to A.

So we need now another set of rules that we can see in the page 150. 

Here we don't have a timing but we can set it. 



## How to talk to your programmer. Avrdude

