Serial Communication
mouseX from computer to arduino processing sends a single byte of data arduino reads each byte arduino uses value to set light brightness Processing In the definitions import processing.serial.*; Serial port; In the setup println("Available serial ports:"); println(Serial.list()); port = new Serial(this, Serial.list()[0], 9600); In the draw port.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 arduino processing sends a single letter arduino reads and checks the letter arduino uses value as switch for light Processing In the definitions import processing.serial.*; Serial port; In the setup println("Available serial ports:"); println(Serial.list()); port = new Serial(this, Serial.list()[0], 9600); In the draw If…. {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 computer arduino sends a single byte from sensor processing stores the byte processing uses value to draw line length Processing In the definitions import processing.serial.*; Serial port; In the setup println("Available serial ports:"); println(Serial.list()); port = new Serial(this, Serial.list()[0], 9600); In the draw - NOTHING void 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);
Processing In the definitions import processing.serial.*; Serial port; In the setup println("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 computer arduino sends data from sensor processing reads data up to new line, cleans, stores data processing uses value to draw line length
Processing import 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 loop sensorValue = 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 computer arduino sends data from sensor processing reads data up to new line, splits, cleans, stores data processing uses value to draw line length
two options Punctuation or Call and response
firmata read and write to arduino sensors and actuators directly from processing (download and add firmata folder to arduino/hardware/Iibraries) load firmata to the arduino via usb download and add arduino folder to processing/libraries make read and write calls to the arduino from processing
data Internet data - use xml library
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
Wireless set 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 pad Wii controller arduino-class-notes-3-4/