Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Eoin Brazil
http://www.flickr.com/photos/collinmel/2317520331/
The development
The hardware The community
environment
Why Arduino?
=
Intel 286 Arduino
16 kBytes of Flash program memory
1 kByte of RAM
16 MHz (Apple II: 1 MHz / Intel 286: 12.5 MHz / Intel Core 2: 3 GHz)
inputs and outputs
13 digital input/output pins
5 analog input pins
6 analog output pins (PWM only)
Digital I/O can read switches and buttons, control LEDs and motors
Analog input can read knobs or other varying sensors
Analog output can be done with PWM
Layout of an Arduino
Digital Ground (light green) Reset Button - S1 (dark blue) Toggles External Power and USB
Digital Pins 2-13 (green) In-circuit Serial Programmer (blue- Power (place jumper on two pins
Digital Pins 0-1/Serial In/Out - TX/ green) closest to desired supply) - SV1
RX (dark green) Analog Reference pin (orange) (purple)
These pins cannot be used for Analog In Pins 0-5 (light blue) USB (used for uploading sketches
digital i/o (digitalRead and Power and Ground Pins (power: to the board and for serial
digitalWrite) if you are also orange, grounds: light orange) communication between the board
using serial communiation (e.g. External Power Supply In and the computer; can be used to
Serial.begin). (9-12VDC) - X1 (pink) power the board) (yellow)
Arduino Glossary
Bluetooth - BlueSmirf
Internet - MatchPort
Many others:
Wifi, IrDa, Zigbee, etc.
Arduino Connections
Motors:
DC, Steppers, Servos
Arduino Connections
Sensors:
Flex, IrDa, Switches,
FSR, Accelerometers
Arduino Connections
Custom Hardware:
e.g.VMusic 2 MP3 player
Lilypad
http://www.cs.colorado.edu/~buechley/diy/diy_lilypad_arduino.html
A Construction Kit for Electronic Textiles - IEEE International Symposium on Wearable Computers (ISWC) 2006.
Existing Toolkits
Existing Toolkits
Expensive but
user friendly
Existing Toolkits
Expensive but
user friendly
Sufficient for
almost all needs
Existing Toolkits
Expensive but
user friendly
Chips and
Sufficient for PCBs
almost all needs
Cost / Difficulty
Tradeoff
ATMega168
Cost / Difficulty
Tradeoff
ATMega168
Approx.
~€250
Cost / Difficulty
Tradeoff
Approx.
~€25
ATMega168
Approx.
~€250
Cost / Difficulty
Tradeoff
Approx.
~€25
ATMega168
Approx.
Approx. ~€4
~€250
Development Style
Opportunistic
Development
Development Style
Big / Heavyweight
Software
Development Style
Dovetails / Tight
Integration
Development Style
Definition: A Mash-up is a
combination of existing
technologies glued together
to create new functionality
Examples
Accelerometer & RGB
LED
int xAccelPin = 0; // select the input pin for the x accelermoter details
int yAccelPin = 1; // select the input pin for the y accelermoter details
int zAccelPin = 2; // select the input pin for the z accelermoter details
int x_val = 0; // variable to store the value coming from the sensor
int y_val = 0; // variable to store the value coming from the sensor
int z_val = 0; // variable to store the value coming from the sensor
int red_val = 0; // variable to store the value coming from the sensor
int green_val = 0; // variable to store the value coming from the sensor
int blue_val = 0; // variable to store the value coming from the sensor
void setup() {
pinMode(redPin, OUTPUT); // sets the pins as output
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
analogWrite(redPin, 127); // set them all to mid brightness
analogWrite(greenPin, 127); // set them all to mid brightness
analogWrite(bluePin, 127); // set them all to mid brightness
Serial.begin(9600);
}
void loop() {
x_val = analogRead(xAccelPin); // read the value from the sensor
y_val = analogRead(yAccelPin); // read the value from the sensor
z_val = analogRead(zAccelPin); // read the value from the sensor
Serial.print(x_val);
Serial.print(" ");
Serial.print(y_val);
Serial.print(" ");
Serial.println(z_val);
delay(100);
}
Accelerometer & RGB
LED
int xAccelPin = 0; // select the input pin for the x accelermoter details
int yAccelPin = 1; // select the input pin for the y accelermoter details
int zAccelPin = 2; // select the input pin for the z accelermoter details
int x_val = 0; // variable to store the value coming from the sensor
int y_val = 0; // variable to store the value coming from the sensor
int z_val = 0; // variable to store the value coming from the sensor
int red_val = 0; // variable to store the value coming from the sensor
int green_val = 0; // variable to store the value coming from the sensor
int blue_val = 0; // variable to store the value coming from the sensor
void setup() {
pinMode(redPin, OUTPUT); // sets the pins as output
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
analogWrite(redPin, 127); // set them all to mid brightness
analogWrite(greenPin, 127); // set them all to mid brightness
analogWrite(bluePin, 127); // set them all to mid brightness
Serial.begin(9600);
}
void loop() {
x_val = analogRead(xAccelPin); // read the value from the sensor
y_val = analogRead(yAccelPin); // read the value from the sensor
z_val = analogRead(zAccelPin); // read the value from the sensor
Serial.print(x_val);
Serial.print(" ");
Serial.print(y_val);
Serial.print(" ");
Serial.println(z_val);
delay(100);
}
Hanging Gardens -
Another Example
Hanging Gardens -
Another Example
Hanging Gardens:
Collaboration with Jürgen Simpson
2 field of insects
Circadian rhythm
Botanicalls
Sensors to
Arduino
Arduino to
XPort to Twitter
SL to RL
LSL script for SL
objects
LSL to PHP
webserver with
connected Arduino
PHP to Arduino’s
serial port
Write program
Compile (check
for errors)
Reset board
Upload to board
pinMode()
digitalWrite() / digitalRead()
analogRead() / analogWrite()
delay()
millis()
Input / Output
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
Serial.begin(19200); // initiate serial communication
}
void loop()
{
while (Serial.available()>0) {
inByte = Serial.read();
}
if (inByte>0) {
digitalWrite(ledPin, HIGH); // sets the LED on
} else {
digitalWrite(ledPin, LOW); // sets the LED off
}
}
Blinking LED
void setup()
{
variables
pinMode(ledPin, OUTPUT); // sets the digital pin as output
Serial.begin(19200); // initiate serial communication
}
void loop()
{
while (Serial.available()>0) {
inByte = Serial.read();
}
if (inByte>0) {
digitalWrite(ledPin, HIGH); // sets the LED on
} else {
digitalWrite(ledPin, LOW); // sets the LED off
}
}
Blinking LED
void loop()
{
while (Serial.available()>0) {
inByte = Serial.read();
}
if (inByte>0) {
digitalWrite(ledPin, HIGH); // sets the LED on
} else {
digitalWrite(ledPin, LOW); // sets the LED off
}
}
Blinking LED
void loop()
{
while (Serial.available()>0) {
inByte = Serial.read();
}
if (inByte>0) {
digitalWrite(ledPin, HIGH); // sets the LED on
} else {
digitalWrite(ledPin, LOW); // sets the LED off
}
}
Push button LED
/* Digital reading, turns on and off a light emitting diode (LED) connected to digital
* pin 13, when pressing a pushbutton attached to pin 7. It illustrates the concept of
* Active-Low, which consists in connecting buttons using a 1K to 10K pull-up resistor.
*/
void setup() {
pinMode(ledPin, OUTPUT); // set LED as output
pinMode(inPin, INPUT); // set pushbutton as input
Serial.begin(19200); // start serial communication to computer
}
void loop() {
buttonval = digitalRead(inPin); // read the pin and get the button's state
if (buttonval == HIGH) { // check if the input is HIGH (button released)
digitalWrite(ledPin, LOW); // turn LED OFF
Serial.write('0'); // Button off (0) sent to computer
} else {
digitalWrite(ledPin, HIGH); // turn LED ON
Serial.write('1'); // Button on (1) sent to computer
}
}
Push button LED
/* Digital reading, turns on and off a light emitting diode (LED) connected to digital
* pin 13, when pressing a pushbutton attached to pin 7. It illustrates the concept of
* Active-Low, which consists in connecting buttons using a 1K to 10K pull-up resistor.
*/
void loop() {
buttonval = digitalRead(inPin); // read the pin and get the button's state
if (buttonval == HIGH) { // check if the input is HIGH (button released)
digitalWrite(ledPin, LOW); // turn LED OFF
Serial.write('0'); // Button off (0) sent to computer
} else {
digitalWrite(ledPin, HIGH); // turn LED ON
Serial.write('1'); // Button on (1) sent to computer
}
}
Push button LED
/* Digital reading, turns on and off a light emitting diode (LED) connected to digital
* pin 13, when pressing a pushbutton attached to pin 7. It illustrates the concept of
Setup LED pin,
* Active-Low, which consists in connecting buttons using a 1K to 10K pull-up resistor.
*/
int ledPin = 13; // choose the pin for the LED switch pin and
int inPin = 7; // choose the input pin (button)
int buttonval = 0; // variable for reading the pin status serial connection
void setup() {
pinMode(ledPin, OUTPUT); // set LED as output
pinMode(inPin, INPUT); // set pushbutton as input
Serial.begin(19200); // start serial communication to computer
}
void loop() {
buttonval = digitalRead(inPin); // read the pin and get the button's state
if (buttonval == HIGH) { // check if the input is HIGH (button released)
digitalWrite(ledPin, LOW); // turn LED OFF
Serial.write('0'); // Button off (0) sent to computer
} else {
digitalWrite(ledPin, HIGH); // turn LED ON
Serial.write('1'); // Button on (1) sent to computer
}
}
Push button LED
/* Digital reading, turns on and off a light emitting diode (LED) connected to digital
* pin 13, when pressing a pushbutton attached to pin 7. It illustrates the concept of
* Active-Low, which consists in connecting buttons using a 1K to 10K pull-up resistor.
*/
Loop - Reading the
int ledPin = 13; // choose the pin for the LED
int inPin = 7; // choose the input pin (button)
button for info, when
int buttonval = 0; // variable for reading the pin status button is press turn
void setup() { the LED on and signal
pinMode(ledPin, OUTPUT); // set LED as output
pinMode(inPin, INPUT); // set pushbutton as input the computer of
Serial.begin(19200); // start serial communication to computer change
}
void loop() {
buttonval = digitalRead(inPin); // read the pin and get the button's state
if (buttonval == HIGH) { // check if the input is HIGH (button released)
digitalWrite(ledPin, LOW); // turn LED OFF
Serial.write('0'); // Button off (0) sent to computer
} else {
digitalWrite(ledPin, HIGH); // turn LED ON
Serial.write('1'); // Button on (1) sent to computer
}
}
Useful Stuff
Protocols and Proxies
http://www.digitalartistshandbook.org/node/10
Suggested Books
Useful Links
Arduino - http://www.arduino.cc/
Lilypad - http://www.cs.colorado.edu/~buechley/diy/
diy_lilypad_arduino.html