# Starting with Arduino. Installing and first blink ###### tags: `IB` `Computer Science` `Arduino` [ToC] ## What is this about Since Computer Science is about _thinking_ we're going to see how an arduino thinks and let's try to see if it works. The menu is as follows * I give you this brief explanation * You install the software to talk to arduino * We test an example called "blink" * We explain a little further * We do more examples about functions (in other pages) The final project here that we're going to do together (probably not in the same day) is a program that converts a text message into morse code. ## So what's an arduino In brief we can say **Arduino is a easy-to-program microcontroller board**. But if we dig up a bit, Arduino can stand for 6 different things and we're going to refer mainly to 2 of them. These things can be: - Arduino the physical microcontroller that you have. "My arduino doesn't work" usually is refering to this part. There are several models and the most common and easy to use is arduino uno r3. (but we can finde arduino nano, micro, leonardo, etc) ![](https://i.imgur.com/JQObLhb.png) - Arduino the architecture of that hardware and their specifications. ![](https://i.imgur.com/9EIFf3z.png) - Arduino IDE (IDE means Integrated Development Enviroment, we'll get to that later). The software that can program the microcontroller (and other microcontrollers!). We are going to use Arduino IDE to program arduino but we could use other IDEs with the proper plugins. ![](https://i.imgur.com/GjDMUOi.png) - Arduino the toolchain. This is the list of things that has to do the Arduino IDE (or other program) to upload our code into the Arduino. ![](https://i.imgur.com/CI6YCl0.png) - Arduino the company. ![](https://i.imgur.com/OEt6Efy.png) - Arduino the library of C++ that we need to use commands like "digitalWrite()". By default the program language C++ doesn't have the tools to interact and use the commands that an arduino has. There is a library that handles that (put by default by Arduino IDE so we don't have to worry about it) ![](https://i.imgur.com/0BCLyoH.png) We usually are going to refer to Arduino as the **Arduino IDE** and the **Arduino the hardware**. So if it's so *easy to program* let's try to do something with it! ## Start downloading Arduino IDE So you should have your arduinos by now. To talk to them you will need arduino software. It can be online or downloaded. I recommend to download it at least in Windows OS. https://www.arduino.cc/en/software There are 2 options to download. The 2 should be fine and work. But the 1.8.19 (the old one) has more support and more help that you can find easily. If you're in doubt, choose this one. ![](https://i.imgur.com/DpcYOTl.png) You don't have to contribute. You can "just download" ![](https://i.imgur.com/makcRrj.png) Once you have it downloaded you open the installer: ![](https://i.imgur.com/8j3CCEk.png) If windows says something like "do you allow Arduino to make changes in the system?" you say yes. ![](https://i.imgur.com/xV6snhL.png) Here you say that you agree to the EULA (End User License Agreeement) ![](https://i.imgur.com/PnDvinj.png) You can uncheck the dekstop if you don't like it but I suggest to keep the start meno shorcut. *Please, install the USB driver and associate .ino files* ![](https://i.imgur.com/Amc5nbK.png) You can change the place where you install this package and check if you have enough space. Then you clic install. ![](https://i.imgur.com/PeHMBTv.png) Then you open it up from the Start (you can look for it or write "Arduino" and windows will find it) ![](https://i.imgur.com/1Eddy4H.png) If it opens this, you're done installing! ### Variant of version 2.0.0 rc9.2 In the website there is also the option to download the _new_ version of Arduino IDE. Version 2.0 ![](https://i.imgur.com/q0CQmR5.png) This is not a stable version (yet) but it's moving to do it. That's why is an "RC", "release candidate". There have been other Released Candidate versions before each of them with less bugs and more stable than the former. ![](https://i.imgur.com/iPQrGxx.png) To install we use the same process as in 1.8. If you're confused by the windows that are slighlty different, you should keep with the 1.8 version. It may ask you for permissions like these: ![](https://i.imgur.com/OgeMph7.png) ![](https://i.imgur.com/wfqnWwJ.png) You have to allow it. If you're done you should have this window: ![](https://i.imgur.com/49a3DBh.png) ## Load (and modify) the first program If you don't have the Blink program, you can easily load it using the menus: File -> examples -> 0.1 Basics -> Blink ![](https://i.imgur.com/HhhJ7gj.png) It will open a new window with that program. You might close te former window if you want. ## The first program it's already loaded in the IDE! Ok, so now let's try to program our arduinos to check if the hardware and the software is ok. ## Change the Blink program If you plug your arduinos out of the box they seem to have preinstalled the "Blink" program. You should check what happens if you plug the arduino with the USB. There is a small led that is blinking. That's why we're going to use a modified version of the program. To change this we're going to tweak a bit the default blink program. In the part that says "void loop(){}" we're going to put this code in the brackets ```C++ digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) delay(100); // wait for a tenth of a second digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW delay(100); // wait for a tenth of a second ``` This chunk of lines that you copy and paste is called a **snippet** of code. We're substituting the 1000 in the delays for 100. Then we have to set up the correct port once the arduino is pluged in to the computer we're using. To do that we go to the menu tools -> port and we select the one that says "Arduino Uno" ![](https://i.imgur.com/hkXac7G.png) It can be COM1, COM3, COM4 depending on the circunstances. Then we have 2 buttons that we have to know in arduino. The button "compile" and the button "upload" ### The verify button ![](https://i.imgur.com/z0TpVL6.png) The button verify is just a check that saves the file and runs the compiler, checking any problems with the syntax of the program. Something like writing "digitalwrite" instead of "digitalWrite" is a common mistake detected by this since C++ is case sensitive (the good one is "digitalWrite"). **This button doesn't interface with the arduino board** ### The upload button ![](https://i.imgur.com/fDcAGif.png) This button first compiles the program and then attempts to upload it using the the full toolchain. **We need to press this button in order to make the program work in the arduino board.** Once we press it it's going to do stuff in the bottom part of the window. If everything goes well you should have something like this that says "Subido" or "Uploaded": ![](https://i.imgur.com/fFn1XEV.png) ### Common errors In the bottom screen you might see some errors. Here you can find some of the basics that you can find today. **"Expected something"** ![](https://i.imgur.com/Hmd1IhM.png) It usually means that you missed a semicolon or a bracket or a parenthesis. You can check in what line is the error and change it. Here in the last delay there is no semicolon. **"Somehting was not declared in the scope"** ![](https://i.imgur.com/deJYyk8.png) Usually it means that you misspelled something. Be aware of the upper and lower case that you have to use. You can check in what line is the error and change it. Here I wrote "digitalwrite" instead of "digitalWrite" (also it changed the color) **"Problem uploading to board"** ![](https://i.imgur.com/KYlwiCe.png) It usually means that either your arduino is not connected or maybe you didn't defined the port properly. Check both things. ## Try to tweak it by yourself! Change the values and I'll explain on the board what is happening in this simple program. ### Next step: Coding Morse Code. https://hackmd.io/2OLbqEc6SnuhkR-RcrGRDA ## References: Class of Fabacademy 2022 on embedded programming https://vimeo.com/689983001