You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

212 lines
9.7 KiB

= Εισαγωγή στο Διαδίκτυο των Αντικειμένων !
Apostolos rootApostolos@swarmlab.io
// Metadata:
:description: IoT Arduino Uno
:keywords: iot, swarm, Arduino
:data-uri:
:toc: right
:toc-title: Πίνακας περιεχομένων
:toclevels: 4
:source-highlighter: highlight
:icons: font
:sectnums:
{empty} +
Το Arduino είναι ένας μικροελεγκτής μονής πλακέτας, δηλαδή μια απλή μητρική πλακέτα ανοικτού κώδικα με ενσωματωμένο μικροελεγκτή και εισόδους/εξόδους, η οποία μπορεί να προγραμματιστεί με τη γλώσσα Wiring (ουσιαστικά πρόκειται για τη γλώσσα προγραμματισμού C++ και ένα σύνολο από βιβλιοθήκες, υλοποιημένες επίσης στην C++ ). Το Arduino μπορεί να χρησιμοποιηθεί για την ανάπτυξη ανεξάρτητων διαδραστικών αντικειμένων αλλά και να συνδεθεί με υπολογιστή μέσω προγραμμάτων σε Processing, Max/MSP, Pure Data, SuperCollider. Οι περισσότερες εκδόσεις του Arduino μπορούν να αγοραστούν προ-συναρμολογημένες· το διάγραμμα και πληροφορίες για το υλικό είναι ελεύθερα διαθέσιμα για αυτούς που θέλουν να συναρμολογήσουν το Arduino μόνοι τους.
Wikipedia(EL) +
https://el.wikipedia.org/wiki/Arduino[^]
Wikipedia(EN) +
https://en.wikipedia.org/wiki/Arduino[^]
[[cheat-HowTo]]
== How to use Arduino Board
The 14 digital input/output pins can be used as input or output pins by using pinMode(), digitalRead() and digitalWrite() functions in arduino programming. Each pin operate at 5V and can provide or receive a maximum of 40mA current, and has an internal pull-up resistor of 20-50 KOhms which are disconnected by default. Out of these 14 pins, some pins have specific functions as listed below:
- Serial Pins 0 (Rx) and 1 (Tx): Rx and Tx pins are used to receive and transmit TTL serial data. They are connected with the corresponding ATmega328P USB to TTL serial chip.
- External Interrupt Pins 2 and 3: These pins can be configured to trigger an interrupt on a low value, a rising or falling edge, or a change in value.
- PWM Pins 3, 5, 6, 9 and 11: These pins provide an 8-bit PWM output by using analogWrite() function.
- SPI Pins 10 (SS), 11 (MOSI), 12 (MISO) and 13 (SCK): These pins are used for SPI communication.
- In-built LED Pin 13: This pin is connected with an built-in LED, when pin 13 is HIGH – LED is on and when pin 13 is LOW, its off.
Along with 14 Digital pins, there are 6 analog input pins, each of which provide 10 bits of resolution, i.e. 1024 different values. They measure from 0 to 5 volts but this limit can be increased by using AREF pin with analog Reference() function.
Analog pin 4 (SDA) and pin 5 (SCA) also used for TWI communication using Wire library.
Arduino Uno has a couple of other pins as explained below:
- AREF: Used to provide reference voltage for analog inputs with analogReference() function.
- Reset Pin: Making this pin LOW, resets the microcontroller.
== Install the Arduino Software (IDE) on Linux
=== Download the Arduino Software (IDE)
==== Installing via a tarball
Get the latest version from the download page https://www.arduino.cc/en/Main/Software[^]. You can choose between the 32, 64 and ARM versions. +
It is very important that you choose the right version for your Linux distro.
Clicking on the chosen version brings you to the donation page and then you can either open or save the file. Please save it on your computer.
TIP: We can download the latest version of the Arduino IDE from the Arduino website (here) as a tarball. A tarball is a type of compressed folder, like a .zip file, commonly used to distrubute software in Linux; its file extension is usually .tar.xz (or .tar.gz, if it uses Z compression. We'll get to this later).
WARNING: **Installing via apt**
While there is a package for the Arduino IDE on current APT repositories, it has not been updated for a while.
As such, while it is still possible to install the IDE by running sudo apt install arduino, it is not recommended to do so, as asking for support when using outdated software is more difficult.
In order to extract the files we need from the tarball, we can open a terminal, cd to where the downloaded tarball is, then run
```
tar -xvf FILENAME
```
where FILENAME is the name of the download (typically arduino-(version number)-linux64.tar.xz).
The command can be read as
* e**X**tract from an archive...
* **V**erbosely (meaning it prints the name of every file it finds)...
* from a **f**ile given by FILENAME.
When the command finishes, run ls again; tar should have created a new folder named arduino-(version number).
cd into the folder; there will be a file named install.sh in the folder. To install the IDE, execute install.sh with
```
./install.sh
```
If the script executes correctly and outputs done! at the end of its output, the IDE was installed correctly! Let's try to launch it in the next step.
=== First Launch
Before launching the IDE, connect your Arduino board to your computer with a USB cable.
==== Permissions checker
The first time we launch Arduino, a window will pop up asking to add us to the dialout group:
image:./1fbbfedb89a5133d.png[alt="IDE.",width=250,height=250]
==== Permissions
We can look at the Arduino device by running
```
ls -l /dev/ttyACM*
```
in a terminal. The output looks mostly like this:
```
crw-rw---- 1 root dialout 166, 0 Des 14 09:47 /dev/ttyACM0
```
The ‘0' at the end of ‘ACM' might be different, and multiple entries might be listed, but the parts we need to focus on are the string of letters and dashes in front, and the two names root and dialout.
The first name root is the owner of the device, and dialout is the owner group of the device.
The letters and dashes in front, starting after ‘c', represent the permissions for the device by user:
* The first triplet rw- mean that the owner (root) can read and write to this device
* The second triplet rw- mean that members of the owner group (dialout) can read and write to this device
* The third triplet --- means that other users have no permissions at all (meaning that nobody else can read and write to the device)
In short, nobody except root and members of dialout can do anything with the Arduino; since we aren't running the IDE as root or as a member of dialout, the IDE can't access the Arduino due to insufficient permissions.
After you log back in the Arduino IDE, the Serial Port option should be available; change that, and we should be able to upload code to the Arduino.
image:./6061b4c693302b28.png[alt="Port.",width=250,height=250]
==== Coding
Congratulations, you made it!
You've just installed the Arduino IDE on your computer; you've also learned how permissions and groups work in Linux!
== Programming Arduino
Once arduino IDE is installed on the computer, connect the board with computer using USB cable. Now open the arduino IDE and choose the correct board by selecting Tools>Boards>Arduino/Genuino Uno, and choose the correct Port by selecting Tools>Port. Arduino Uno is programmed using Arduino programming language based on Wiring. To get it started with Arduino Uno board and blink the built-in LED, load the example code by selecting Files>Examples>Basics>Blink. Once the example code (also shown below) is loaded into your IDE, click on the ‘upload’ button given on the top bar. Once the upload is finished, you should see the Arduino’s built-in LED blinking. Below is the example code for blinking:
```
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
```
== Pin Description
.Pin Description
[options="header,footer"]
|=======================
|Pin Category|Pin Name|Details
|Power|Vin, 3.3V, 5V, GND|
* Vin: Input voltage to Arduino when using an external power source.
* 5V: Regulated power supply used to power microcontroller and other components on the board.
* 3.3V: 3.3V supply generated by on-board voltage regulator. Maximum current draw is 50mA.
* GND: ground pins.
|Reset|Reset|
Resets the microcontroller.
| Analog Pins|A0 – A5|Used to provide analog input in the range of 0-5V
|Input/Output Pins|Digital Pins 0 - 13|Can be used as input or output pins.
|Serial|0(Rx), 1(Tx)|Used to receive and transmit TTL serial data.
|External Interrupts|2, 3|To trigger an interrupt.
|PWM|3, 5, 6, 9, 11|Provides 8-bit PWM output.
|SPI|10 (SS), 11 (MOSI), 12 (MISO) and 13 (SCK)|Used for SPI communication.
|Inbuilt LED|13|To turn on the inbuilt LED.
|TWI|A4 (SDA), A5 (SCA)|Used for TWI communication.
|AREF|AREF|To provide reference voltage for input voltage.
|=======================
== Arduino
image:./Arduino_KY-012_Keyes_Active_buzzer_module_connection_diagram.png[alt="Arduino.",width=250,height=250]
:hardbreaks:
{empty} +
{empty} +
{empty}
:!hardbreaks:
'''
.Reminder
[NOTE]
====
:hardbreaks:
Caminante, no hay camino,
se hace camino al andar.
Wanderer, there is no path,
the path is made by walking.
*Antonio Machado* Campos de Castilla
====