Changes

no edit summary
Line 68: Line 68:  
<youtube>64oEr1zTlOg</youtube>
 
<youtube>64oEr1zTlOg</youtube>
   −
== Arduino IDE and internal Libraries ==
+
== Arduino IDE and Tools ==
    
===Arduino IDE:===
 
===Arduino IDE:===
Line 78: Line 78:  
[[File:Arduino IDE2.jpg|930x930px]]
 
[[File:Arduino IDE2.jpg|930x930px]]
   −
===Blink program:===
+
=== Internal Libraries ===
The Arduino IDE provides creators with a plethora of written programs that are fully ready to run on an Arduino board. They are located in the Files>Examples folder. Amongst the most basic is the "Blink" program, which can be used to not only get to know the basic features in the software and the hardware, but are also a great way to test the connectivity between the Arduino board and the user's computer. This program is located in Files>Examples>01.Basics>Blink.  
+
 
 +
==== What is a library? ====
 +
A library is a file that contains pre-written code that can be referred to in order to use certain sensors and functions. Often, in order to complete a task like connecting to a server to spinning a motor many lines of code must be written and executed. Libraries are bits of code that users can refer to in order to complete those tasks without having to type out each line of code, it simplifies the programming process and allows us to perform relatively complex tasks with ease.
 +
 
 +
 
 +
In this module we won’t be using complex or external libraries! But keep this in mind for the following ones as this will be necessary later on.
 +
 
 +
==== Built-in Libraries ====
 +
Built-in libraries are ones that come preinstalled into the Arduino IDE, you don’t need to import the library into the IDE. An example of this type of library is the math.h library, which is used for most basic math operations.
 +
 
 +
 
 +
''<u>Where to find them?</u>''
 +
 
 +
There are a few ways to looks for what built-in libraries are available, you can do a quick search in different online Arduino forums, or the easiest way is to look at the library manager in the Arduino IDE. This window displays libraries that are already installed and you also have the ability to install libraries that would would like.
   −
The following provides an overview of the different functions used in this program:
  −
[[File:Blink program overview.jpg|center|frameless|800x800px]]
  −
{| class="wikitable"
  −
|+Table 2: Overview of functions used in the Blink program
  −
!Function
  −
!Description
  −
|-
  −
|Setup()
  −
|Performs any actions that are initially required to run the rest of the program, such as initializing any peripheral components and setting the communication frequency between the Arduino and the PC.
  −
|-
  −
|Loop()
  −
|The loop function acts as the program's driver, it runs on a continuous loop and specifies the order of operation the microcontroller will perform. Execution starts at the top, goes through the contents of the loop and then starts executing from the top again. This procedure is repeated forever.
  −
|-
  −
|pinMode (pin number, INPUT or Output)
  −
|Configures the pin to behave as either an INPUT or an OUTPUT.
  −
|-
  −
|digitalWrite (pin number, HIGH or LOW)
  −
|Writes a HIGH or LOW value to a digital pin. If the pin has been configured as an OUTPUT, then the signal sent over (ie the voltage) will be set as 5 V (HIGH), or 0 V (LOW). For 3.3 V output boards, the high value will be set to 3.3 V, whereas the low is the same as the 5V board, which is 0V.
  −
|-
  −
|Delay (time in milliseconds)
  −
|Pauses the program for the amount of time specified in the parameter.
  −
|}
     −
=== Initializing a Pin as an Input or Output ===
+
As seen below, in the menu bar at the top of the window click on ''Tools > Manage Libraries...'' [[File:Library Dropdown.jpg|none|thumb|627x627px]]Inside the manager as seen below you are able to select the type of library you are looking for, for example, installed, arduino and etc.[[File:Manage libraries.png|thumb|alt=|none|783x783px]]
When using components you will often have to initialize the pin they are connected to as either an input or output! The syntax for this will vary depending on the component and what pin type it is connected to.  
     −
==== Analog Input/output ====
  −
When trying to manipulate data from an analog pin, the following lines of code are used to read data from it:
  −
int ''variable'' = analogRead(''insert pin number''); //here a variable is being defined to hold the value read from the pin
  −
When you want to write data to the pin the following syntax is used:
  −
int ''variable'' = analogWrite(''insert pin number''); //here a variable is being defined to hold the value read from the pin
     −
==== Digital Input/output ====
+
When wanting to use a library, one must declare it at the top of their code so that their IDE knows that that file is being referred to, the syntax is:
When wanting to use a digital pin you will need to declare as either an input or output in the Void Setup () as follows:
+
  #include<math.h>
pinMode(LED1, OUTPUT); //For example if you had a pin called LED1
  −
When wanting to write a value to LED1 then you would use the following syntax:
  −
  digitalWrite(LED1, HIGH); //Here HIGH or LOW would indicate if you would like the led to turn on - for turning it on you set HIGH, and LOW otherwise.
      
=== Serial Monitors ===
 
=== Serial Monitors ===
Line 152: Line 134:  
<youtube>f1z-1Db2IAI</youtube>
 
<youtube>f1z-1Db2IAI</youtube>
   −
== Introduction Libraries ==
+
==Introduction to Programming Syntax and Conceptualization==
 +
As mentioned previously, and IDE is used to compile and execute the code utilized in a microcontroller. There are many different IDEs that can be used for various types of microcontroller and for each purpose there are more suitable boards that can be used. In order to program an Arduino, one must have the Arduino IDE downloaded (Refer to '''Connecting an Arduino'''). The Arduino IDE provides users with a programming editor as well as a way to easily upload and compile programs onto the Arduino board. Programs in the Arduino IDE are called sketches, and are normally saved with the .ino extension. The language used to program the Arduino board is based on the C++ language, which is a general use Object Oriented language. Like any common language, in order to start coding, one must be aware of the grammar rules and vocabulary that is used. An important word that will be often encountered is a “function”, which is a block of code that takes in an input, processes the input, then returns an output.
   −
