I get Euler Angles from GY-25 by Serial protocol (in Arduino IDE). If you use Software serial (Virtual serial port) you can only use baud rate of 9600 to get data from GY-25. But if you use Arduino Mega 2560, you can use Serial1 or Serial2 or Serial3 (Actual Serial ports) and set baud rate of 115200 to get data from GY-25 (fast and exact).
My code for All Arduino boards with Software serial:
#include <SoftwareSerial.h>
static const int RXPin = 68, TXPin = 69; // announce your Rx and Tx pins
SoftwareSerial Portone(RXPin, TXPin);
float Roll,Pitch,Yaw;
unsigned char Re_buf[8],counter=0;
void setup()
{
Serial.begin(115200);
Portone.begin(9600); // SoftwareSerial can only support 9600 baud rate for GY 25 but Serial3 can support 115200 and 9600 both
delay(4000);
Portone.write(0XA5);
Portone.write(0X54);//correction mode
delay(4000);
Portone.write(0XA5);
Portone.write(0X51);//0X51:query mode, return directly to the angle value, to be sent each read, 0X52:Automatic mode,send a direct return angle, only initialization
}
void loop() {
serialEvent();
Serial.print("roll= ");
Serial.print(Roll);
Serial.print(" pitch= ");
Serial.print(Pitch);
Serial.print(" yaw= ");
Serial.println(Yaw);
} // End of void loop
void serialEvent() {
Portone.write(0XA5);
Portone.write(0X51);//send it for each read
while (Portone.available()) {
Re_buf[counter]=(unsigned char)Portone.read();
if(counter==0&&Re_buf[0]!=0xAA) return;
counter++;
if(counter==8) // package is complete
{
counter=0;
if(Re_buf[0]==0xAA && Re_buf[7]==0x55) // data package is correct
{
Yaw=(int16_t)(Re_buf[1]<<8|Re_buf[2])/100.00;
Pitch=(int16_t)(Re_buf[3]<<8|Re_buf[4])/100.00;
Roll=(int16_t)(Re_buf[5]<<8|Re_buf[6])/100.00;
}
}
} // End of while
} // End of serialEvent
My code for Arduino Mega 2560 with Actual Serial ports:
// Connect RX of GY 25 to TX3 Arduino Mega and TX of GY 25 to RX3 Arduino Mega
float Roll,Pitch,Yaw;
unsigned char Re_buf[8],counter=0;
void setup()
{
Serial.begin(115200);
Serial3.begin(115200);// SoftwareSerial can only support 9600 baud rate for GY 25 but Serial3 can support 115200 and 9600 both
delay(4000);
Serial3.write(0XA5);
Serial3.write(0X54);//correction mode
delay(4000);
Serial3.write(0XA5);
Serial3.write(0X51);//0X51:query mode, return directly to the angle value, to be sent each read, 0X52:Automatic mode,send a direct return angle, only initialization
}
void loop() {
serialEvent();
Serial.print("roll= ");
Serial.print(Roll);
Serial.print(" pitch= ");
Serial.print(Pitch);
Serial.print(" yaw= ");
Serial.println(Yaw);
} // End of void loop
void serialEvent() {
Serial3.write(0XA5);
Serial3.write(0X51);//send it for each read
while (Serial3.available()) {
Re_buf[counter]=(unsigned char)Serial3.read();
if(counter==0&&Re_buf[0]!=0xAA) return;
counter++;
if(counter==8) //package is complete
{
counter=0;
if(Re_buf[0]==0xAA && Re_buf[7]==0x55) // data package is correct
{
Yaw=(int16_t)(Re_buf[1]<<8|Re_buf[2])/100.00;
Pitch=(int16_t)(Re_buf[3]<<8|Re_buf[4])/100.00;
Roll=(int16_t)(Re_buf[5]<<8|Re_buf[6])/100.00;
}
}
} // End of while
} // End of serialEvent
Note: You should set Baud rate of GY-25 according to the attached picture.
I used GY-25 with this code for my system, but the final result of GY-955 (BNO055) through I2C connection, was very better in comparison to GY-25. Here is the code to get Euler angles from GY-955 through I2C connection: Run GY-955 (BNO055) through I2C connection in Arduino IDE - Sensors - Arduino Forum
And also, I obtained distance vector along the north and the east using Ublox Neo 6M module:
https://forum.arduino.cc/index.php?topic=728538.msg4902802#msg4902802
If you have any question, you can ask me in comments or by a pm.