dpnm lab., postech 1/44 cs490k - internet of things (iot) jonghwan hyun dpnm lab. department of...

44
NM Lab., POSTECH 1/4 CS490K - Internet of Things (IoT) Jonghwan Hyun DPNM Lab. Department of Computer Science and Engineering, POSTECH [email protected] Oct. 29, 2015 Introduction to Arduino

Upload: donald-dennis

Post on 21-Jan-2016

221 views

Category:

Documents


0 download

TRANSCRIPT

1

Jonghwan Hyun

DPNM Lab.Department of Computer Science and Engineering, POSTECH

[email protected]

Oct. 29, 2015Introduction to ArduinoDPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)1Microcontroller (mc, MCU)A small computer on a single chip Containing a processor, memory, and input/outputTypically "embedded" inside some device that they control Often small and low cost

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Microcontroller (mc, MCU)Computer on a single integrated chipProcessor (CPU)Memory (RAM / ROM / Flash)I/O ports (USB, I2C, SPI, ADC)Common microcontroller familiesIntel: 4004, 8008, etc.Atmel: AT and AVRMicrochip: PICARM: multiple manufacturersUsed inCellphonesToysHousehold appliancesCarsCameras

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)What is Arduino?Open-source hardware platformOpen source development environmentEasy-to learn language and libraries Integrated development environmentAvailable for Windows / Mac / LinuxA programmable microcontroller for prototyping electromechanical devicesAble to connect digital and analog electronic partsSensors (Gyroscopes, GPS Locators, accelerometers)Actuators (LEDS or electrical motors)

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)What is Arduino?Taken from the official web site (arduino.cc)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.

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Why use Arduino?Easy to use platformEase of programmingArduino C is a greatly simplified version of C++Simple USB interfaceSimple IDEMany shields availableInexpensive$35 retailDPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)

Arduino - UnoElectrical Inputs and OutputsInput voltage: 7-12 V (USB, DC plug, or Vin)Max output current per pin: 40 mAHardware I/O13 Digital I/O bits2 = serial TxD/RxD4 LEDs6 Analog outputsPulse-width modulatedChoose digital or PWM8-bit resolution6 Analog inputs10-bit resolution at bestDPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Arduino - UnoThe ATmega328P MicrocontrollerUsed by the Arduino UNOAVR 8-bit RISC architectureUp to 20 MHz clock32kB flash memory30 kB available for user code2 kB for bootloader2 kB RAMVolatile data memoryVariables + stack + heap + 23 programmable I/O channelsSix 10-bit ADC inputsThree timers/countersSix PWM outputs

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Many Flavors of ArduinoMany different versionNumber of I/O channelsForm factorProcessor

UnoLeonardoDueMicro / Mini / NanoLilyPadEsploraMega

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Many Flavors of ArduinoLeonardoCompared to the Uno, a slight upgradeBuilt in USB compatibilityPresents to PC as a mouse or keyboard

DueMuch faster processor, many more pinsOperates on 3.3 voltsSimilar to the Mega

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Many Flavors of ArduinoMicroWhen size matters: Micro, Nano, MiniIncludes all functionality of the LeonardoEasily usable on a breadboard

LilyPadPopular for clothing-based projects

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Many Flavors of ArduinoEsploraGame controllerIncludes joystick, four buttons, linear potentiometer (slider), microphone, light sensor, temperature sensor, three-axis accelerometerNot the standard set of IO pinsMegaCompared to the Uno:Many more communication pinsMore memory

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Arduino-like SystemsCortino (ARM)Xduino (ARM)LeafLabs Maple (ARM)BeagleBoard (Linux)Wiring Board (Arduino predecessor)

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Arduino Add-ons (Shields)

(Connects to a computer power supply)

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)

Arduino Add-ons (Shields)

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Arduino Add-ons (Shields)Communication Shields

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Modules send serial data strings to the ArduinoArduino Add-ons (Modules)

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Arduino Add-ons (Sensors)

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Arduino Add-ons (Sensors)Photoresistor, infrared, force sensitive resistor, Hall effect, Piezo, tilt sensor

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Arduino Add-ons (Actuators)ActuatorCause some physical action to be takenMovement, lighting, heating, motor action, display of information, sending or receiving network, radio communications, and etc.Types of ActuatorsLightLEDs, Fluorescent lamps, LCD displays, lasersSoundBuzzers, Beepers, Speakers, MP3/Audio players, synthesizersMotionDC Motors, Stepper Motors, Servo-motors, solenoids, "muscle-wire", electromagnetsPower ControlControl of other electrically operated devices

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Raspberry Pi vs. ArduinoRaspberry PiFully functional computerCPU, memory, graphics driver, Runs Linux OSInternal storage (SD cards)Network connectivity (Ethernet)ArduinoMicrocontrollers, not full computersDirectly executing simple code is easierNo operating system overheadGood for interfacing with other devices and actuatorsDPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Raspberry Pi vs. ArduinoRaspberry PiArduinoPowerRequires constant 5V powerShould be shutdown via a software processExecuting code when turned onStops when lose powerNetworkingBuilt-in Ethernet portEasy to use Wi-Fi (using USB)Need an extra chip with wiring and codingSensorsRequires software to effectively interface with these sorts of devicesEasier to connect analog sensorsWhen to Use?When you would otherwise complete your task with a personal computerConnect to the Internet to read and write data, view media of any kind, or connect to an external displayWhen the main task is reading sensor data and changing values on motors or other devicesDevice will be constantly running and requires little to no interactionDPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)ProjectsOWI535 Robotic Arm To Rover Armhttp://sourceforge.net/projects/owi535roverarm/

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Projects

