Hesher

Forum Replies Created

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #4536
    Hesher
    Participant

    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/sensor

    Note: 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) 😀

    #4525
    Hesher
    Participant
    #4408
    Hesher
    Participant

    not 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 not

    #4405
    Hesher
    Participant

    Hey 🙂

    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()

Viewing 4 posts - 1 through 4 (of 4 total)

Blip, blop, bloop…