Parsing values from Arduino to processing.
in
Integration and Hardware
•
1 year ago
I'm trying to parse my values which i get from my 6 DOF inertial measurement unit , from arduino to processing. So far, following results have been accomplished.
1. Sent the float values as string to processing. Converted them back to float in processing and displayed.
Problem : When i tilt my IMU, the values changes accordingly, but these changes are not affected in processing, but it is successfully affected in arduino serial monitor. There is only slight variation in processing, say from 5.8 to 6.2 when i do a 90 degree tilt, whereas the actual should have been like about 5.8 to 70.4 or something.
This is the code fragment from arduino.
- mpu.dmpGetQuaternion(&q, fifoBuffer);
- mpu.dmpGetEuler(euler, &q);
- Serial.println(euler[0] * 180/M_PI);
- Serial.println(euler[1] * 180/M_PI);
- Serial.println(euler[2] * 180/M_PI);
- import processing.serial.*;
- import processing.opengl.*;
- Serial myPort;
- float[] value=new float[4];
- int i=0;
- int k=100;
- String[] msg=new String[5];
- void setup()
- {
- size(600,600,OPENGL);
- noStroke();
- String portName="COM4";
- myPort = new Serial(this, portName, 115200);
- frameRate(50);
- background(255);
- fill(246, 225, 65);
- lights();
- }
- void draw()
- {
- if(i>2)
- i=0;
- msg[i] = myPort.readStringUntil(13);
- if(msg[i] != null)
- {
- value[i] = float(msg[i]);
- println(value);
- }
- ++i;
- background(255);
- translate(width/2,0);
- fill(0);
- text("Yaw: " + ((float) value[0]), 0, k);
- text("Pitch: " + ((float) value[1]), 100, k);
- text("Roll: " + ((float) value[2]), 200, k);
- }
1