Post Go back to editing

Unable to read data from ADIS16362

Hi ,

I am new to SPI and trying to read data from the IMU.

Can anyone share a code that is working to read data from IMU ? 

The code I am using is

#include <SPI.h>
//ADIS16362 ---- Arduino Mega
//2(SCLK)--------52(SCLK)
//3(SS)----------53(ss)
//4(SDO)---------50(MISO)
//6(SDI)---------51(MOSI)
//7,8,9----------GND
//10,11,12-------V(3.3 OR 5)
//13-------------8(IRQ)

//uint16_t value = (highByte << 8) | lowByte ;

int ss = 53;
word ax_l, ay_l, az_l,ax_h,ay_h ,az_h;
word gx_l, gy_l, gz_l,gx_h,gy_h, gz_h;
word datax, datay, dataz;
word dataxg, datayg, datazg;
float dax, day, daz ;
float dgx, dgy, dgz;

void setup()
{
Serial.begin (1000000);
SPI.begin();
pinMode(ss, OUTPUT);
SPI.setDataMode(SPI_MODE3);
SPI.setBitOrder(MSBFIRST);
SPI.setClockDivider(SPI_CLOCK_DIV8);
digitalWrite(ss, HIGH);
}

void loop()
{

//=================================
// Accelerometer Readings
//=================================

// X_ACCELEROMETER_OUT

digitalWrite(ss,LOW);
delayMicroseconds(200);
ax_l=SPI.transfer(0x0A);
delayMicroseconds(200);
ax_h=SPI.transfer(0x0B);
digitalWrite(ss,HIGH);
datax=(ax_h<<8)|ax_l;
dax=datax*(0.333);
Serial.print("X Accel: ");
Serial.print(dax, DEC);
Serial.print(" mg");
Serial.print("\n");
delay(200);
////=============================
//
////Y_ACCELEROMETER_OUT

digitalWrite(ss,LOW);
delayMicroseconds(200);
ay_l=SPI.transfer(0x0C);
delayMicroseconds(200);
ay_h=SPI.transfer(0x0D);
digitalWrite(ss,HIGH);
datay=(ay_h<<8)|ay_l;
day=datay*(0.333);
Serial.print("Y Accel: ");
Serial.print(day, DEC);
Serial.print(" mg");
Serial.print("\n");
delay(200);
//=====================================

//z_ACCELEROMETER_OUT

digitalWrite(ss,LOW);
delayMicroseconds(200);
az_l=SPI.transfer(0xE);
delayMicroseconds(200);
az_h =SPI.transfer(0xF);
digitalWrite(ss,HIGH);
dataz= (az_h<<8) | az_l;
daz=dataz*(0.333);
Serial.print("Z Accel: ");
Serial.print(daz, DEC);
Serial.print(" mg");
Serial.print("\n\n");
delay(200);

//========================
// GyRoScOpE READINGS
//========================
//
////X_GYRO_OUT
//
digitalWrite(ss,LOW);
delayMicroseconds(200);
gx_l=SPI.transfer(0x04);
delayMicroseconds(200);
gx_h=SPI.transfer(0x05);
digitalWrite(ss,HIGH);
dataxg=(gx_h<<8)|gy_l;
dgx=(dataxg*0.05);
Serial.print("X Gyro: ");
Serial.print(dgx, DEC);
Serial.print(" deg/sec");
Serial.print("\n");
delay(200);

////=================================================
////Y_GYRO_OUT
//
digitalWrite(ss,LOW);
delayMicroseconds(200);
gy_l=SPI.transfer(0x06);
delayMicroseconds(200);
gy_h=SPI.transfer(0x07);
digitalWrite(ss,HIGH);
datayg=(gy_h<<8)| gy_l ;
dgy=(datayg*0.05);
Serial.print("Y Gyro: ");
Serial.print(dgy, DEC);
Serial.print(" deg/sec");
Serial.print("\n");
delay(200);

//
////=================================================
////Z_GYRO_OUT
digitalWrite(ss,LOW);
delayMicroseconds(200);
gz_l=SPI.transfer(0x08);
delayMicroseconds(200);
gz_h =SPI.transfer(0x09);
digitalWrite(ss,HIGH);
datazg=(gz_h<<8)| gz_l;
dgz=(datazg*0.05);
Serial.print("Z Gyro: ");
Serial.print(dgz, DEC);
Serial.print(" deg/sec");
Serial.print("\n\n");
delay(1000);
}

The output  is this 


X Accel: 85.2480010986 mg
Y Accel: 342.3240051269 mg
Z Accel: 0.0000000000 mg

X Gyro: 0.1000000000 deg/sec
Y Gyro: 0.0000000000 deg/sec
Z Gyro: 0.0000000000 deg/sec

X Accel: 85.2480010986 mg
Y Accel: 342.3240051269 mg
Z Accel: 598.7340087890 mg

X Gyro: 0.0000000000 deg/sec
Y Gyro: 38.5000000000 deg/sec
Z Gyro: 0.0000000000 deg/sec

X Accel: 0.0000000000 mg
Y Accel: 0.0000000000 mg
Z Accel: 0.0000000000 mg

X Gyro: 0.1000000000 deg/sec
Y Gyro: 38.5000000000 deg/sec
Z Gyro: 0.0000000000 deg/sec

X Accel: 85.2480010986 mg
Y Accel: 342.3240051269 mg
Z Accel: 598.7340087890 mg

X Gyro: 0.1000000000 deg/sec
Y Gyro: 0.0000000000 deg/sec
Z Gyro: 0.0000000000 deg/sec

X Accel: 85.2480010986 mg
Y Accel: 342.3240051269 mg

  • Dear HariHoney,

    I'm not exactly sure where the problem is, but I have two recommendations:

    1. The product ID register at address 0x56 is extremely handy for debugging the serial port as it always reads back the same value. The GPIO_CTRL register is also useful as you can observe the state change on a DIO pin as you program it.

    2. We have a sample code driver for the Teensy Shield developed using Arduino Libraries for the ADIS16490. While it's not the same target IMU, the code should be similar enough to be useful to you.

    https://github.com/juchong/ADIS16490_Arduino_Teensy

    -Paul Kern