Upload
avice-parks
View
214
Download
0
Embed Size (px)
Citation preview
Serial Communication
mouseX from computer to arduinoprocessing sends a single byte of data
arduino reads each bytearduino uses value to set light brightness
• ProcessingIn the definitionsimport processing.serial.*;Serial port;In the setupprintln("Available serial ports:");println(Serial.list());port = new Serial(this, Serial.list()[0], 9600); In the drawport.write(mouseX);
• Arduino
In the setup
Serial.begin(9600);
In the loop
byte brightness;
if (Serial.available()) {
brightness = Serial.read();
analogWrite(ledPin, brightness);
}
keystrokes from computer to arduinoprocessing sends a single letter
arduino reads and checks the letter arduino uses value as switch for light
• ProcessingIn the definitionsimport processing.serial.*;Serial port;In the setupprintln("Available serial ports:");println(Serial.list());port = new Serial(this, Serial.list()[0], 9600); In the drawIf….{port.write(‘H’);}else….{port.write(‘L’);}
• Arduino
In the setup
Serial.begin(9600);
In the loop
int inLetter;
if (Serial.available()) {
inLetter = Serial.read();
If (inLetter == ‘H’){
digitalWrite(ledPin, HIGH);}
}
single data byte from arduino to computerarduino sends a single byte from sensor
processing stores the byteprocessing uses value to draw line length
• ProcessingIn the definitionsimport processing.serial.*;Serial port;In the setupprintln("Available serial ports:");println(Serial.list());port = new Serial(this, Serial.list()[0], 9600); In the draw - NOTHINGvoid serialEvent (Serial port) {int inByte = port.read(); line(graphXPos, height, graphXPos, height - inByte);}
• Arduino
In the setup
Serial.begin(9600);
In the loop
val = analogRead(sensorPin);
val = val/4;
Serial.print(val, BYTE);
• ProcessingIn the definitionsimport processing.serial.*;Serial port;In the setupprintln("Available serial ports:");println(Serial.list());port = new Serial(this, Serial.list()[0], 9600);port.bufferUntil('\n'); void serialEvent (Serial port)String inString = port.readStringUntil('\n');if (inString != null) {inString = trim(inString);float inByte = float(inString); inByte = map(inByte, 0, 1023, 0, height);line(xPos, height, xPos, height - inByte);
• Arduino
In the setup
Serial.begin(9600);
In the loop Serial.println(analogRead(0));
single data string from arduino to computerarduino sends data from sensor
processing reads data up to new line, cleans, stores dataprocessing uses value to draw line length
• Processingimport processing.serial.*;Serial myPort; void setup() {myPort = new Serial(this, Serial.list()[0], 9600);myPort.bufferUntil('\n');}void draw() {fill(fgcolor);ellipse(xpos, ypos, 20, 20);}void serialEvent(Serial myPort) { String myString = myPort.readStringUntil('\n');if (myString != null) { myString = trim(myString); int sensors[] = int(split(myString, ',')); if (sensors.length > 1) { xpos = map(sensors[0], 0,1023,0,width); ypos = map(sensors[1], 0,1023,0,height); fgcolor = sensors[2] * 255; }}}
• Arduino
In the setup
Serial.begin(9600);
In the loopsensorValue = analogRead(analogOne);Serial.print(sensorValue, DEC);Serial.print(",");sensorValue = analogRead(analogTwo);Serial.print(sensorValue, DEC);Serial.print(",");sensorValue = digitalRead(digitalOne);Serial.println(sensorValue, DEC);
multiple data strings from arduino to computerarduino sends data from sensor
processing reads data up to new line, splits, cleans, stores dataprocessing uses value to draw line length
two options
Punctuation
or
Call and response
firmataread and write to arduino sensors and actuators directly from processing
• (download and add firmata folder to arduino/hardware/Iibraries)
http://at.or.at/hans/pd/objects.html#pduino
• load firmata to the arduino via usb
• download and add arduino folder to processing/libraries
http://www.arduino.cc/playground/Interfacing/Processing
• make read and write calls to the arduino from processing
data
• Internet data - use xml library
• http://www.pachube.com/
rfid
•Arduino serial RX to Parallax TX•Arduino GND to Parallax GND•Arduino digital pin (i.e. #2) to Parallax /ENABLE•Arduino +5V to Parallax Vcc
Wirelessset up xbee parameters in zterm
midi
three pieces of information sent in midi message:
the action (note on, note off, pitch bend, etc.)
the pitch (plain old musical pitch)
the velocity (basically, how loud you want the sound to play)
extras
• lilly padhttp://web.media.mit.edu/~leah/LilyPad/
• Wii controller
http://todbot.com/blog/2007/11/24/bionic-arduino-class-notes-3-4/