Serial Communication. mouseX from computer to arduino processing sends a single byte of data arduino...
-
Upload
avice-parks -
Category
Documents
-
view
214 -
download
0
Transcript of Serial Communication. mouseX from computer to arduino processing sends a single byte of data arduino...
![Page 1: 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.](https://reader035.fdocuments.in/reader035/viewer/2022081816/5697bf751a28abf838c8000c/html5/thumbnails/1.jpg)
Serial Communication
![Page 2: 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.](https://reader035.fdocuments.in/reader035/viewer/2022081816/5697bf751a28abf838c8000c/html5/thumbnails/2.jpg)
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);
}
![Page 3: 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.](https://reader035.fdocuments.in/reader035/viewer/2022081816/5697bf751a28abf838c8000c/html5/thumbnails/3.jpg)
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);}
}
![Page 4: 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.](https://reader035.fdocuments.in/reader035/viewer/2022081816/5697bf751a28abf838c8000c/html5/thumbnails/4.jpg)
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);
![Page 5: 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.](https://reader035.fdocuments.in/reader035/viewer/2022081816/5697bf751a28abf838c8000c/html5/thumbnails/5.jpg)
• 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
![Page 6: 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.](https://reader035.fdocuments.in/reader035/viewer/2022081816/5697bf751a28abf838c8000c/html5/thumbnails/6.jpg)
• 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
![Page 7: 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.](https://reader035.fdocuments.in/reader035/viewer/2022081816/5697bf751a28abf838c8000c/html5/thumbnails/7.jpg)
two options
Punctuation
or
Call and response
![Page 8: 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.](https://reader035.fdocuments.in/reader035/viewer/2022081816/5697bf751a28abf838c8000c/html5/thumbnails/8.jpg)
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
![Page 9: 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.](https://reader035.fdocuments.in/reader035/viewer/2022081816/5697bf751a28abf838c8000c/html5/thumbnails/9.jpg)
data
• Internet data - use xml library
• http://www.pachube.com/
![Page 10: 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.](https://reader035.fdocuments.in/reader035/viewer/2022081816/5697bf751a28abf838c8000c/html5/thumbnails/10.jpg)
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
![Page 11: 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.](https://reader035.fdocuments.in/reader035/viewer/2022081816/5697bf751a28abf838c8000c/html5/thumbnails/11.jpg)
Wirelessset up xbee parameters in zterm
![Page 12: 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.](https://reader035.fdocuments.in/reader035/viewer/2022081816/5697bf751a28abf838c8000c/html5/thumbnails/12.jpg)
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)
![Page 13: 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.](https://reader035.fdocuments.in/reader035/viewer/2022081816/5697bf751a28abf838c8000c/html5/thumbnails/13.jpg)
![Page 14: 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.](https://reader035.fdocuments.in/reader035/viewer/2022081816/5697bf751a28abf838c8000c/html5/thumbnails/14.jpg)
extras
• lilly padhttp://web.media.mit.edu/~leah/LilyPad/
• Wii controller
http://todbot.com/blog/2007/11/24/bionic-arduino-class-notes-3-4/