Dcube Tech Ventures
Published

Interfacing of 3-Axis Gyroscope Sensor BMG160 With Arduino

BMG160 is basically a 16-bit, digital, tri-axial, gyroscope sensor which can measure angular rates.

IntermediateProtip4 hours4,139
Interfacing of 3-Axis Gyroscope Sensor BMG160 With Arduino

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
BMG160 16-bit Triaxial Gyroscope Sensor
×1
I²C Cable
×1
ControlEverything.com I2C Shield for Arduino Nano
×1

Story

Read more

Schematics

BMG160 Schematic

Code

3-Axis Gyroscope Measurement Arduino Code

Arduino
#include
// BMG160 I2C address is 0x68(104)
#define Addr 0x68
void setup() 
{
// Initialise I2C communication as MASTER   
Wire.begin();  
// Initialise Serial Communication, set baud rate = 9600  
Serial.begin(9600);
 // Start I2C Transmission  
Wire.beginTransmission(Addr);  
// Select Range register  
Wire.write(0x0F);  
// Configure full scale range 2000 dps  
Wire.write(0x80);  
// Stop I2C Transmission  
Wire.endTransmission();
 // Start I2C Transmission  
Wire.beginTransmission(Addr);  
// Select Bandwidth register  
Wire.write(0x10);  
// Set bandwidth = 200 Hz  
Wire.write(0x04);  
// Stop I2C Transmission  
Wire.endTransmission();  
delay(300);
}
void loop()
{  
unsigned int data[6];  
// Start I2C Transmission  
Wire.beginTransmission(Addr);  
// Select Gyrometer data register 
Wire.write(0x02);  
// Stop I2C Transmission  
Wire.endTransmission();
 // Request 6 bytes of data  
Wire.requestFrom(Addr, 6);  
// Read 6 bytes of data 
// xGyro lsb, xGyro msb, yGyro lsb, yGyro msb, zGyro lsb, zGyro msb  
if(Wire.available() == 6)  
{    
data[0] = Wire.read();    
data[1] = Wire.read();    
data[2] = Wire.read();    
data[3] = Wire.read();    
data[4] = Wire.read();    
data[5] = Wire.read();  
}  
delay(300);    
// Convert the data  
int xGyro = ((data[1] * 256) + data[0]);  
int yGyro = ((data[3] * 256) + data[2]);  
int zGyro = ((data[5] * 256) + data[4]);    
// Output data to the serial monitor  
Serial.print("X-Axis of Rotation:  ");  
Serial.println(xGyro);  Serial.print("Y-Axis of Rotation:  ");  
Serial.println(yGyro);  Serial.print("Z-Axis of Rotation:  ");  
Serial.println(zGyro);  
delay(500);
}

Github file

Credits

Dcube Tech Ventures

Dcube Tech Ventures

34 projects • 16 followers
Dcube Tech Ventures Pvt Limited is collaboration of Hardware, Embedded and Software endeavour's to create the Internet of things. www.dcubestore.com

Comments