Forum Replies Created
- AuthorPosts
- February 2, 2016 at 8:33 am #4536HesherParticipant
Hi,
so here are my findings:
The best lib for the Gyro (L3GD20) i´ve found is:
https://github.com/OlivierLD/raspberry-pi4j-samples/tree/75f8ec4583477a5ee1cf8707e64d9df75976986c/I2C.SPI/src/i2c/sensorNote: You have to change the ADDRESS in:
L3GD20.java
Line 17: public final static int L3GD20ADDRESS = 0x6b;
to public final static int L3GD20ADDRESS = 0x6a;And thats the code which works for me – but bugy – if i move the gyro around, it looses accuracy over time
L3GD20 sensor = new L3GD20(); sensor.setPowerMode(L3GD20Dictionaries.NORMAL); sensor.setFullScaleValue(L3GD20Dictionaries._250_DPS); sensor.setAxisXEnabled(true); sensor.setAxisYEnabled(true); sensor.setAxisZEnabled(true); sensor.init(); sensor.calibrate(); Thread t = new Thread(){ public void run() { while (true) { try { data = sensor.getCalOutValue(); //data = sensor.getRawOutValues(); } catch (Exception ex) { Logger.getLogger(Raspi.class.getName()).log(Level.SEVERE, null, ex); } now = System.nanoTime(); timeDelta = (now - lastRead)*0.000000001; lastRead = now; xAngle += (data[0]*timeDelta); yAngle += (data[1]*timeDelta); zAngle += (data[2]*timeDelta); try { Thread.sleep(1); } catch (InterruptedException ex) {} } } }; t.start(); Thread t2 = new Thread(){ public void run() { while (true) { try { System.out.println("X:" + Math.round(xAngle) + " ## Y:" + Math.round(yAngle) + " ## Z:" + Math.round(zAngle)); //System.out.println(timeDelta); } catch (Exception ex) { Logger.getLogger(Raspi.class.getName()).log(Level.SEVERE, null, ex); } try { Thread.sleep(500); } catch (InterruptedException ex) {} } } }; t2.start();
PS:
Btw: the error in my code above (in my question) is: it reads X-axis only (not x,y,z) 😀January 24, 2016 at 9:59 pm #4525HesherParticipantHi again,
ive tried to read values from BMP180 – which works well with this code
https://code.google.com/p/raspberry-pi4j-samples/source/browse/AdafruitI2C/src/adafruiti2c/AdafruitBMP180.java?spec=svn74c33e4a5cc3048678061c52c6df0119dbca14a2&r=74c33e4a5cc3048678061c52c6df0119dbca14a2I´ll try accelerometer next.
January 11, 2016 at 2:06 am #4408HesherParticipantnot yet, but i will, just need to fix some other issues with my pi 🙂
i´ll give you an update in some days – if this works / or notJanuary 10, 2016 at 11:21 pm #4405HesherParticipantHey 🙂
thank you for reply, yes i still have the issue.
The gyro works with C and Phyton code.
PS: i guess i´ve found a bug in python-LSM9DS0-gryo-accel-compass 😉
Line 154 – 156
GYRx = readGYRx()
GYRy = readGYRx()
GYRz = readGYRx() - AuthorPosts