Introduction To Arduino - Dipartimento Di Matematica .

Transcription

Introduction to ArduinoMobile Computing, aa. 2016/2017May 12, 2017Daniele Ronzani - Ph.D student in Computer Sciencedronzani@math.unipd.it

What are Microcontrollers Very small and simple computers Cheap and useful Present in every smart system Atmel is one of the family of microcontrollers2

What is the DIY paradigm Create something without professional knowledge Many fields ProgrammingEducationCritical theoryBusinessElectronics.3

The Arduino projectArduino UNOArduino is an open-source electronicsprototyping platform based on flexible,easy-to-use hardware and software. It'sintended for artists, designers, hobbyists,and anyone interested in creating interactiveobjects or environments.Arduino.cc An Italian prototyping tool project Ready-made electronic products at low costs Open Source Boards with different performances Shields that extend the functions Wi-Fi, GPSR, Ethernet, microSD reader, .Shields and sensors4

Some History of Arduino Arduino was born in 2005 in Ivrea, Italy IDEA: less expensive device for controllinginteractive electronic projects Rapid prototyping Name "Arduino" in honor of Bar di ReArduino Start to produce boards in a small factory Arduino was built around the Wiringproject of Hernando Barragan. Hernando's thesis project at the Interaction DesignInstitute Ivrea. Remove the deep knowledge barriersMassimo Banzi5

The First Protoype6

Arduino Today Arduino community is mushrooming across the globe80% fromEurope and USAMore than 200distributors7

Some Competitors - 1 Lego Mindstorm Intelligent brick computerProgrammed in Brick LogoStrong communityToo much expensive (cost: 349) i-cubeX Objects respond to human actions andenvironmental parametersHuman Interface DevicesEasy but expensive Phidgets Easy-to-assemble sensors and controllersNot open source (proprietary)Requires less hardware and software knowledge 3.5 x the cost of Arduino board8

Some Competitors - 2 Make Controller Kit More powerful CPU than ArduinoHas quite a lot of "bang for the buck" Raspberry It is closer to a computerIncludes CPU, USB ports, Ethernet, HDMI, .Includes an own OS (Linux) Teensy Same Arduino firmwareCompatible with ArduinoVery small size UDOO Merges Arduino and RaspberryPowerful prototyping platformLinux or Android OSs9

The three key concepts of Arduino ProjectHardwareCan sense the environmentby sensors, and affects it bycontrolling lights, motors,and other actuators.EnvironmentAllows to write code in theArduino programming languageand using the Arduinodevelopment environment.CommunityIt is made up of everyone fromand to hobbyists, students,designers and engineers allacross the world. 10

Why should we use Arduino? Simple, academic purposes Open source Hardware & Software: permits to manufacture the boards andsoftware distribution by anyone Arduino compatibile: Canaduino, Freeduino, Linduino, SainSmart, .GNU Lesser General Public License (LGPL) Opportunistic prototyping Community WikiForumTutorials Could be used as an IoT starting point Physical computing objects11

2006: New Generation (NG) ATmega168First Mini Arduino 2007: Portable andcommunication i-BluetoothSew-through contacts pads 2009: Nano and LilyPad New Arduino Mega withATmega1280 2010: Rapid development Official Arduino Uno 2012: Miniaturization and CPUpower enhance LilyPad Simple/Snap and MicroArduino Due (32 bit)12

Evolution of Arduino 2013: 700.000 official boards were sold 2016: 17 versions of the Arduino board have beencommercially produced.13

Some Current Arduino BoardsUNO Current official reference of Arduino BoardsMost used and documented boardMega Designed for more complex projects54 digital I/O pins, 16 analog inputsATmega2560LilyPad Designed for e-textiles and wearables projectsCan be sewn to fabric and to power suppliesNano Compact board similar to the UNO14

Arduino as Physical Computing PlatformPhysical Computing involves the design of interactive objects that cancommunicate with humans using sensors and actuators controlled by abehaviour implemented as software running inside a microcontroller.15

Smart Objects in the Internet Of ThingsIoT is a new emerging technology where thethings are connected altogether and interact Arduino provides the tools Remote processing of dataConnection of physical objects to the Internet IoT Manifest Open SW & HW: Possibility to share worksMore innovation Sustainable Devices should be easily upgraded Fair You should have control of your devicesSecurity16

Arduino Cloud A new platform to make building IoT Creation of tools that allow connection and control of device on/bythe Internet MQTT broker makes connection between each object17

Home Control and Automation18

Arduino Usage ExamplesBeat Bearing19

Arduino Usage ExamplesTwitter Lamp20

TeleBall (Breakout game)21

Other Examples22

Arduino Architecture andComponents23

General ArchitectureMain components AVR Microcontroller Analog and digital I/O pins Flash memory Integrated in the microcontroller USB port for serial communicationUSBATmega328DC power jack24

Components: mandatoryWiresUSB connectorPrototyping board (breadboard)Resistors and leds25

Components: I/O devices26

Components: communication devicesWired and Wireless comm. devicesInfraredWiFiBluetoothZig-BeeEthernet27

Characteristics - 1Arduino UNO (ATmega 328)Technical characteristics Clock speed: 16 MHz (Intel 286: 12.5 MHz) - 8-bitFlash program memory: 32 KBytes (0.5 used by bootloader)SRAM: 2 KBytesInput / Output 14 digital input/output pins6 analog input pins6 analog output pins (PWM)28

