Same problem for me. :( Anyone know of any code / can share any experience successfully reading a L3G4200D on Android ?
On Sunday, September 8, 2013 12:47:15 PM UTC-7, Jorge Sánchez Briantes wrote: > > Hello. I have a 10DOF IMU connected to IOIO with I2C: > > TwiMaster twi = ioio_.openTwiMaster(1, TwiMaster.Rate.RATE_1MHz, false);. > > > The GY-80 Inertial Measurement Unit contains the following sensors: > I2C Address 0x69 is the L3G4200D - 3axis 16bit gyro with ±250, 500, > 2000°/sec ranges > I2C Address 0x53 is the ADXL345 - 3 axis 10-13bit Accelerometer with ±2g, > 4g, 8g, 16g ranges > I2C Address 0x1E is the HMC5883L - 3 Axis, 12bit Magnetometer with ±0.88, > 1.3, 1.9, 2.5, 4.0, 4.7, 5.6, 8.1 gauss ranges > I2C Address 0x77 is the BMP085 - 300-1100hPa Barometer (16-19bits) + > Temperature (16bits) > > I receive data from all sensor but I only BMP085 is working good > (temperature and presure). > All other sensor sends me data but I only properly interpret BMP085. > I read about thouse sensor and examples for arduino in bildr pages: > http://bildr.org/2011/06/l3g4200d-arduino/ > This is my code for the other (simplified): > > ... > > // Initialization > > byte whatever[] = new byte[3]; > > //ADXL345 3-AXIS DIGITAL ACCELEROMETER > > boolean success = twi.writeRead(0x53, false, new byte[] {0x2D,0x08}, > 2, whatever, 0); > > success = twi.writeRead(0x53, false, new byte[] {0x31,0x08}, 2, whatever, > 0); > > Thread.sleep(1); > > //HMC5883L 3-AXIS DIGITAL COMPASS > > success = twi.writeRead(0x1E, false, new byte[] {0x02,0x00}, 2, whatever, > 0); > > Thread.sleep(5); > > > // L3G4200D > > // Enable x, y, z and turn off power down: > > success = twi.writeRead(L3G4200D_Address, false, new byte[] {0x20,0x0F}, > 2, whatever, 0); > > success = twi.writeRead(L3G4200D_Address, false, new byte[] {0x21,0x00}, > 2, whatever, 0); > > success = twi.writeRead(L3G4200D_Address, false, new byte[] {0x22,0x00}, > 2, whatever, 0); > > success = twi.writeRead(L3G4200D_Address, false, new byte[] {0x23,0x00}, > 2, whatever, 0); > > success = twi.writeRead(L3G4200D_Address, false, new byte[] {0x24,0x00}, > 2, whatever, 0); > > ... > > > After this. Read data on the loop: > > // accelerometer samples > > byte [] acc = new byte [6]; > > boolean success2 = twi.writeRead(0x53, false, new byte[]{0x32}, 1, acc, > 6); > > int dataX = (acc[0]) + ((acc[1]) << 8); > > int dataY = (acc[2]) + ((acc[3]) << 8); > > int dataZ = (acc[4]) + ((acc[5]) << 8); > > > label1.setText("Acel X:"+String.valueOf(dataX)+" > "+Integer.toHexString(dataX)+" "+Integer.toHexString(acc[0])+" > "+Integer.toHexString(acc[1])); > > label2.setText("Acel Y:"+String.valueOf(dataY)+" > "+Integer.toHexString(dataY)+" "+Integer.toHexString(acc[2])+" > "+Integer.toHexString(acc[3])); > > label3.setText("Acel Z:"+String.valueOf(dataZ)+" > "+Integer.toHexString(dataZ)+" "+Integer.toHexString(acc[4])+" > "+Integer.toHexString(acc[5])); > > > Thread.sleep(5); > > > // digital compass > > success2 = twi.writeRead(0x1E, false, new byte[]{0x03}, 1, acc, 6); > > dataX = (acc[0]) + ((acc[1]) << 8); > > dataY = (acc[2]) + ((acc[3]) << 8); > > dataZ = (acc[4]) + ((acc[5]) << 8); > > label4.setText("Mag X:"+String.valueOf(dataX)); > > label5.setText("Mag Y:"+String.valueOf(dataY)); > > label6.setText("Mag Z:"+String.valueOf(dataZ)); > > > // Calculate heading when the magnetometer is level, then correct for > signs of axis. > > double heading = Math.atan2(dataY, dataX); > > double declinationAngle = -0.0301; > > heading += declinationAngle; > > > > // Correct for when signs are reversed. > > if(heading < 0) > > heading += 2*Math.PI; > > > > // Check for wrap due to addition of declination. > > if(heading > 2*Math.PI) > > heading -= 2*Math.PI; > > // Convert radians to degrees for readability. > > double headingDegrees = heading * 180/Math.PI; > > > label4.setText(label4.getText().toString()+ " HDG: > "+String.valueOf(headingDegrees)); > > Thread.sleep(5); > > > // gyro > > byte [] xMSB = new byte [1]; > > byte [] xLSB = new byte [1]; > > success2 = twi.writeRead(L3G4200D_Address, false, new byte[]{0x29}, 1, > xMSB, 1); > > success2 = twi.writeRead(L3G4200D_Address, false, new byte[]{0x28}, 1, > xLSB, 1); > > dataX = xLSB[0] + ((xMSB[0]) << 8); > > > success2 = twi.writeRead(L3G4200D_Address, false, new byte[]{0x2B}, 1, > xMSB, 1); > > success2 = twi.writeRead(L3G4200D_Address, false, new byte[]{0x2A}, 1, > xLSB, 1); > > dataY = xLSB[0] + ((xMSB[0]) << 8); > > > success2 = twi.writeRead(L3G4200D_Address, false, new byte[]{0x2D}, 1, > xMSB, 1); > > success2 = twi.writeRead(L3G4200D_Address, false, new byte[]{0x2C}, 1, > xLSB, 1); > > dataZ = xLSB[0] + ((xMSB[0]) << 8); > > > label11.setText("Gyro X:"+String.valueOf(dataX)); > > label12.setText("Gyro Y:"+String.valueOf(dataY)); > > label13.setText("Gyro Z:"+String.valueOf(dataZ)); > > > As I said, the problems is I think the receive data isn't correct. > I know It isn't a IOIO problem, but I haven't found examples for IOIO > using this sensor. > I was wondering If someone has used some of this sensor and could share > his code with us, or someone could help me about get correct values. > > Thanks in advance. > -- You received this message because you are subscribed to the Google Groups "ioio-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/ioio-users. For more options, visit https://groups.google.com/d/optout.
