lab 2: arduino - u-m personal world wide web serverfrankxu/chinese/images/job/engr... · 2017. 12....
TRANSCRIPT
![Page 1: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/1.jpg)
Lab 2: Arduino
Zhentao Xu
![Page 2: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/2.jpg)
Today’s schedule
• Lecture 1: Arduino
• Install Arduino driver
• Lab 1: use Arduino UNO to control LED.
• Lecture 2: Sensor and Feedback
• Lab 2: use Arduino UNO and ultrasonic distancesensor to measure distance
• Lecture 3: Minimum system
• Lab 3: Building minimum system using AVR chip.
![Page 3: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/3.jpg)
What is Arduino?
• Official definition: A combination of hardware, software, development team, design philosophy.
• From Ivrea, Italy.(意大利的艾维里)
• Hardware include Arduino UNO and Arduino Mega, Software include Arduino IDE.
• Arduino UNO: Development board of AVR chips.
• Arduino UNO is announced in 2011.
• UNO Punto Zero (1.0)
![Page 4: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/4.jpg)
What can Arduino UNO do?
Self-balanced Car
![Page 5: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/5.jpg)
What can Arduino UNO do?
LED-Cubic
![Page 6: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/6.jpg)
Arduino Components
Processor
USB
PortsPower
Supply power & Serial Communicate
Connection with outside world
Supply power
Process information & Make decision
![Page 7: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/7.jpg)
Real Circuit Diagram
![Page 8: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/8.jpg)
Install Arduino driver
Refer to the PDF file from the announcement on SAKAI.
For Windows 7 Operating Systen:
• Step 1: Download Arduino IDE and unzip it.• http://arduino.googlecode.com/files/arduino-1.0.5-r2-
windows.zip
• Step 2: Plug in Arduino UNO board.
• Step 3: Right-click This PC Manage Other device Right-click Unknown deviceUpdatedriver Scan the driver folder in Arduino IDE.
For Windows 8/8.1, please refer to PDF file.
For Mac OS/Linux, Skip this slides.
![Page 9: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/9.jpg)
Arduino IDE
![Page 10: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/10.jpg)
Arduino IDE
• An integrated development environment designed for Arduino hardware.
• The language is C++ - like.
• Process of doing Arduino Project:• Connect hardware with Arduino UNO
• Write program on Arduino IDE.
• Download it onto Arduino UNO.
• Power Arduino UNO on and enjoy it.
![Page 11: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/11.jpg)
Arduino IDE
• Structure: two necessary functions:
1. void setup(){}
2. void loop(){}
• The relationship between Arduino Language andC++ Language.
• Important sentence:pinMode (PinNumber,Mode); (general in setup(){};)
digitalWrite (PinNumber, DigitalVoltage);
delay (MiliSeconds);
![Page 12: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/12.jpg)
Lab #1: Light up LED
• Requirement:• Light up LED and keep 3 seconds, than power it off and
keep 3 seconds.
• Repeat the procedure.
• DIY
![Page 13: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/13.jpg)
Quite easy, right?
void setup()
{
//Connect LED resistor on pin 13.pinMode(13,OUTPUT);
}
void loop()
{
digitalWrite(13,HIGH);
delay(5000);
digitalWrite(13,LOW);
delay(5000);
}
![Page 14: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/14.jpg)
Quick Review
• You have controlled the On and Off of LED by control the output voltage of a certain port.
• The voltage on pin 13 is called digital signal, which can be either 1 (logical-high voltage) or 0 (logical-low voltage).
• Actually, Arduino UNO can output/input digital/analog signals.
![Page 15: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/15.jpg)
Sensor(传感器)
• Arduino is like a brain. It also needs ears, eyes, nose, etc. to measure quantities in outside environment.
• Sensor serves as the connection between Arduino and the outside environment.
• So called Feed back control
Temp. Sound
Light …
Environment
![Page 16: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/16.jpg)
Velocity Sensor -- Tachometer
Velocity sensor –Tachometers
Where K is the back EMF constant.
Every car has a tachometer so as to measurer to measure speed.
(t) K (t)t vwV
![Page 17: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/17.jpg)
Temperature Sensor
• Three classes f temperature sensors:• Thermometers and bimetallic strips ---- Sensors which
change physical dimension as a function of temperature.
• RTDs and thermistors ----Sensors which change resistance as a function of temperature.• RTD:
• Thermistor:
• Thermocouples ----Sensors which work based on thermoelectric phenomena
0 0(1 (T T ))R R
0
1 1( )
0
T TR R e
![Page 18: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/18.jpg)
Ultrasonic sensor
• Ultrasonic sensors are used to measure distance.
• An impulse of ultrasonic wave is emitted from the sensor. The wave will reflect when reaches some obstacles. The time between emission and receiving will be calculated.
• Use formula to calculate the distance.
/ 2L Vt
![Page 19: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/19.jpg)
HC-SR04 ultrasonic sensor
• Four pins (GND, VCC, Trig, Echo)
• GND and VCC is the power supply to this module.
• Arduino UNO send message to Trig, and read message from Echo.
![Page 20: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/20.jpg)
Serial Ports (COM,串口) Communication• Serial is one way in which information is transferred
between computer & Arduino.
• Information can also be transferred using Parallel Ports.(并口)
• Two important sentence of serial communication.• Serial.begin(BaudRate); (must be in setup())
• Serial.write(message);
![Page 21: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/21.jpg)
Lab 2: Use ultrasonic sensor to measure distance
Electronic components Number Note
Arduino UNO 1 With USB wire
HC-SR04 Sensor 1
Wires 4
Arduino UNO HC-SR04 Note
GND GND
VCC VCC
A1 (Pin 15) Trig
A0(Pin 14) Echo
Lab equipment:
Wire connection
![Page 22: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/22.jpg)
Program
void loop(){digitalWrite(TrigPin, LOW); delayMicroseconds(2); digitalWrite(TrigPin, HIGH); delayMicroseconds(5); digitalWrite(TrigPin, LOW); cm = int(pulseIn(EchoPin, HIGH) / 58.0);Serial.println(cm);
}
const int TrigPin = 15; const int EchoPin = 14; float cm; void setup(){Serial.begin(9600);pinMode(TrigPin, OUTPUT); pinMode(EchoPin, INPUT);
}
![Page 23: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/23.jpg)
Quick Review
• Sensor: connection between Arduino and outside environment.
• Serial: one way in which information is transferred.
![Page 24: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/24.jpg)
AVR
• AVR is a family of MCU chips which are produced by ATMEL Company.
• The AVR chip on Arduino UNO is Atmega328.
• The AVR chip on Arduino MEGA is Atmega2560
• Working environment:• Stable 5V power supply
• Time reference input
• (RESET)
![Page 25: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/25.jpg)
Atmega328P-PU
• Pin number and counting order.
• Significant pin for working.• Power supply: PIN7,
PIN8, PIN20, PIN22.
• RESET: PIN1
• Timing: PIN9, PIN10
• Serial Ports: PIN2, PIN3
![Page 26: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/26.jpg)
Min. Sys. Of Atmega328P-PU
• Minimum system: MCU chip with simplest peripheral circuit. (外围电路).
• Below is the circuit for min. sys. of Atmega328P.
![Page 27: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/27.jpg)
Lab 3: Min. Sys. Of Atmega328P
• Step 1 Remove the MCU chip on Arduino.
![Page 28: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/28.jpg)
Step 2. Build the minimum system
![Page 29: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/29.jpg)
Step 3 Connect LED and download program• Connect the series of LED and resistor to pin GND
and pin 19.
• Connect the Arduino PCB and your computer as is done in Lab 1.
• Write exactly the same program as in Lab 1 without any change.
• Click the Download button.
• See what happen~~^_^
![Page 30: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/30.jpg)
Step 3 Connect LED and download program• When the download process has been down, you
can remove the RESET line and RX TX line, just leaving the VCC and GND so as to give power to the Atmega328.
![Page 31: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/31.jpg)
A Quick Review
• In the lab 3, we connect the LED to pin GND and Pin 19, but actually in the program we define the Port 13, why?
![Page 32: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/32.jpg)
![Page 33: Lab 2: Arduino - U-M Personal World Wide Web Serverfrankxu/chinese/images/job/engr... · 2017. 12. 24. · Arduino IDE •An integrated development environment designed for Arduino](https://reader035.vdocument.in/reader035/viewer/2022071608/61472496f4263007b135a16b/html5/thumbnails/33.jpg)
Reference
• [1] Arduino Internal, Wheat, Dale.
• [2] Slides of Dr. Huang Peisen.
• [3] www.arduino.cc