chlonosAn open source talking multimedia clock gadgetUsing a 126 LED display, temperature and light sensorshttps://code.google.com/p/chlonos/

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)ProjectsRearEye - A wearable additional eye Simple Lilypad project to get additional distance sensesBy putting it in pocket or backpack in order to sense someone / something approachingConsists of a Lilypad, a LilyPad Vibe Board and a SRF05 Ultrasonic Ranger

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)ProjectsLED Matrix from processinghttp://www.youtube.com/watch?v=kkJDWrM-K4UArduino Flash Controlhttp://www.youtube.com/watch?v=7T1jmj4KClAGoogle Earthwalkhttp://www.youtube.com/watch?v=zoNwJ931aqIUltrasonic grasshttp://www.youtube.com/watch?v=bZIKbuZaJSQPiezo ponghttp://www.youtube.com/watch?v=nXLDyBFsqdgAccelerometer and Flashhttp://www.youtube.com/watch?v=49WBPIIo3EE

Lots of interesting projects you can find in http://playground.arduino.cc/projects/arduinoUsersDPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Referenceshttp://arduino.cc/Official homepage with Playground & forumshttp://ladyada.net/learn/arduino/Great Arduino tutorialshttp://todbot.com/blog/category/arduino/Various movies, hacks, tutorials on Arduinohttp://freeduino.org/Index of Arduino knowledgehttp://adafruit.com/Arduino starter kits, Boarduino Arduino clone, lots of cool kitshttp://sparkfun.com/Sells Arduino boards and lots of neat sensors & stuff

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Installing ArduinoWhat do we need?

(Optional)

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Installing ArduinoDownload & install the Arduino environment (IDE)Connect the board to your computer via the USB cableInstall the driversLaunch the Arduino IDESelect your boardSelect your serial portWrite codesUpload the program

Reference: http://arduino.cc/en/Guide/HomePage

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Installing ArduinoDownload & install the Arduino environment (IDE)Official homepage: http://arduino.cc/en/Main/SoftwareLink for faster downloadhttp://server.noraki.net/Arduino/

No installer needed, except for WindowsJava needs to be installed(Windows) Install drivers during IDE installation(Linux) $ sudo apt-get install arduinoPrerequisite for LinuxAssumes running Ubuntu$ sudo apt-get remove brltty

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Installing ArduinoConnect the board to your computer via the USB cable

USB A typeUSB B type

USB A typeUSB B typeDPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Installing ArduinoConnecting ArduinoMACClick Network Preferences, and in the window that appears, click Apply.

Linux$ ls /dev/tty* SHOULD have device name like ttyACM*, ttyUSB* or ttyS*Windows

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Programming ArduinoArduino IDEYet Another IDEVery few featuresSimple programsExactly the use caseWritten in JavaClick to upload

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Programming ArduinoProgramming LanguageC like syntax, but simplifiedAbstracts the pin naming to numbersTrades efficience for ease of useEasy to learn, yet powerfulLots of example code Easy to reuse C-code from other projectsLibraries can be written in C++Lots of libraries availableDPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Programming ArduinoLaunch the Arduino IDE

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Programming ArduinoSelect board

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Programming ArduinoSelect your serial port(Windows) Device manager (Win + R devmgmt.msc )(MAC) tty.usbmodem(Linux) /dev/tty/USB* or /dev/tty.USB*

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Programming Arduino Programming Reference

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Sample Program LED BlinkLED BlinkBlinking LED on Arduino board

CodesLoad the Blink exampleFileExamplesBasicsBlink

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Sample Program LED BlinkVerify & Compile

Once it compiles, you must see the following messages in the Status bar and the Program notification Area

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Sample Program LED BlinkUpload to the board

Once it upload, you must see the following messages in the Status bar and the Program notification Area

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Sample Program Serial CommunicationSerial communicationArduino uses serial ports to communicate with PCWritingSerial.begin (baud)Initialize serial port for communicationSets baud rateExampleSerial.begin(9600); // 9600 baudSerial.print (val), Serial.print (val, fmt)Prints data to the serial portExamplesSerial.print(Hi); // print a stringSerial.print(78); // works with numbers, tooSerial.print(variable); // works with variablesSerial.print(78,BIN); // will print 1001110Serial.println(val)Same as Serial.print(), but with line-feedDPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Sample Program Serial CommunicationReadingSerial.available()Returns the number of bytes available to be read, if anyExampleif (Serial.available() > 0) data = Serial.read();Reading data from serial portletter = Serial.read()letters = Serial.readBytesUntil(character, buffer, length)number = Serial.parseInt()number = Serial.parseFloat()Serial MonitorSend / Receive serial dataIncluded in the IDECtrl Shift M

DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)Sample Program Serial CommunicationEchoArduino will echo anything you send to it until you send , (a comma)Source codes

/* Use a variable called byteRead to temporarily store the data coming from the PC */byte byteRead;

void setup() { // Turn the Serial Protocol ON Serial.begin(9600);}

void loop() { /* check if data has been sent from the computer: */ if (Serial.available()) { /* read the most recent byte */ byteRead = Serial.read(); /*Listen for a comma which equals byte code # 44 */ if(byteRead==44){ Serial.println(); }else{ /*ECHO the value that was read, back to the serial port. */ Serial.write(byteRead); } }}DPNM Lab., POSTECH #/44CS490K - Internet of Things (IoT)