I’ve been mostly working on viz class and pcom mid term over the weekend. One big thing is I once made the eight-buck-deal RF Link work in the studio, but never succeeded in testing again since I went back to the dorm. I used software serial library to utilize digital pins as serial input/output and leave the original serial port for computer monitoring, but the RL Links still feel like a black box to me. The transmitter side looks working perfectly while I hooked up a USB cable and tried to read the TX stream, however the receiver side keeps getting rubbish data. More efforts are to be invested on this issue!!
Just a quick update on the multi-serial-input, shown as the video below (yes I still love my force sensors):
It’s pretty simple, just using two serial inputs. But the concept of encoding data and protocol is pretty clear.
Arduino Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | int leftPin = 4; int rightPin = 5; int leftValue,rightValue; void setup() { beginSerial(9600); //set up communication back to pc } void loop() { leftValue = analogRead(leftPin); rightValue = analogRead(rightPin); //if (abs(leftValue - rightValue) > 50) //{ Serial.print(leftValue,DEC); Serial.print(44,BYTE); Serial.print(rightValue,DEC); Serial.print(44,BYTE); Serial.println(); //} } |
Processing Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | import processing.serial.*; Serial myPort; String data; int leftValue = 0; int rightValue = 0; void setup() { size(800, 600, P3D); directionalLight(126, 126, 126, 0, 0, -1); ambientLight(102, 102, 102); noStroke(); myPort = new Serial(this, Serial.list()[0], 9600); ellipseMode(CENTER); } void draw() { background(0); float leftR = map(leftValue,0,1023,0,PI/2); float rightR = map(rightValue,0,1023,0,PI/2); translate(width/2, height/2); rotateX(-PI/12); rotateZ(rightR - leftR); stroke(160,10); fill(150,150,150,90); box(500,10,100); translate(0,10); noStroke(); fill(255,0,0); translate(map(rightValue - leftValue,-1023,1023,-250,250),-25); sphere(10); } void serialEvent(Serial p) { String input = p.readStringUntil(10); //make sure you return (Ascii 13) at the end of your transmission if (input != null) { String[] parts = input.split(","); //this will only work if you put commas (Ascii 44) between things in your transmission if (parts.length >= 2) { //println("Raw Input: " + input); if (abs(int(parts[0]) - leftValue) > 10) { leftValue = int(parts[0]); } if (abs(int(parts[1]) - rightValue) > 10) { rightValue = int(parts[1]); } } } } |

Post a Comment