Characteristics - 2Layout of Arduino UNO11.2.3.4.5.6.7.8.9.10.Analog Reference pinDigital GroundDigital pins 2-13Digital pins 0-1/Seral In/OutReset ButtonIn-circuit Serial ProgrammerAnalog In pins 0-5Power and Ground pinsExternal Power Supply InUSB port234106598729

Digital and Analog pins Digital pins have only two values on/off (0/1) Arduino UNO has 14 digital I/O pinsTo connect devices that read/produce digital values (switch, leds, .) Analog pins use many states using quantization Arduino UNO has 6 input analog pinsTo read analog sensors (temperature, pressure, . )An A/D converter of 10 bit returns integers from 0 to 102330

Digital and Analog pins Analog output pins use PWM technique Arduino UNO has 6 digital pins used as PWM ( )The signal is affected on the input pulse duration31

Programming in Arduino32

Life Cycle of a programpower ONresetpress resetGlobal Variables Declare variablesInitialize variablessetup() Run once at beginningSet pinsloop() Run the main programRepeatedly, after the setup33

Arduino IDE software Friendly Multi Platform applicationwritten in Java Allows you to write programs andupload them to your Arduino board Derived by "Processing" IDE Initially developed in 2003 to simplifieselectronic projects Very simple for novice programmers Simple programming languageBootloader Source code of IDE and library are distributed under thefree GNU GPLv2 license34

Arduino IDE software Text editor containing syntaxhighlighting and automaticindentation Toolbar Text Console Compiler Serial monitor to debug Sketch filled with the twobasic Arduino functions:the setup() and loop().Allows you to read the data thatArduino communicates throughthe COM serial port35

Online IDE - Web Editor36

Wiring-based Language Open Source computer programming language Derived by C/C language With some slight simplifications and modifications Includes classical libraries and functions Data types (Integer, float, long, character, .)Operators (Mathematical, logical, comparison, .)Control statements (If, switch/case, while, for, .) Offer to the programmer simple access to I/O devices Wiring programs are called sketch37

Some functionssetup()pinMode(pin, Input Output)or output Serial.begin(9600) talk to the computer at 9600 baud rate loop()set pin ledPin as an input Some values: 300, 600, 1200, 2400, 4800, 9600, 14400,19200, 28800, 38400, 57600, or 115200write text on Serial Monitor Serial.print(" . ") digitalWrite(pin, HIGH LOW) digitalRead(pin) analogRead(pin) analogWrite(pin, intValue) delay(milliseconds)set a digital pin high/lowread a digital pin's stateread an a analog pinwrite an "analog" PWM valuewait an amount of time38

Arduino's Hello World: LED blinking/*BlinkTurn on and off a LED every one second*/int ledPin 13; // LED connected to digital pin 13void setup(){Serial.begin(9600);pinMode(ledPin, OUTPUT); // sets the digital pin as output}// the loop routine runs over and over again forever:void loop(){digitalWrite(ledPin, HIGH);// turn the LED on (HIGH is the voltage level)delay(1000);// wait for a seconddigitalWrite(ledPin, LOW);// turn the LED off by making the voltage LOWdelay(1000);// wait for a second}39

Arduino's Hello World: LED blinking/*BlinkTurn on and off a LED every one second*/int ledPin 13; // LED connected to digital pin 13Initialise the variable with thepin numbervoid setup(){Serial.begin(9600);pinMode(ledPin, OUTPUT); // sets the digital pin as output}// the loop routine runs over and over again forever:void loop(){digitalWrite(ledPin, HIGH);// turn the LED on (HIGH is the voltage level)delay(1000);// wait for a seconddigitalWrite(ledPin, LOW);// turn the LED off by making the voltage LOWdelay(1000);// wait for a second}40

Arduino's Hello World: LED blinking/*BlinkTurn on and off a LED every one second*/int ledPin 13; // LED connected to digital pin 13void setup(){Serial.begin(9600);pinMode(ledPin, OUTPUT); // sets the digital pin as output}Setup the serialconnections and LED// the loop routine runs over and over again forever:void loop(){digitalWrite(ledPin, HIGH);// turn the LED on (HIGH is the voltage level)delay(1000);// wait for a seconddigitalWrite(ledPin, LOW);// turn the LED off by making the voltage LOWdelay(1000);// wait for a second}41

Arduino's Hello World: LED blinking/*BlinkTurn on and off a LED every one second*/int ledPin 13; // LED connected to digital pin 13void setup(){Serial.begin(9600);pinMode(ledPin, OUTPUT); // sets the digital pin as output}Turn the LED on and off// the loop routine runs over and over again forever:continuously in the loopvoid loop(){digitalWrite(ledPin, HIGH);// turn the LED on (HIGH is the voltage level)delay(1000);// wait for a seconddigitalWrite(ledPin, LOW);// turn the LED off by making the voltage LOWdelay(1000);// wait for a second}42

LED and Servo control via Android Application43

Thank you for the attentionDaniele Ronzanidronzani@math.unipd.it44

The Arduino project Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It's intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments. Arduino.cc An Italian prototyping