GY-91 Sensor; Arduino: Difference between revisions
From wikiluntti
| Line 19: | Line 19: | ||
#include <MPU9250_asukiaaa.h> | #include <MPU9250_asukiaaa.h> | ||
MPU9250_asukiaaa mySensor; | MPU9250_asukiaaa mySensor; | ||
float aX, aY, aZ | float aX, aY, aZ; | ||
void setup() { | void setup() { | ||
| Line 34: | Line 34: | ||
aY = mySensor.accelY(); | aY = mySensor.accelY(); | ||
aZ = mySensor.accelZ(); | aZ = mySensor.accelZ(); | ||
// Print the data | |||
// | |||
Serial.print( aX ); | Serial.print( aX ); | ||
Latest revision as of 20:24, 26 November 2022
Introduction
Uisng GY-91 sensor with Asukiaa's MPU9250 library. Install the library using Arduino IDE Manage Libraries. More information about the library is at https://github.com/asukiaaa/MPU9250_asukiaaa
GY-91 includes MPU-9250 circuit which has gyro, accelerometer and compass.
Theory
Example code

The following code reads and prints the acceleration to each three directions, but using the following ideas, you can use gyroscope and magnetometer data also.
The output is sent to Serial line, and if the USB cable is plugged, you can read the data using Serial monitor, or more preferably using Serial plotter. Make sure that the bps is correct.
#include <MPU9250_asukiaaa.h>
MPU9250_asukiaaa mySensor;
float aX, aY, aZ;
void setup() {
Wire.begin();
mySensor.setWire(&Wire);
mySensor.beginAccel();
Serial.begin(9600); // open the serial port at 9600 bps:
}
void loop() {
mySensor.accelUpdate();
aX = mySensor.accelX();
aY = mySensor.accelY();
aZ = mySensor.accelZ();
// Print the data
Serial.print( aX );
Serial.print( "\t" );
Serial.print( aY );
Serial.print( "\t" );
Serial.print( aZ );
Serial.print( "\n" );
}
Accelerometer
mySensor.beginAccel();
accelX();
Gyrometer
mySensor.beginGyro();
gyroX();
Magnetometer
mySensor.beginMag();
magX();
Exercises
See Also & References
https://www.cod3v.info/index.php?title=Arduino_OKY3259-1_GY-BMP280