Arduino Nano v3 + GY-521 (acc+gyro) --> Processing --> CSV, can't get it to work
dear all,
for school project have acceleration , filtered angle data acc+gyro (gy-521) sensor excel analyze them. use arduino nano v3 , macbook lion - osx 10.7.5. today (for quick test) hoping let processing create simple csv y-accelerations in there, 1 on each row, can't work... processing sketch make csv file, it's it's empty , it's showing right values so:
-50,32
30,00
20
1,00
294,90
etc
it splits 201,00 somewhere in middle , adds empty line.
now question is: how possible writes empty file , filled file. , why filled jump @ random places next line? looks it's not in sync??! serial monitor of arduino environment gives perfect rows of values..
can me? much!
this processing sketch used:
and arduino code (part of complete code):
for school project have acceleration , filtered angle data acc+gyro (gy-521) sensor excel analyze them. use arduino nano v3 , macbook lion - osx 10.7.5. today (for quick test) hoping let processing create simple csv y-accelerations in there, 1 on each row, can't work... processing sketch make csv file, it's it's empty , it's showing right values so:
-50,32
30,00
20
1,00
294,90
etc
it splits 201,00 somewhere in middle , adds empty line.
now question is: how possible writes empty file , filled file. , why filled jump @ random places next line? looks it's not in sync??! serial monitor of arduino environment gives perfect rows of values..
can me? much!
this processing sketch used:
code: [select]
import processing.serial.*;
serial myserial;
printwriter output;
//float accel_y;
void setup() {
myserial = new serial( this, serial.list()[1], 19200 );
output = createwriter( "documents/datalaumann5.txt" );
}
void draw() {
if (myserial.available() > 0 ) {
string accel_y = myserial.readstring();
if ( accel_y != null ) {
output.println(accel_y);
}
}
}
void keypressed() {
output.flush(); // writes remaining data file
output.close(); // finishes file
exit(); // stops program
}
and arduino code (part of complete code):
code: [select]
float accel_y;
}
void setup()
{
int error;
uint8_t c;
serial.begin(19200);
/*
serial.println(f("invensense mpu-6050"));
serial.println(f("june 2012"));
*/
// initialize 'wire' class i2c-bus.
wire.begin();
// default @ power-up:
// gyro @ 250 degrees second
// acceleration @ 2g
// clock source @ internal 8mhz
// device in sleep mode.
//
error = mpu6050_read (mpu6050_who_am_i, &c, 1);
/*
serial.print(f("who_am_i : "));
serial.print(c,hex);
serial.print(f(", error = "));
serial.println(error,dec);
*/
// according datasheet, 'sleep' bit
// should read '1'. read '0'.
// bit has cleared, since sensor
// in sleep mode @ power-up. if the
// bit reads '0'.
error = mpu6050_read (mpu6050_pwr_mgmt_2, &c, 1);
/*
serial.print(f("pwr_mgmt_2 : "));
serial.print(c,hex);
serial.print(f(", error = "));
serial.println(error,dec);
*/
// clear 'sleep' bit start sensor.
mpu6050_write_reg (mpu6050_pwr_mgmt_1, 0);
//initialize angles
calibrate_sensors();
set_last_read_angle_data(millis(), 0, 0, 0, 0, 0, 0);
}
void loop()
{
int error;
double dt;
accel_t_gyro_union accel_t_gyro;
/*
serial.println(f(""));
serial.println(f("mpu-6050"));
*/
// read raw values.
error = read_gyro_accel_vals((uint8_t*) &accel_t_gyro);
// time of reading rotation computations
unsigned long t_now = millis();
// convert gyro values degrees/sec
float fs_sel = 131;
/*
float gyro_x = (accel_t_gyro.value.x_gyro - base_x_gyro)/fs_sel;
float gyro_y = (accel_t_gyro.value.y_gyro - base_y_gyro)/fs_sel;
float gyro_z = (accel_t_gyro.value.z_gyro - base_z_gyro)/fs_sel;
*/
float gyro_x = (accel_t_gyro.value.x_gyro - base_x_gyro)/fs_sel;
float gyro_y = (accel_t_gyro.value.y_gyro - base_y_gyro)/fs_sel;
float gyro_z = (accel_t_gyro.value.z_gyro - base_z_gyro)/fs_sel;
// raw acceleration values
//float g_convert = 16384;
float accel_x = accel_t_gyro.value.x_accel;
float accel_y = accel_t_gyro.value.y_accel;
float accel_z = accel_t_gyro.value.z_accel;
// angle values accelerometer
float radians_to_degrees = 180/3.14159;
// float accel_vector_length = sqrt(pow(accel_x,2) + pow(accel_y,2) + pow(accel_z,2));
float accel_angle_y = atan(-1*accel_x/sqrt(pow(accel_y,2) + pow(accel_z,2)))*radians_to_degrees;
float accel_angle_x = atan(accel_y/sqrt(pow(accel_x,2) + pow(accel_z,2)))*radians_to_degrees;
float accel_angle_z = 0;
// compute (filtered) gyro angles
float dt =(t_now - get_last_time())/1000.0;
float gyro_angle_x = gyro_x*dt + get_last_x_angle();
float gyro_angle_y = gyro_y*dt + get_last_y_angle();
float gyro_angle_z = gyro_z*dt + get_last_z_angle();
// compute drifting gyro angles
float unfiltered_gyro_angle_x = gyro_x*dt + get_last_gyro_x_angle();
float unfiltered_gyro_angle_y = gyro_y*dt + get_last_gyro_y_angle();
float unfiltered_gyro_angle_z = gyro_z*dt + get_last_gyro_z_angle();
// apply complementary filter figure out change in angle - choice of alpha is
// estimated now. alpha depends on sampling rate...
float alpha = 0.96;
float angle_x = alpha*gyro_angle_x + (1.0 - alpha)*accel_angle_x;
float angle_y = alpha*gyro_angle_y + (1.0 - alpha)*accel_angle_y;
float angle_z = gyro_angle_z; //accelerometer doesn't give z-angle
// update saved data latest values
set_last_read_angle_data(t_now, angle_x, angle_y, angle_z, unfiltered_gyro_angle_x, unfiltered_gyro_angle_y, unfiltered_gyro_angle_z);
// send data serial port
/*
serial.print(f("del:")); //delta t
serial.print(dt, dec);
serial.print(f("#acc:")); //accelerometer angle
serial.print(accel_angle_x, 2);
serial.print(f(","));
serial.print(accel_angle_y, 2);
serial.print(f(","));
serial.print(accel_angle_z, 2);
serial.print(f("#gyr:"));
serial.print(unfiltered_gyro_angle_x, 2); //gyroscope angle
serial.print(f(","));
serial.print(unfiltered_gyro_angle_y, 2);
serial.print(f(","));
serial.print(unfiltered_gyro_angle_z, 2);
serial.print(f("#fil:")); //filtered angle
serial.print(angle_x, 2);
serial.print(f(","));
serial.print(angle_y, 2);
serial.print(f(","));
serial.print(angle_z, 2);
serial.println(f(""));
*/
serial.println(accel_y);
// delay don't swamp serial port
//delay(200);
}
code: [select]
string accel_y = myserial.readstring();
what, exactly, defines string? makes readstring() stop reading?
you should have serialevent() function, instead of doing serial reading in draw().
you should have myserial.bufferuntil() statement in setup(), define when trigger serialevent() method, , should use readbytesuntil() in serialevent().
Arduino Forum > Using Arduino > Interfacing w/ Software on the Computer > Arduino Nano v3 + GY-521 (acc+gyro) --> Processing --> CSV, can't get it to work
arduino
Comments
Post a Comment