Go Down

Topic: Getting all values 0 from the imu.  (Read 321 times) previous topic - next topic

pravin382

May 15, 2019, 03:47 pm Last Edit: May 15, 2019, 04:03 pm by pravin382
Dear All,

I am trying to get the data from UM7 imu sensor to Arduino Mega. I think I have connected the pins properly and I have written the code below.
But unfortunately, I do not get any data from the sensor or all the values are zero. If you wish to refer the datasheet of UM7, it can be found in http://www.chrobotics.com/docs/UM7_Datasheet.pdf. I have tried to attach pictures from the datasheet regarding the communication. I hope, you can view them.

If you need any more info, I can send you more.


Code: [Select]
#include<SPI.h>

// Read and write operations
#define Reg_read  0x00
#define Reg_write 0x01

// Registers list
#define DREG_EULER_PHI_THETA 0x70


//define the variables to be used for data from UM7
float roll, pitch;
uint32_t data, data1; // maybe I donot require this
uint8_t byte_0,byte_1, byte_2, byte_3; //for datacoming from register

void setup() {
  // for serial communication between PC and arduino
  Serial.begin(115200);
  SPI.begin();                            //Begins the SPI commnuication
  //SPI.setClockDivider(SPI_CLOCK_DIV16);    //Sets clock for SPI communication at 16 (16/16=1Mhz)
  digitalWrite(SS,HIGH);                  // Setting SlaveSelect as HIGH (So master doesnt connnect with slave)
}

void loop() {
  // put your main code here, to run repeatedly:
  SPI.beginTransaction(SPISettings(10000000,MSBFIRST,SPI_MODE1));
  digitalWrite(SS, LOW);              //Starts communication with Slave connected to master
  SPI.transfer(Reg_read);
  SPI.transfer(DREG_EULER_PHI_THETA);
  // reading the data from the register
  byte_0 = SPI.transfer(Reg_read);
  byte_1 = SPI.transfer(Reg_read);
  byte_2 = SPI.transfer(Reg_read);
  byte_3 = SPI.transfer(Reg_read);
  digitalWrite(SS,HIGH);
  SPI.endTransaction();
  delayMicroseconds(5); // wait for 5 microns

  Serial.print(byte_0);
  Serial.print('\t');
  Serial.print(byte_1);
  Serial.print('\t');
  Serial.print(byte_2);
  Serial.print('\t');
  Serial.print(byte_3);
  Serial.print('\n');
}



pravin382

#1
May 15, 2019, 04:05 pm Last Edit: May 15, 2019, 04:05 pm by pravin382
Sorry, I think the connections were loose. So, I am getting non- zero values now. But they are now either  a constant value or zero even though I rotate the imu

pylon

Quote
I think I have connected the pins properly and I have written the code below.
Let us check that. Post a wiring diagram of your setup.

pravin382

The actual wiring diagram is not so clear but still I uploaded it. Also, I write here the pin connection that I made:

IMU              Arduino Mega pin
MISO             MISO (50)
MOSI             MOSI (51)
SS                 53
SCK               52
Vin                5V
ground          ground

I am using level_shifter to convert 5V to 3.3 Volts because SPI communication works with 3.3V and Arduino Mega operates in 5V

pravin382


pylon

Quote
Does my program seem alright?
Only partially. You're not communicating with a hardware SPI chip but with another MCU. As the datasheet specifies, this MCU needs 5µs to store the transferred byte before you can send the next byte. Try inserting a delayMicroseconds(5) between consecutive SPI.transfer() calls.

pravin382

Yes, I changed that but forgot to update here. I kept a delay of 25microseconds between each consecutive SPI.transfer() calls. I think it should not affect so much. And I do roll and pitch calculations from the data that I get from above operations.

As I mentioned earlier, I am getting some non-zero values but the values are now mostly zero but occasionally some non zero number appears.

Below is the glimpse of the data that I get after roll and pitch calculations.  The first column is roll data. How should I tackle this problem?


