Difference between revisions of "Arduino first steps"

From www.wiki.ardumower.de
Jump to: navigation, search
 
(31 intermediate revisions by 3 users not shown)
Line 3: Line 3:
  
  
All you need to <b>'upload' the example code</b> to your Arduino is:
+
All you need to run the example below is:
 
* One Arduino Nano (or Arduino Mega2560)
 
* One Arduino Nano (or Arduino Mega2560)
 
* One USB cable
 
* One USB cable
Line 15: Line 15:
 
  File: Arduino atmega2560 usb connected.jpg|Arduino Mega 2560 connected via USB
 
  File: Arduino atmega2560 usb connected.jpg|Arduino Mega 2560 connected via USB
 
  </gallery>
 
  </gallery>
 +
 +
If your Arduino is not recognised as an USB device after plug-in, try a different USB cable.
 +
 +
You may need to install a driver for your Arduino:
 +
*  Arduino Nano: Click [http://forum.diamex.de/attachment.php?attachmentid=65&d=1346742303 here] to download 'FTDI CDM 2.08.24'
 +
  Note: Do NOT use the newest FTDI drivers as they may make your Arduino malfunction). Here are the steps to remove any newer driver:
 +
  1. In Windows, choose 'Computer->Properties->Extended system settings->Hardware device settings'
 +
  2. Set 'Should Windows install drivers automatically?' to 'NO'
 +
  3. Activate 'Never install drivers via Windows Update'
 +
  4. Run [http://www.ftdichip.com/Support/Utilities.htm CDM Uninstaller]
 +
  5. Click 'Add', then 'Remove Devices'
 +
  6. Restart your computer
 +
  7. Re-plug Arduino Nano, now Windows should ask for driver installation, and you can choose the correct driver version (2.08.24)
 +
*  Arduino Mega 2560:
 +
  1. Download the Arduino development software (link in next section below) to your computer
 +
  2. Navigate to and select the driver file named "arduino.inf", located in the "Drivers" folder of the Arduino Software download.
  
 
<h3><b>2. Download</b></h3>
 
<h3><b>2. Download</b></h3>
  Click here to download the Arduino development software (v1.5.8) to your computer  
+
  Click here to download the Arduino development software (v1.6.3) to your computer  
 
  (Windows users should download the 'Installer' version on that page):
 
  (Windows users should download the 'Installer' version on that page):
  
Line 24: Line 40:
 
<h3><b>3. Install</b></h3>
 
<h3><b>3. Install</b></h3>
 
  After the download completed, install the Arduino development software on your computer:
 
  After the download completed, install the Arduino development software on your computer:
  For Windows users, double click the downloaded file ('arduino-1.5.8-windows.exe') in your
+
  For Windows users, double click the downloaded file ('arduino-1.6.3-windows.exe') in your
 
  Windows file explorer to run the installation.
 
  Windows file explorer to run the installation.
  
Line 52: Line 68:
 
<h3><b>8. Upload the blink example</b></h3>
 
<h3><b>8. Upload the blink example</b></h3>
 
  Click on the 'Upload' symbol to upload the blink example to your Arduino.  
 
  Click on the 'Upload' symbol to upload the blink example to your Arduino.  
After the upload completed, your Arduino will start to blink!
 
  
 
  [[File: Arduino ide upload.jpg]]
 
  [[File: Arduino ide upload.jpg]]
  
  After the code is uploaded, your Arduino will start to blink:
+
  After the code is uploaded, your Arduino will start to blink!
  
  [[File: Arduino nano blink.jpg]]
+
  [[File: Arduino nano blink example.gif]]
  
 
<h3><b>Congratulations!</b></h3>
 
<h3><b>Congratulations!</b></h3>
Line 64: Line 79:
  
  
<h3><b>Now let's look a little bit closer at the blink code to understand it:</b></h3>  
+
<h3><b>Now let's look a little bit closer at the above blink code to understand it:</b></h3>  
  The Arduino has several pins, each of them has a number, and each of them can be configured as either <b>INPUT</b> or <b>OUTPUT</b>  
+
  The Arduino has several pins, each of them has a number.  As shown below, Pin 13 is already (internally) connected to the on-board LED:
depending on wheter you want to read it or write to it:  
+
 
 +
[[File: Arduino nano pinout.jpg|300px]]
 +
 
 +
Each pin can be configured as either <b>INPUT</b> or <b>OUTPUT</b> depending on wheter you want  
 +
to measure or control that pin :  
  
 
<blockquote style="background-color: lightgrey; border: solid thin grey;">
 
<blockquote style="background-color: lightgrey; border: solid thin grey;">
 
<pre>
 
<pre>
  <b>INPUT</b> means that you can read (or measure) that pin. The measurement can be either ON  
+
  INPUT   means that you can read (or measure) that pin. The measurement can be either ON  
  (there is voltage on that pin) or OFF (there is no voltage on that pin).
+
  (there is voltage on that pin) or OFF (there is no voltage on that pin).
<b>OUTPUT</b> means that you can write (or control) that pin.
+
 
</pre>
 
</pre>
 
</blockquote>
 
</blockquote>
  
We are using the LED pin (pin 13) in the blink example that is already connected to an LED. Because we want to control that pin,
 
we are configuring it as <b>OUTPUT</b>.
 
 
 
<blockquote style="background-color: lightgrey; border: solid thin grey;">
 
<blockquote style="background-color: lightgrey; border: solid thin grey;">
 
<pre>
 
<pre>
  <b>pinMode(13, OUTPUT);</b>
+
  OUTPUT   means that you can write (or control) the voltage of that pin.
 
</pre>
 
</pre>
 
</blockquote>
 
</blockquote>
  
  Now let's see how we can turn ON and OFF the LED using an Arduino command. This command will turn ON the voltage for pin 13:
+
  In the blink example above, we are using the LED pin (pin 13) that is already connected to an LED.  
 +
Because we want to control that pin, we are configuring it as <b>OUTPUT</b>:  
  
 
<blockquote style="background-color: lightgrey; border: solid thin grey;">
 
<blockquote style="background-color: lightgrey; border: solid thin grey;">
 
<pre>
 
<pre>
  <b>digitalWrite(13, HIGH);</b>
+
  pinMode(13, OUTPUT);
 
</pre>
 
</pre>
 
</blockquote>
 
</blockquote>
  
  And this command will turn OFF the voltage for pin 13:
+
 
 +
  Now let's see how we can turn ON or OFF the LED using an Arduino command. This command will turn ON the voltage for pin 13:
  
 
<blockquote style="background-color: lightgrey; border: solid thin grey;">
 
<blockquote style="background-color: lightgrey; border: solid thin grey;">
 
<pre>
 
<pre>
  <b>digitalWrite(13, LOW);</b>
+
  digitalWrite(13, HIGH);
 +
</pre>
 +
</blockquote>
 +
 
 +
And consequently this command will turn OFF the voltage for pin 13:
 +
 
 +
<blockquote style="background-color: lightgrey; border: solid thin grey;">
 +
<pre>
 +
digitalWrite(13, LOW);
 
</pre>
 
</pre>
 
</blockquote>
 
</blockquote>
 
   
 
   
  Let's see how we can wait one second between the ON and OFF toggling. This command will wait (halt) the program for one second:
+
  Let's see how we can wait one second between the ON and OFF toggling. This command will wait (halt)  
 +
the program for one second (=1000 milliseconds):
  
 
<blockquote style="background-color: lightgrey; border: solid thin grey;">
 
<blockquote style="background-color: lightgrey; border: solid thin grey;">
Line 109: Line 135:
 
</blockquote>
 
</blockquote>
  
 +
 +
So let's look at the complete blink program again:
 +
 +
<blockquote style="background-color: lightgrey; border: solid thin grey;">
 +
<pre>
 +
void setup(){
 +
  pinMode(13, OUTPUT);      // we want to control pin 13
 +
}
 +
 +
void loop(){
 +
  digitalWrite(13, HIGH);  // pin 13 will go HIGH (voltage ON)
 +
  delay(1000);              // wait one second (=1000 milliseconds)
 +
  digitalWrite(13, LOW);    // pin 13 wil go LOW (voltage OFF)
 +
  delay(1000);              // wait one second (=1000 milliseconds)
 +
  // ...now everything repeats                         
 +
}
 +
</pre>
 +
</blockquote>
  
  
  Now you can try to upload the [http://wiki.ardumower.de/index.php?title=Ardumower_PCB Ardumower code] the same way as you uploaded the blink example!
+
<h3><b>How to go further...</b></h3>
 +
  Now you can try to upload the Ardumower code the same way as you uploaded the blink example!
  
 
  &nbsp;
 
  &nbsp;

Latest revision as of 09:51, 4 July 2017

If you have never worked with Arduino before, this page describes how to start with your Arduino that you can purchase via the shop Shopping.png.


All you need to run the example below is:

  • One Arduino Nano (or Arduino Mega2560)
  • One USB cable
Arduino nano usb cable.jpg


1. Attach the Arduino to your computer

Using an USB cable, attach the Arduino (Arduino Nano or Arduino Mega) to your computer as shown below.

If your Arduino is not recognised as an USB device after plug-in, try a different USB cable.

You may need to install a driver for your Arduino:

  • Arduino Nano: Click here to download 'FTDI CDM 2.08.24'
  Note: Do NOT use the newest FTDI drivers as they may make your Arduino malfunction). Here are the steps to remove any newer driver:
  1. In Windows, choose 'Computer->Properties->Extended system settings->Hardware device settings'
  2. Set 'Should Windows install drivers automatically?' to 'NO'
  3. Activate 'Never install drivers via Windows Update'
  4. Run CDM Uninstaller
  5. Click 'Add', then 'Remove Devices'
  6. Restart your computer
  7. Re-plug Arduino Nano, now Windows should ask for driver installation, and you can choose the correct driver version (2.08.24)
  • Arduino Mega 2560:
  1. Download the Arduino development software (link in next section below) to your computer
  2. Navigate to and select the driver file named "arduino.inf", located in the "Drivers" folder of the Arduino Software download.

2. Download

Click here to download the Arduino development software (v1.6.3) to your computer 
(Windows users should download the 'Installer' version on that page):
Arduino symbol small.jpg  

3. Install

After the download completed, install the Arduino development software on your computer:
For Windows users, double click the downloaded file ('arduino-1.6.3-windows.exe') in your
Windows file explorer to run the installation.

4. Run

After the installation completed, run the Arduino development software on your computer 
by double clicking the 'Arduino' symbol on your Windows desktop.
Arduino start symbol small.jpg

5. Choose blink example

After the Arduino development software has started, choose the menu, 
and click on 'File->Examples->Basics->Blink'. This will load the Arduino blink example.
Arduino ide blink example.jpg

6. Choose correct board type

Via the menu, click on 'Tools->Board->Arduino Nano' to choose your Nano board 
(or Arduino Mega 2560 if you want to use a Mega board). 
Arduino ide choose board.jpg

7. Choose correct USB serial port

Via the menu, click on 'Tools->Port', and choose the detected USB serial port.
Arduino ide choose port.jpg

8. Upload the blink example

Click on the 'Upload' symbol to upload the blink example to your Arduino. 
Arduino ide upload.jpg
After the code is uploaded, your Arduino will start to blink!
Arduino nano blink example.gif

Congratulations!

You have just programmed your first Arduino!


Now let's look a little bit closer at the above blink code to understand it:

The Arduino has several pins, each of them has a number.  As shown below, Pin 13 is already (internally) connected to the on-board LED:
Arduino nano pinout.jpg
Each pin can be configured as either INPUT or OUTPUT depending on wheter you want 
to measure or control that pin : 
 INPUT   means that you can read (or measure) that pin. The measurement can be either ON 
 (there is voltage on that pin)  or OFF (there is no voltage on that pin).
 OUTPUT   means that you can write (or control) the voltage of that pin.
In the blink example above, we are using the LED pin (pin 13) that is already connected to an LED. 
Because we want to control that pin, we are configuring it as OUTPUT: 
 pinMode(13, OUTPUT);


Now let's see how we can turn ON or OFF the LED using an Arduino command. This command will turn ON the voltage for pin 13:
 digitalWrite(13, HIGH);
And consequently this command will turn OFF the voltage for pin 13:
 digitalWrite(13, LOW);
Let's see how we can wait one second between the ON and OFF toggling. This command will wait (halt) 
the program for one second (=1000 milliseconds):
 delay(1000);


So let's look at the complete blink program again:
 void setup(){
   pinMode(13, OUTPUT);      // we want to control pin 13 
 }

 void loop(){
   digitalWrite(13, HIGH);   // pin 13 will go HIGH (voltage ON)
   delay(1000);              // wait one second (=1000 milliseconds)
   digitalWrite(13, LOW);    // pin 13 wil go LOW (voltage OFF)
   delay(1000);              // wait one second (=1000 milliseconds)
   // ...now everything repeats                           
 }


How to go further...

Now you can try to upload the Ardumower code the same way as you uploaded the blink example!