The Arduino IDE

 Arduino is a platform that is effective in people just starting out in electronics. The Arduino comes with a development environment that only has the necessary aspects in what the development environment as to do. The dev environment is an innovation on its own, since a designer decided they needed to make it very simple for people who are just starting with electronics without a PhD and to be able to be productive. The environment has made programming with a microcontroller simple to do. The second issue is the USB port. Microcontroller is dependent on hardware, but you can just use your computer with the Arduino and USB, and you can connect your computer just like you can do with any other device. You can just program your Arduino, using a bootloader, which is what you work with to make your life much, much easier as a hobbyist. I want to talk about the Arduino IDE here. 

There are many different ways in which you can program it, using a variety of IDE, adapting the way you program the Arduino with the existing programming tools or the development environment which you are using. We will use the standard arduino environment, which is the version 1.8.13. 



The blink is the equivalent of the hello world program and that is to blink turn the LED on and off. A text editor allows us to put in code, comments, and create multiple files for programs if it contains multiple files, and allows us to debug applications and so on. The Arduino IDE is very simple. Think of the Arduino IDE as an environment that is optimized to program microcontrollers like those that you find in the Arduino, which is by far the best way to get started with the program, and has only the features that you really, really need. Once everything is set, you can upload a sketch from an IDE to the Arduino Uno. 

We are trying to explore a technical solution here and iterate through problems properly, which really is disposable because we upload them to sketch. The verify button is on the top left and the upload button is the button that is second from the left. We can type in instructions and the environment is capable of telling us if we make any mistakes and the environment itself, we don't expose to it other than the messages that flow really quickly inside the black bottom area of the IDE, called the verification stage. This generates an error, and you can debug and find the approximate location in terms of where this error is. 


Now if your program is ready to go, and the Arduino is done compiling, with no error, we can go ahead and upload the sketch. There are also a New button for a new sketch, you can open sketches from different locations, or even default IDE sketches, and the last one is SAVE.

There is another button on the far right, which are text monitors, kind of like a console in Java, for evaluation. This can be very overwhelming for people who are just starting. The system is the exact same situation in regards to starting to operating system.

A big item in the menu is preferences, and you can display line numbers, and the IDE has the numbers for each line, and if you remove it, the lines will disappear. I much rather would work with both lines. 

There is also a '+' function in order to hide what is inside certain setups.


Verify code, mans that when the Arduino IDE uploads the IDE will double check that the sketch was correctly uploaded in its entirety. It compares the IDE on the text editor to what the Arduino has recorded in its memory. An extension has been a .pde extension and now the sketches have changed to .ino. We also need to save safely the current version of the program on the disk. Now we move up the top before returning down to the bottom. The sketchbook location is you can put wherever is convenient in a dropbox directory, or you can synchronize between different computers and store inside of the cloud.

When I go to file -> sketchbook, they exist ask libraries, and if I save a new sketch it will appear in a sketchbook menu through saving it as a sketch folder. It's just one place where the Arduino IDO knows you are saving Arduino sketchbook, and gives you quick access to the file sketchbook menu item, and you can save and load Arduino sketches anywhere you would like in your file system. You can also have a system default, and you can change the editor font size in the preferences. The scale means how big the components of the Arduino IDE is, controlling the size. 2 selections in the bottom involve the information you get in the bottom of the Arduino IDE main window, affecting compiler/compilation/uploading process state. We want all the sompilation information and the upload information output appearing in the black area and I want all of the warnings that the compiler produces during a compilation. The network tab helps you have the Arduino IDE, since they need to have an active internet connection to do some things, and if there is a proxy, you might need to provide the information in the proxy, to provide the Arduino access with the internet. 


You can create a new sketch on the file system and look at examples shipping with the arduino IDE, and you can get to play around with them and get an idea of what. This course works specifically with the Arduino Uno and there are many other Arduinos out there that are both Arduino branded or compatible board, and they all ship with their own example sketches. There are also many examples that show you how to lose a library, and there are code that applies to text of an editor, you can copy from forum, can copy as HTML (good for blogs) in the "edit" tab.