==== What is a library? ====
+
=== Blink program: An Example ===
A library is a file that contains pre-written code that can be referred to in order to use certain sensors and functions. Often, in order to complete a task like connecting to a server to spinning a motor many lines of code must be written and executed. Libraries are bits of code that users can refer to in order to complete those tasks without having to type out each line of code, it simplifies the programming process and allows us to perform relatively complex tasks with ease.
+
The Arduino IDE provides creators with a plethora of written programs that are fully ready to run on an Arduino board. They are located in the Files>Examples folder. Amongst the most basic is the "Blink" program, which can be used to not only get to know the basic features in the software and the hardware, but are also a great way to test the connectivity between the Arduino board and the user's computer. This program is located in Files>Examples>01.Basics>Blink.  
    +
The following provides an overview of the different functions used in this program:
 +
[[File:Blink program overview.jpg|center|frameless|800x800px]]
 +
{| class="wikitable"
 +
|+Table 2: Overview of functions used in the Blink program
 +
!Function
 +
!Description
 +
|-
 +
|Setup()
 +
|Performs any actions that are initially required to run the rest of the program, such as initializing any peripheral components and setting the communication frequency between the Arduino and the PC.
 +
|-
 +
|Loop()
 +
|The loop function acts as the program's driver, it runs on a continuous loop and specifies the order of operation the microcontroller will perform. Execution starts at the top, goes through the contents of the loop and then starts executing from the top again. This procedure is repeated forever.
 +
|-
 +
|pinMode (pin number, INPUT or Output)
 +
|Configures the pin to behave as either an INPUT or an OUTPUT.
 +
|-
 +
|digitalWrite (pin number, HIGH or LOW)
 +
|Writes a HIGH or LOW value to a digital pin. If the pin has been configured as an OUTPUT, then the signal sent over (ie the voltage) will be set as 5 V (HIGH), or 0 V (LOW). For 3.3 V output boards, the high value will be set to 3.3 V, whereas the low is the same as the 5V board, which is 0V.
 +
|-
 +
|Delay (time in milliseconds)
 +
|Pauses the program for the amount of time specified in the parameter.
 +
|}
   −
In this module we won’t be using complex or external libraries! But keep this in mind for the following ones as this will be necessary later on.
+
=== Initializing a Pin as an Input or Output ===
 +
When using components you will often have to initialize the pin they are connected to as either an input or output! The syntax for this will vary depending on the component and what pin type it is connected to.  
   −
==== Built-in Libraries ====
+
==== Analog Input/output ====
Built-in libraries are ones that come preinstalled into the Arduino IDE, you don’t need to import the library into the IDE. An example of this type of library is the math.h library, which is used for most basic math operations.
+
When trying to manipulate data from an analog pin, the following lines of code are used to read data from it:
 +
int ''variable'' = analogRead(''insert pin number''); //here a variable is being defined to hold the value read from the pin
 +
When you want to write data to the pin the following syntax is used:
 +
int ''variable'' = analogWrite(''insert pin number''); //here a variable is being defined to hold the value read from the pin
    +
==== Digital Input/output ====
 +
When wanting to use a digital pin you will need to declare as either an input or output in the Void Setup () as follows:
 +
pinMode(LED1, OUTPUT); //For example if you had a pin called LED1
 +
When wanting to write a value to LED1 then you would use the following syntax:
 +
digitalWrite(LED1, HIGH); //Here HIGH or LOW would indicate if you would like the led to turn on - for turning it on you set HIGH, and LOW otherwise.
   −
''<u>Where to find them?</u>''
+
====== Some other basic considerations: ======
 
  −
There are a few ways to looks for what built-in libraries are available, you can do a quick search in different online Arduino forums, or the easiest way is to look at the library manager in the Arduino IDE. This window displays libraries that are already installed and you also have the ability to install libraries that would would like.
  −
 
  −
 
  −
As seen below, in the menu bar at the top of the window click on ''Tools > Manage Libraries...'' [[File:Library Dropdown.jpg|none|thumb|627x627px]]Inside the manager as seen below you are able to select the type of library you are looking for, for example, installed, arduino and etc.[[File:Manage libraries.png|thumb|alt=|none|783x783px]]
  −
 
  −
 
  −
When wanting to use a library, one must declare it at the top of their code so that their IDE knows that that file is being referred to, the syntax is:
  −
#include<math.h>
  −
 
  −
==Introduction to Programming Syntax and Conceptualization==
  −
As mentioned previously, and IDE is used to compile and execute the code utilized in a microcontroller. There are many different IDEs that can be used for various types of microcontroller and for each purpose there are more suitable boards that can be used. In order to program an Arduino, one must have the Arduino IDE downloaded (Refer to '''Connecting an Arduino'''). The Arduino IDE provides users with a programming editor as well as a way to easily upload and compile programs onto the Arduino board. Programs in the Arduino IDE are called sketches, and are normally saved with the .ino extension. The language used to program the Arduino board is based on the C++ language, which is a general use Object Oriented language. Like any common language, in order to start coding, one must be aware of the grammar rules and vocabulary that is used. An important word that will be often encountered is a “function”, which is a block of code that takes in an input, processes the input, then returns an output.
  −
 
  −
Some other basic considerations:
   
{| class="wikitable"
 
{| class="wikitable"
 
|+Table 3: Overview of some basic elements of programming
 
|+Table 3: Overview of some basic elements of programming
MakerRepo Staff, MakerRepo Volunteers
240

edits