phylab.fudan.edu.cn

Download Report

Transcript phylab.fudan.edu.cn

Introduction to Arduino
朱骏
s(at)zhujunsan.net
2015/7/17
What is arduino
Bridge between computer world and real world
• Develop interactive objects
• Taking inputs from switches, sensors and more
• Controlling a variety of lights, motors, and
other physical outputs
Why Arduino?
• Inexpensive
• Cross-platform
• Open source
• Simple
• Healthy community
So, what is arduino?
Hardware: Arduino board
and there are many more:
arduino.cc/en/Main/Products
Software: Arduino IDE
Arduino board: Arduino Uno (front)
Reset
digital input/output
USB port
Main chip
power plug
(7-12V)
power pins
analog input
Arduino board: Arduino Uno (back)
Arduino IDE
• Newest version can be downloaded at:
http://arduino.cc/en/Main/Software
• After unpack, run the arduino
(yes that’s it! No need to install)
Arduino IDE
Compile Upload
New
Open
Save
Edit area
Output area
Serial monitor
Language structure
void setup()
{
// your setup codes
// this function runs only once
}
void
{
//
//
//
}
loop()
you main program codes
this loop will run until
you cut the power
Basic functions
pinMode(pin, mode)
digitalWrite(pin, value)
int digitalRead(pin)
int analogRead(pin)
analogWrite(pin, value)
delay(ms)
Example: 01.Basics -> Blink
// Pin 13 has an LED connected on Arduino
boards, give it a name
int led = 13;
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
void loop() {
digitalWrite(led, HIGH); // turn the LED on
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off
delay(1000); // wait for a second
}
Put it together
1. Download the Arduino IDE and unpack it;
2. Plug your Arduino to the computer;
(Driver for the Arduino Uno can be found at {Arduino IDE}\driver folder)
3. Open the IDE and start coding…
4. After done coding, choose the corresponding board
and serial port number;
5. Compile (optional but recommended) then upload to
your board;
6. Done, go have fun!
More to read (websites)
• Getting Started with Arduino
http://arduino.cc/en/Guide/HomePage
• Language Reference
http://arduino.cc/en/Reference/HomePage
• phylab: Arduino单片机基础及应用开发
http://phylab.fudan.edu.cn/doku.php?id=yuandi:arduino:start
(登录后可在最下方讨论区留言讨论)
More to read (books)
• “Arduino programming notebook”
• “Getting start with arduino”
• “Programming interactivity”
Thank you all for your listening!
朱骏
s(at)zhujunsan.net
7/17/2015