issues with Uno R3 using FreeIMU v0.4, MPU6050, and Processing
hello all. bought mpu-6050 use uno r3.
heres specific board i'm using: https://www.sparkfun.com/products/11028
and have connected so:
vdd - arduino 3.3v
gnd - arduino gnd
int - arduino digital pin 2
fsync - leave unconnected
scl - arduino scl (dedicated pin or analog 5)
sda - arduino sda (dedicated pin or analog 4)
vio - arduino 3.3v
clk - leave unconnected
ascl - leave unconnected
asda - leave unconnected
i followed beginner guide: http://playground.arduino.cc/main/mpu-6050got working little effort.
after tried using guide includes using ide "processing" visual representation in 3d space: http://www.varesano.net/blog/fabio/initial-tests-freeimu-v04-and-mpu6050
this i'm running issues. in video turns arduino mpu6050, rectangle on screen moves accordingly.
when i'm using arduino , mpu6050, "processing" rectangle on screen free floating, me moving actual chip around has no effect on it.
heres code i'm using on arduino, freeimu_quaternion example sketch:
and here's i'm using in processing:
i'm using freeimu example quaternion uploaded uno, installed libraries in freeimu, , processing sketch provides on blog. compiles fine on end, when visual representation in processing rectangle free floating, , fabios reacts arduino/mpu6050's position.
any insight appreciated
heres specific board i'm using: https://www.sparkfun.com/products/11028
and have connected so:
vdd - arduino 3.3v
gnd - arduino gnd
int - arduino digital pin 2
fsync - leave unconnected
scl - arduino scl (dedicated pin or analog 5)
sda - arduino sda (dedicated pin or analog 4)
vio - arduino 3.3v
clk - leave unconnected
ascl - leave unconnected
asda - leave unconnected
i followed beginner guide: http://playground.arduino.cc/main/mpu-6050got working little effort.
after tried using guide includes using ide "processing" visual representation in 3d space: http://www.varesano.net/blog/fabio/initial-tests-freeimu-v04-and-mpu6050
this i'm running issues. in video turns arduino mpu6050, rectangle on screen moves accordingly.
when i'm using arduino , mpu6050, "processing" rectangle on screen free floating, me moving actual chip around has no effect on it.
heres code i'm using on arduino, freeimu_quaternion example sketch:
code: [select]
#include <adxl345.h>
#include <bma180.h>
#include <hmc58x3.h>
#include <itg3200.h>
#include <ms561101ba.h>
#include <i2cdev.h>
#include <mpu60x0.h>
#include <eeprom.h>
//#define debug
#include "debugutils.h"
#include "communicationutils.h"
#include "freeimu.h"
#include <wire.h>
#include <spi.h>
float q[4];
// set freeimu object
freeimu my3imu = freeimu();
void setup() {
serial.begin(115200);
wire.begin();
delay(5);
my3imu.init();
delay(5);
}
void loop() {
my3imu.getq(q);
serialprintfloatarr(q, 4);
serial.println("");
delay(20);
}
and here's i'm using in processing:
code: [select]
/**
visualize cube assumes orientation described
in quaternion coming serial port.
instructions:
this program has run when have freeimu_quaternion
program running on arduino , arduino connected pc.
remember set serialport variable below point name the
arduino serial port has in system. can port using the
arduino ide tools->serial port: selected entry have
to use serialport variable.
copyright (c) 2011 fabio varesano - http://www.varesano.net/
this program free software: can redistribute and/or modify
it under terms of version 3 gnu general public license as
published free software foundation.
this program distributed in hope useful,
but without warranty; without implied warranty of
merchantability or fitness particular purpose. see the
gnu general public license more details.
you should have received copy of gnu general public license
along program. if not, see <http://www.gnu.org/licenses/>.
*/
import processing.serial.*;
serial myport; // create object serial class
final string serialport = "/dev/tty.usbmodem1411"; // replace serial port. on windows need "com1".
float [] q = new float [4];
float [] hq = null;
float [] euler = new float [3]; // psi, theta, phi
int lf = 10; // 10 '\n' in ascii
byte[] inbuffer = new byte[22]; // number of chars on each line arduino (including /r/n)
pfont font;
final int view_size_x = 1024, view_size_y = 768;
void setup()
{
size(view_size_x, view_size_y, p3d);
myport = new serial(this, serialport, 115200);
// font must located in sketch's "data" directory load successfully
font = loadfont("couriernew36.vlw");
/*
float [] axis = new float[3];
axis[0] = 0.0;
axis[1] = 0.0;
axis[2] = 1.0;
float angle = pi/2.0;
hq = quataxisangle(axis, angle);
hq = new float[4];
hq[0] = 0.0;
hq[1] = 0.0;
hq[2] = 0.0;
hq[3] = 1.0;
*/
delay(100);
myport.clear();
myport.write("1");
}
float decodefloat(string instring) {
byte [] indata = new byte[4];
if(instring.length() == 8) {
indata[0] = (byte) unhex(instring.substring(0, 2));
indata[1] = (byte) unhex(instring.substring(2, 4));
indata[2] = (byte) unhex(instring.substring(4, 6));
indata[3] = (byte) unhex(instring.substring(6, 8));
}
int intbits = (indata[3] << 24) | ((indata[2] & 0xff) << 16) | ((indata[1] & 0xff) << 8) | (indata[0] & 0xff);
return float.intbitstofloat(intbits);
}
void readq() {
if(myport.available() >= 18) {
string inputstring = myport.readstringuntil('\n');
//print(inputstring);
if (inputstring != null && inputstring.length() > 0) {
string [] inputstringarr = split(inputstring, ",");
if(inputstringarr.length >= 5) { // q1,q2,q3,q4,\r\n have 5 elements
q[0] = decodefloat(inputstringarr[0]);
q[1] = decodefloat(inputstringarr[1]);
q[2] = decodefloat(inputstringarr[2]);
q[3] = decodefloat(inputstringarr[3]);
}
}
}
}
void buildboxshape() {
//box(60, 10, 40);
nostroke();
beginshape(quads);
//z+ (to drawing area)
fill(#00ff00);
vertex(-30, -5, 20);
vertex(30, -5, 20);
vertex(30, 5, 20);
vertex(-30, 5, 20);
//z-
fill(#0000ff);
vertex(-30, -5, -20);
vertex(30, -5, -20);
vertex(30, 5, -20);
vertex(-30, 5, -20);
//x-
fill(#ff0000);
vertex(-30, -5, -20);
vertex(-30, -5, 20);
vertex(-30, 5, 20);
vertex(-30, 5, -20);
//x+
fill(#ffff00);
vertex(30, -5, -20);
vertex(30, -5, 20);
vertex(30, 5, 20);
vertex(30, 5, -20);
//y-
fill(#ff00ff);
vertex(-30, -5, -20);
vertex(30, -5, -20);
vertex(30, -5, 20);
vertex(-30, -5, 20);
//y+
fill(#00ffff);
vertex(-30, 5, -20);
vertex(30, 5, -20);
vertex(30, 5, 20);
vertex(-30, 5, 20);
endshape();
}
void drawcube() {
pushmatrix();
translate(view_size_x/2, view_size_y/2 + 50, 0);
scale(5,5,5);
// demonstration of following @
// http://www.varesano.net/blog/fabio/ahrs-sensor-fusion-orientation-filter-3d-graphical-rotating-cube
rotatez(-euler[2]);
rotatex(-euler[1]);
rotatey(-euler[0]);
buildboxshape();
popmatrix();
}
void draw() {
background(#000000);
fill(#ffffff);
readq();
if(hq != null) { // use home quaternion
quaterniontoeuler(quatprod(hq, q), euler);
text("disable home position pressing \"n\"", 20, view_size_y - 30);
}
else {
quaterniontoeuler(q, euler);
text("point freeimu's x axis monitor press \"h\"", 20, view_size_y - 30);
}
textfont(font, 20);
textalign(left, top);
text("q:\n" + q[0] + "\n" + q[1] + "\n" + q[2] + "\n" + q[3], 20, 20);
text("euler angles:\nyaw (psi) : " + degrees(euler[0]) + "\npitch (theta): " + degrees(euler[1]) + "\nroll (phi) : " + degrees(euler[2]), 200, 20);
drawcube();
}
void keypressed() {
if(key == 'h') {
println("pressed h");
// set hq home quaternion quatnion conjugate coming sensor fusion
hq = quatconjugate(q);
}
else if(key == 'n') {
println("pressed n");
hq = null;
}
}
// see sebastian o.h. madwick report
// "an efficient orientation filter inertial , intertial/magnetic sensor arrays" chapter 2 quaternion representation
void quaterniontoeuler(float [] q, float [] euler) {
euler[0] = atan2(2 * q[1] * q[2] - 2 * q[0] * q[3], 2 * q[0]*q[0] + 2 * q[1] * q[1] - 1); // psi
euler[1] = -asin(2 * q[1] * q[3] + 2 * q[0] * q[2]); // theta
euler[2] = atan2(2 * q[2] * q[3] - 2 * q[0] * q[1], 2 * q[0] * q[0] + 2 * q[3] * q[3] - 1); // phi
}
float [] quatprod(float [] a, float [] b) {
float [] q = new float[4];
q[0] = a[0] * b[0] - a[1] * b[1] - a[2] * b[2] - a[3] * b[3];
q[1] = a[0] * b[1] + a[1] * b[0] + a[2] * b[3] - a[3] * b[2];
q[2] = a[0] * b[2] - a[1] * b[3] + a[2] * b[0] + a[3] * b[1];
q[3] = a[0] * b[3] + a[1] * b[2] - a[2] * b[1] + a[3] * b[0];
return q;
}
// returns quaternion axis angle representation
float [] quataxisangle(float [] axis, float angle) {
float [] q = new float[4];
float halfangle = angle / 2.0;
float sinhalfangle = sin(halfangle);
q[0] = cos(halfangle);
q[1] = -axis[0] * sinhalfangle;
q[2] = -axis[1] * sinhalfangle;
q[3] = -axis[2] * sinhalfangle;
return q;
}
// return quaternion conjugate of quat
float [] quatconjugate(float [] quat) {
float [] conj = new float[4];
conj[0] = quat[0];
conj[1] = -quat[1];
conj[2] = -quat[2];
conj[3] = -quat[3];
return conj;
}
i'm using freeimu example quaternion uploaded uno, installed libraries in freeimu, , processing sketch provides on blog. compiles fine on end, when visual representation in processing rectangle free floating, , fabios reacts arduino/mpu6050's position.
any insight appreciated
did ever working? didnt see reply's , wondered how went
i'm starting out
i know half problem testing breadboards
now solder , working, ide & processing working, cant see next bit working
Arduino Forum > Using Arduino > Interfacing w/ Software on the Computer > issues with Uno R3 using FreeIMU v0.4, MPU6050, and Processing
arduino
Comments
Post a Comment