Now that we have the board files and libraries installed, let’s take a look at the Arduino IDE menu and sketch structure. The first thing to understand are the quick access buttons underneath the main menu.
Quick Access Buttons
They have the following functions:
- Verify – This button is used to compile your code. When you click on Verify, the Arduino IDE will pull code from all the libraries included in your design, combine it with your code, and create an executable file that the Arduino microcontroller can use. If there are any problems during this process, you’ll be notified in the status window at the bottom. Clicking on Verify is a good way to check that your code is syntactically correct and all the libraries it needs are accessible. Hence, it’s a good way to “Verify” your code.
- Upload – This button combines the Verify function and once the code is compiled successfully, it will “Upload” it via the serial port to your microcontroller. This is what we actually want because once it’s uploaded to the microcontroller, we can see the code in action.
- New, Open, and Save – These three buttons are the same as File/New, File/Open, and File/Save. They are shortcuts for these functions and are pretty self explanatory.
- Serial Monitor – Clicking on this button brings up the Serial Monitor window. This is a terminal window which allows you to communicate with the microcontroller via the serial port. For more information regarding the Serial Monitor, we recommend you check out this video from the Build Your Own Datalogger course.
- Status Window – The status window informs you of the status of the operation you’ve selected. If you select Verify, it will inform you of any errors when it tries to build your code. If you select Upload, it will inform you when the code has finished uploading.
Arduino Sketch Code Structure
The next thing is to understand the code structure for Arduino sketches. Arduino sketches are actually written in C++ but a lot of the complexity has been abstracted so that you mainly will be responsible for two blocks of code: setup and loop. The setup code executes once at startup and is used to initialize the system. If you need to set a pin to output and then a HIGH or LOW value, initialize a serial port to a specific speed, or initialize a library, you would do it in the setup block.
The setup block executes once and then control goes to the loop block. The loop block will then execute repeatedly forever. This is where the main functionality of the device comes in. You’ll need to think in terms of that paradigm to understand how to write the code. For example, if you want to turn on an LED when the temperature goes above 30 degrees C, then you would constantly read a temperature sensor and compare it to the threshold value of 30 degrees C. When it goes above that threshold, you can instruct the system to turn on the LED. When it drops below, you can turn it off.
For more information on how to write code for Arduino instruments, we recommend you check out our Build Your Own Datalogger video series.
Now we understand the IDE menu and sketch structure, let’s upload some sketches to our board.