Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 Serial Communication

2 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); }

3 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);} }

4 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);

5 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

6 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

7 two options Punctuation or Call and response

8 firmata read 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

9 data Internet data - use xml library http://www.pachube.com/

10 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

11 Wireless set up xbee parameters in zterm

12 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)

13

14 extras lilly pad http://web.media.mit.edu/~leah/LilyPad/ Wii controller http://todbot.com/blog/2007/11/24/bionic- arduino-class-notes-3-4/


Download ppt "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."

Similar presentations


Ads by Google