KEMBAR78
Arduino 101 | PDF
Arduino 101
Giorgio Aresu
Bologna, December 2, 2015
Who am I
void setup() {
Serial.begin(9600);
}
void intro() {
Serial.println("First name:_______________________________________Giorgio");
Serial.println("Last name:__________________________________________Aresu");
Serial.println("I am:__________________________________Computer Scientist");
Serial.println("Working in:_______________________________SCAI Consulting");
Serial.println(" ( '_')0*´¯`·_¸_·´¯`°Q('_' ) ");
Serial.println("Twitter:___________________________________@giorgio_aresu");
Serial.println("LinkedIn:___________________________________Giorgio Aresu");
Serial.println("Personal email:____________________giorgioaresu@gmail.com");
Serial.println("Work email:___giorgio.aresu@scai-consulting.grupposcai.it");
Serial.println("Interests:_________motorcycles,technology,electronics,IoT");
}
void loop() {
intro();
delay(1000);
}
What is it?
Open-source prototyping platform
Based on Atmel 8-, 16- or 32-bit AVR microcontrollers
Standard connectors to connect and stack shields
Pre-programmed with a bootloader that simplifies uploading of programs to the
on-chip flash memory
More straightforward by allowing the use of an ordinary computer as the
programmer.
What for
- Domotics
- Alarm systems, motion
detection
- Weather stations
- Wearables
- Sensor networks
- Robots and drones
- Retro-gaming, LED controllers,
etc.
Some use cases
RGB infinity mirror
http://www.instructables.com/id/Arduino-controlled-RGB-LED-Infinity-Mirror/
LEDmePlay
http://mithotronic.de/ledmeplay_games_overview.html
The Inebriator - Cocktail machine
http://www.theinebriator.com/
Flamethrowing jack-o’-lantern
http://arstechnica.com/information-technology/2013/05/11-arduino-projects-that-require-major-hacking-skills-or-a-bit-of-insanity/3/
Microcontroller or Microprocessor?
Microcontroller (MCU)
Contains a processor core, memory,
and programmable input/output
peripherals.
Designed for application-specific,
embedded applications (remote
controls, appliances, toys).
Cheaper, smaller, lower power
consumption (as low as nanowatts),
optimized for latency.
Microprocessor
Only contains a CPU, has no memory
and uses all pins as a bus.
Multipurpose programmable
processing unit.
Faster, more versatile, suitable for
complex tasks, optimized for
throughput.
Why Arduino?
1. Inexpensive
2. Cross-platform
3. Simple programming
environment
4. Open source and extensible
software
5. Open source and extensible
hardware
Uno Mega
Nano
Gemma
Pro Mini
Lots of models
and many more...
Connections and pins
Main connections
USB
5v regulated input
Vin
5-9v or 5-12v (depending on board)
unregulated input
IOREF
Board I/O voltage, Uno supplies 5v, Due
3.3v
GND
IOREF
RESET
3.3V
5V
GND
GND
Vin
USB
Vin
Pay attention to power limits on all pins,
you may damage your board!
RESET
I/O Pins
Digital I/O
Standard 1/0 levels
5 volts
Analog Input
10-bit ADC
0-5 volts adjusted via AREF
Can be used as Digital I/O
Digital
Analog
AREF
I/O Pins
Serial
Used as a console and to communicate
to other TTL devices
TX
RX
USB
Example:
- ESP8266 (WiFi module)
I/O Pins
External interrupts
Can be configured to trigger an interrupt
on a signal state change
Example:
- PIR (IR movement sensor)
PIN 2
PIN 3
I/O Pins
Pulse Width Modulation
8-bit PWM output, can simulate analog
output
Example:
- Light Dimmer
- Motor speed control
PIN 5
PIN 3
PIN 6
PIN 9
PIN 11
PIN 10
I/O Pins
SPI
Serial bus used to connect multiple
devices and to flash the MCU itself,
bypassing the bootloader
Single master, one or more slaves (one
SS line per slave)
Example:
- Barometric Pressure Sensor
- AD5206 (Digital Potentiometer)
- LCD/OLED Displays
- ICSP
SCK
MISO
MOSI
SS
ICSP
ICSP
I/O Pins
I2
C
Bus used to attach multiple peripherals
Slower than SPI but only requires 2 lines
and scales better with multiple devices
Example:
- EEPROM Modules
- TMP102 (Temperature sensor)
- LCD/OLED Displays
SDA
SCL
IDE
IDE - Official
➔ Simple and lightweight
➔ Cross-platform
IDE - Visual Micro
➔ Visual Studio plugin
➔ Intellisense and autocomplete
➔ Windows only
IDE - Scratch
➔ Alternative language
➔ Event driven programming
➔ Cross-platform
Base sketch structure
// Libraries
#include <SPI.h>
#include <SD.h>
// Global variables
File myFile;
// One time initialization function
void setup()
{
Serial.begin(9600);
Serial.print("Initializing SD card...");
// [...]
}
// Endless loop function
void loop()
{
// [...]
}
void setup()
initialize system
void loop()
contains all logic
Demo time!
Blink sketch - Software
void setup()
{
// initialize digital pin 13 as an output
pinMode(13, OUTPUT);
}
void loop()
{
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Blink sketch - Hardware
BT controlled appliance
#define RELAY 8
void setup()
{
// Open serial communications and wait for port to open
Serial.begin(9600);
// initialize digital pin as an output.
pinMode(RELAY, OUTPUT);
digitalWrite(RELAY, HIGH);
Serial.println("Up and running");
}
void loop()
{
while (!Serial.available()) {} // Wait for connection
int i = Serial.parseInt();
if (i == 2)
digitalWrite(RELAY, LOW);
else if (i == 1)
digitalWrite(RELAY, HIGH);
else if (i == 4)
digitalWrite(RELAY, !digitalRead(RELAY)); // Invert state
}
BT controlled appliance
https://github.com/GiorgioAresu/NeopixelTinyClock
LED Clock
Questions?
You can find software, documentation, forum, and
support the project at https://www.arduino.cc/
Giorgio Aresu
Bologna, December 2, 2015
Arduino 101

Arduino 101

  • 1.
  • 2.
    Who am I voidsetup() { Serial.begin(9600); } void intro() { Serial.println("First name:_______________________________________Giorgio"); Serial.println("Last name:__________________________________________Aresu"); Serial.println("I am:__________________________________Computer Scientist"); Serial.println("Working in:_______________________________SCAI Consulting"); Serial.println(" ( '_')0*´¯`·_¸_·´¯`°Q('_' ) "); Serial.println("Twitter:___________________________________@giorgio_aresu"); Serial.println("LinkedIn:___________________________________Giorgio Aresu"); Serial.println("Personal email:____________________giorgioaresu@gmail.com"); Serial.println("Work email:___giorgio.aresu@scai-consulting.grupposcai.it"); Serial.println("Interests:_________motorcycles,technology,electronics,IoT"); } void loop() { intro(); delay(1000); }
  • 3.
    What is it? Open-sourceprototyping platform Based on Atmel 8-, 16- or 32-bit AVR microcontrollers Standard connectors to connect and stack shields Pre-programmed with a bootloader that simplifies uploading of programs to the on-chip flash memory More straightforward by allowing the use of an ordinary computer as the programmer.
  • 4.
    What for - Domotics -Alarm systems, motion detection - Weather stations - Wearables - Sensor networks - Robots and drones - Retro-gaming, LED controllers, etc. Some use cases
  • 5.
  • 6.
  • 7.
    The Inebriator -Cocktail machine http://www.theinebriator.com/
  • 8.
  • 9.
    Microcontroller or Microprocessor? Microcontroller(MCU) Contains a processor core, memory, and programmable input/output peripherals. Designed for application-specific, embedded applications (remote controls, appliances, toys). Cheaper, smaller, lower power consumption (as low as nanowatts), optimized for latency. Microprocessor Only contains a CPU, has no memory and uses all pins as a bus. Multipurpose programmable processing unit. Faster, more versatile, suitable for complex tasks, optimized for throughput.
  • 10.
    Why Arduino? 1. Inexpensive 2.Cross-platform 3. Simple programming environment 4. Open source and extensible software 5. Open source and extensible hardware
  • 11.
    Uno Mega Nano Gemma Pro Mini Lotsof models and many more...
  • 12.
  • 13.
    Main connections USB 5v regulatedinput Vin 5-9v or 5-12v (depending on board) unregulated input IOREF Board I/O voltage, Uno supplies 5v, Due 3.3v GND IOREF RESET 3.3V 5V GND GND Vin USB Vin Pay attention to power limits on all pins, you may damage your board! RESET
  • 14.
    I/O Pins Digital I/O Standard1/0 levels 5 volts Analog Input 10-bit ADC 0-5 volts adjusted via AREF Can be used as Digital I/O Digital Analog AREF
  • 15.
    I/O Pins Serial Used asa console and to communicate to other TTL devices TX RX USB Example: - ESP8266 (WiFi module)
  • 16.
    I/O Pins External interrupts Canbe configured to trigger an interrupt on a signal state change Example: - PIR (IR movement sensor) PIN 2 PIN 3
  • 17.
    I/O Pins Pulse WidthModulation 8-bit PWM output, can simulate analog output Example: - Light Dimmer - Motor speed control PIN 5 PIN 3 PIN 6 PIN 9 PIN 11 PIN 10
  • 18.
    I/O Pins SPI Serial busused to connect multiple devices and to flash the MCU itself, bypassing the bootloader Single master, one or more slaves (one SS line per slave) Example: - Barometric Pressure Sensor - AD5206 (Digital Potentiometer) - LCD/OLED Displays - ICSP SCK MISO MOSI SS ICSP ICSP
  • 19.
    I/O Pins I2 C Bus usedto attach multiple peripherals Slower than SPI but only requires 2 lines and scales better with multiple devices Example: - EEPROM Modules - TMP102 (Temperature sensor) - LCD/OLED Displays SDA SCL
  • 20.
  • 21.
    IDE - Official ➔Simple and lightweight ➔ Cross-platform
  • 22.
    IDE - VisualMicro ➔ Visual Studio plugin ➔ Intellisense and autocomplete ➔ Windows only
  • 23.
    IDE - Scratch ➔Alternative language ➔ Event driven programming ➔ Cross-platform
  • 24.
    Base sketch structure //Libraries #include <SPI.h> #include <SD.h> // Global variables File myFile; // One time initialization function void setup() { Serial.begin(9600); Serial.print("Initializing SD card..."); // [...] } // Endless loop function void loop() { // [...] } void setup() initialize system void loop() contains all logic
  • 25.
  • 26.
    Blink sketch -Software void setup() { // initialize digital pin 13 as an output pinMode(13, OUTPUT); } void loop() { digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(13, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second }
  • 27.
  • 28.
    BT controlled appliance #defineRELAY 8 void setup() { // Open serial communications and wait for port to open Serial.begin(9600); // initialize digital pin as an output. pinMode(RELAY, OUTPUT); digitalWrite(RELAY, HIGH); Serial.println("Up and running"); } void loop() { while (!Serial.available()) {} // Wait for connection int i = Serial.parseInt(); if (i == 2) digitalWrite(RELAY, LOW); else if (i == 1) digitalWrite(RELAY, HIGH); else if (i == 4) digitalWrite(RELAY, !digitalRead(RELAY)); // Invert state }
  • 29.
  • 30.
  • 31.
    Questions? You can findsoftware, documentation, forum, and support the project at https://www.arduino.cc/ Giorgio Aresu Bologna, December 2, 2015