32
Arduino 101 Giorgio Aresu Bologna, December 2, 2015

Arduino 101

Embed Size (px)

Citation preview

Arduino 101

Giorgio AresuBologna, 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:[email protected]"); Serial.println("Work email:[email protected]"); 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

GNDIOREFRESET

3.3V5V

GNDGND

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

TXRX

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 2PIN 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 11PIN 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

SCKMISOMOSISS

ICSP

ICSP

I/O Pins

I2C

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

SDASCL

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 variablesFile myFile;

// One time initialization functionvoid setup(){ Serial.begin(9600); Serial.print("Initializing SD card..."); // [...]}

// Endless loop functionvoid 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 AresuBologna, December 2, 2015