How to upload a sketch with the Arduino IDE 2
Learn the basics of verifying and uploading sketches with the new IDE 2.
How to Upload a Sketch with the Arduino IDE 2
In the Arduino environment, we write sketches that can be uploaded to Arduino boards. In this tutorial, we will go through how to select a board connected to your computer, and how to upload a sketch to that board, using the Arduino IDE 2.
You can easily download the editor from the Arduino Software page.
You can also follow the downloading and installing the Arduino IDE 2 tutorial for more detailed guide on how to install the editor.
- Arduino IDE 2 installed.
Verify VS Upload
There are two main tools when uploading a sketch to a board: verify and upload. The verify tool simply goes through your sketch, checks for errors and compiles it. The upload tool does the same, but when it finishes compiling the code, it also uploads it to the board.
A good practice is to use the verifying tool before attempting to upload anything. This is a quick way of spotting any errors in your code, so you can fix them before actually uploading the code.
Uploading a Sketch
Uploading a sketch is quick and easy, but let's take a look at what we need to do.
1. Open the Arduino IDE 2.
2. With the editor open, let's take a look at the toolbar at the top. At the very left, there is a checkmark and an arrow pointing right. The checkmark is used to verify, and the arrow is used to upload.
3. But before doing any of that, we should choose what board we are uploading to. Beside the verify and upload button you should see a a drop down menu, this will, in most cases, display Arduino boards that are connected to your computer. If your board is not automatically detected, you can either press "Select other board and port..." in the drop-down and follow the instructions, or go to Tools > Board and Tools > Port in the toolbar menu to select the board and port manually.
So connect your board to the computer and select it from the drop down menu. You'll know that there is a connection to the board when the board name appears in bold.
4. Click on the verify tool (checkmark). Since we are verifying an empty sketch, we can be sure it is going to compile. After a few seconds, we can see the result of the action in the console (black box in the bottom).
5. With the board selected, we are good to go! Click on the upload button, and it will start uploading the sketch to the board.
6. When it is finished, a notification pops up in the bottom right of your IDE window. Of course, sometimes there are some complications when uploading, and these errors will be listed here as well.
Congratulations, you have now uploaded a sketch to your Arduino board!
Please Read (Only Linux Users)
It might happen that when you upload a sketch - after you have selected your board and the serial port - you get an error such as "... Permission denied". If you get this error, you need to set serial port permission.
To do this, open your Terminal and type:
1ls -l /dev/ttyACM*
you will get something like:
1crw-rw---- 1 root dialout 188, 0 5 apr 23.01 ttyACM0
The "0" at the end of ACM might be a different number, or multiple entries might be returned. The data we need is "dialout" (is the group owner of the file).
Now we just need to add our user to the group:
1sudo usermod -a -G dialout <username>
is your Linux user name. You will need to log out and log in again for this change to take effect.
After this procedure, you should be able to proceed normally and upload the sketch to your board or use the Serial Monitor.
The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.