You can also upload a sketch with the programmer through the ICSB headers, and update and export using this programmer compatibility. You can also compile a sketch through "Export compiled Binary" sketch. We're not going to be using this for now. You can also go to "Include Library" in the sketch, edited when the Arduino Library hit version 1.5, and you just now need to know right now that this functionality exists and has a library manager as well. This allows you to select a library by name and You can go to library repositories and find any library that matches this. You can also install a library by copying a zip file that contains it. 

The tools menu has some very useful functionality. Tools -> auto format makes the Arduino IDE move the lines so they go nicely. Archive sketch puts it inside a zip file. Fix encoding and reload is useful if you tend to copy Arduino sketches from websites, and the sketch contains coding that is not compatible with the IDE, or make the compiler not able to read. This fixes most of those problems. The serial monitor is the same function you can access to via the top right button, if the Arduino contains information, you can plot these numbers using the serial plotter. WiFi101 Firmware is for more advanced boards, the Arduino 1010 board. Next down is the board selector in the tools. Similarly with the port, the Arduino IDE needs to know which port it is connected to. In most cases, the IDE should be able to detect both the board and the port, and you can get a board information once you successfully connect a board. The programmer menu tells your Arduino IDE to use a different programmer, but you will be using a USB port to send out a sketch to the Arduino, this programmer is for external hardware. Bootloaders are programs resident on the microcontroller and makes it possible for a sketch to be uploaded from the USB port into the microcontroller. The Arduino IDE ships with the Bootloader, but to get it to the ATMega, you will need an external programmer, and do all the hookup and the wiring and select "Burn Bootloader" and the programmer will assist in storing this resident sketch onto the atmega.


This is something we will do in the advanced course, The windows version is the exact same thing as the apple version and the Linux Version in terms of the user interface. 



Now, we want to try to upload a sketch to the Arduino, and it's time to go ahead and use it to actually program, by connecting the arduino to the computer via the USB and the IDE, load a sketch, and upload it by itself. You need to provide a proper USB cable and the appropriate one should come in a box when you purchase it, or you can just get it on Ebay, and A cable or a B cable. Now we just need to plug in the Arduino to the computer and then connect the other side to the computer and you can see that the power LED is now on, you can see the green LED is on, indicating that there is power. Now the Arduino IDE comes up with a blank editor, as an example sketch. The Arduino IDE comes with a bunch of examples to get started and experiement with teh IDE, and then we go to basics, we see that there are a few small sketches and there is a blink, the classic equivalent of the "Hello World" program. Don't worry too much about the functions, so don't let this confuse you at all. Just make sure that the IDE is ready to upload a sketch to the Arduino, and the Tools is the Arduino/Genuino Uno and in most cases the Arduino IDE will be able to detect the board automatically, and go into the board submenus and find the appropriate type for the arduino and select it. Again go back to same tools, and select teh COM6 port for the Arduino Uno.

This is how to get board info: 


Now we can click on the upload button, and then go to sketch --> upload and here's the result: 


Make sure to show verbose output when compiling and uploading. What happens if you unselect them? There's no compiler feedback and only get very very basic information. I much rather keep them on so I know all the details of the compile process.


Now onto how the Serial moitor does. Serial.begin(9600) tells the arduino tto send the text back to the IDE in the setup() function. Like Serial.println("Off") will be a text message, and pasting things. The idea is that every 1 second, the arduino will send a text message. New sketches will override old sketches. Here's the serial monitor: 


We finally want to update the new sketch to override the old sketch. Every 1 second, the plotter is plotting one of the 2 values specified, either 10 or 0. 

Delay for 1 more second and put intermediate value would make the plot longer, but here's how to do it: 

The remainder will cause me to use the serial monitor a lot, or sensor monitor, and debugging and inserting text messages in various parts of the sketch, and occasionally I may use the plotter to visualize a value from the arduino.

Programming the Arduino is very simple, don't need any special hardware, and we conclude this module here. If you're wondering, here's the code: 

void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  Serial.println(10);
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
  Serial.println(0);
}


Comments

Popular Posts