0.00   0.00
0.00   0.00
0.09   95.71
24.60   -0.18
0.02   98.43
-90.00   0.00
0.00   0.00
0.00   0.00
0.00   0.00
0.00   0.00
0.00   0.00
0.00   0.00
0.09   95.71
22.52   91.53
-180.00   0.00
0.00   0.00
0.00   0.00
0.00   0.00
0.00   0.00
44.30   0.00
0.00   0.00
0.09   95.98
22.87   24.60
-90.00   0.00
0.00   0.00
0.35   -337.15
5.98   -337.13
0.00   0.00
0.00   0.00
0.00   0.00
0.00   0.00
0.00   0.00
0.00   0.00
0.00   0.00
0.00   0.00
0.00   0.00
0.00   0.00
0.00   0.00
0.00   0.00
0.00   0.00
0.00   0.00
0.00   0.00
0.00   0.00
0.35   -354.00
95.71   -354.29
-11.25   0.00
0.00   0.00
0.00   0.00
0.00   0.00
0.00   0.00
0.00   0.00
0.00   0.00
0.00   0.00
0.00   0.00
0.00   0.00
0.00   0.00
0.00   0.00
0.00   0.00
0.00   0.00
0.00   0.00
0.00   0

pylon

25 µs is too long. Use 5µs delays.

Post the code you're actually working with.

pravin382

Sorry for late reply. Here is my current code. The output remains the same as posted before.

Code: [Select]
#include<SPI.h>

// Read and write operations
#define Reg_read  0x00
#define Reg_write 0x01

// Registers list
#define DREG_EULER_PHI_THETA 0x70


//define the variables to be used for data from UM7
short roll, pitch;
uint8_t byte_0,byte_1, byte_2, byte_3; //for data coming from register

void setup() {
  // for serial communication between PC and arduino
  Serial.begin(115200);
  SPI.begin();                            //Begins the SPI commnuication
  //SPI.setClockDivider(SPI_CLOCK_DIV16);    //Sets clock for SPI communication at 16 (16/16=1Mhz)
  digitalWrite(SS,HIGH);                  // Setting SlaveSelect as HIGH (So master doesnt connnect with slave)
}

void loop() {
  // put your main code here, to run repeatedly:
  SPI.beginTransaction(SPISettings(1000000,MSBFIRST,SPI_MODE1));
  digitalWrite(SS, LOW);              //Starts communication with Slave connected to master
  SPI.transfer(Reg_read);
  delayMicroseconds(5);
  SPI.transfer(DREG_EULER_PHI_THETA);
  delayMicroseconds(5);
  // reading the data from the register
  byte_0 = SPI.transfer(Reg_read);
  delayMicroseconds(5);
  byte_1 = SPI.transfer(Reg_read);
  delayMicroseconds(5);
  byte_2 = SPI.transfer(Reg_read);
  delayMicroseconds(5);
  byte_3 = SPI.transfer(Reg_read);
  delayMicroseconds(5); // wait for 25 microns
  digitalWrite(SS,HIGH);
  SPI.endTransaction();
  roll = byte_0 << 8;
  roll |= byte_1;
  pitch = byte_2 << 8;
  pitch |= byte_3;
 
  Serial.print(roll/91.02222);
  Serial.print('\t');
  Serial.print(pitch/91.02222);
  Serial.print('\n');
}

pylon

Code: [Select]
  SPI.beginTransaction(SPISettings(1000000,MSBFIRST,SPI_MODE1));

According to the datasheet the device is using SPI mode 0.

pravin382

I have tried with all the SPI modes but none of them gives me good data.

I am using SPI mode 1 because only when I use SPI mode1, I can see the data that I send (0x00 0x70 0x00 0x00 0x00 0x00 )via MOSI correctly. I verified this with the oscilloscope.

I think now that  SPI pins on my IMU may be damaged. I am expecting an new IMU next week. I will update if that works or not.

pravin382

The new IMU also gives me noise. These values simply do not make sense. The code is still the same
 
116.21   104.88
116.21   51.03
115.72   208.34
209.05   56.70
56.47   116.21
116.21   116.21
56.70   231.03
-331.77   56.70
230.82   104.88
59.88   116.24
208.58   236.70
56.70   104.79
14.29   119.05
56.47   116.21
116.21   104.88
119.05   51.03
115.76   56.71
104.47   208.34
56.70   116.21
104.47   208.34
56.71   116.21
104.96   104.51
231.03   14.52
104.12   116.21
56.70   116.21
59.29   118.34
104.28   113.42
59.52   119.03
115.72   208.36
104.88   56.70

pylon

Just had a closer look to your wiring: the level converter doesn't have the low voltage and high voltage pins connected. I also cannot see a GND connection there. Without them it cannot work.

pravin382

I tried that also but it is still not working. Now Slave select pin does not even go Low. But I can see Clock signals in oscilloscope.  I do not understand what is happening? 

pylon

Post a complete wiring diagram (may be hand drawn) of your setup. Maybe there are other problems in the wiring.

Go Up