Read the Euler angle of the GY-95t sensor using arduino

I used the routine provided by the merchant, but the data read out was all 0.

/////////////////////
/*
GY95Q----MINI
VCC----VCC
GND----GND
1:GY95T_TX---10
2:GY95T_RX---11
*/
//////////////////
#include <SoftwareSerial.h>
typedef struct
{
    
    int16_t roll;
    int16_t pitch;
    int16_t yaw;
    uint8_t leve;
    int16_t temp;
   
} gy;

SoftwareSerial mySerial(10, 11); // RX, TX
byte add=0xa4;
byte len=0,start_reg=0;
unsigned char Re_buf[30],counter=0;
unsigned char sign=0;
gy my_95Q;
void setup() {
   Serial.begin(115200);
   mySerial.begin(115200);
   mySerial.listen();      
} 

void loop() {
  unsigned char i=0,sum=0;
  while (mySerial.available()) {   
    Re_buf[counter]=(unsigned char)mySerial.read();
    switch(counter)
    {
      case 0:
      if(Re_buf[0]!=add)
      return;
      break;
      case 1:
    
      if(Re_buf[1]!=0x03)
        { 
          counter=0;
          return;
      }
      break;
      case 2:
        if(Re_buf[2]<0x2c)
         start_reg=Re_buf[2];
         else
            { 
          counter=0;
          return;
         }
      break;
      case 3:
         if((start_reg+Re_buf[3])<0x2c)
            len=Re_buf[3];
            else
            { 
              counter=0;
             return;
         }
            
      break;
      default:
         if(len+5==counter)
         {  
            sign=1;
         }
      break;
    }
    
  if(sign)
  {   
     sign=0;
     for(i=0;i<counter-1;i++)
      sum+=Re_buf[i]; 
       counter=0;
     if(sum==Re_buf[i] )        //检查帧头,帧尾
     {  	       
        if(start_reg==0x14)
        {
            memcpy(&my_95Q,&Re_buf[4],9);
        }
      	 Serial.print("roll:");
         Serial.print((float)my_95Q.roll/100);
	 Serial.print(",pitch:");
         Serial.print((float)my_95Q.pitch/100);
	 Serial.print(",yaw:");
         Serial.print((float)my_95Q.yaw/100);
	 Serial.print(" ,temp:");  
         Serial.print((float)my_95Q.temp/100);
          Serial.print(",leve:");
         Serial.println((float)my_95Q.leve);
           
     }

   }
   else
   counter++; 

  }
   
}



This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.