Example Code for Arduino-I2C Read Gyro Data

Last revision 2025/12/15

Read tri-axis gyro data from the SD740 module via I2C interface and send the x, y, z values to the serial port. Users can learn how to communicate with I2C devices, read register data, and process sensor outputs.

Hardware Preparation

  • Arduino board: 1 (no specific model mentioned)
  • Tri-Axis Gyro Breakout-SD740 (SKU:TEL0038): 1,

Software Preparation

  • Development tool: Arduino IDE (download from Arduino Official Website)
  • Libraries: Wire library (included in Arduino IDE by default)

Wiring Diagram

I2C Connection

Other Preparation Work

  • Set the I2C address via the MISO/ADDR pin: LOW for 0x4E, HIGH for 0x4F (default used in code is 0x4F)
  • Ensure the module is powered with 3.3V

Sample Code


/*
Gyroscope SD740 I2C Mode

 Version 1.0  Lauren <[email protected]>

 Operating Supply Voltage           V    2.6 - 5% - 3.3 + 5%
 Full Scale Range (digital output) °/s  1024
 Sensitivity Accuracy               %    ± 5
 Sensitivity Error Over Temperature %    ± 5
 Signal Update Rate                 KHz  10
 SPI Communication Speed            KHz  400

 Full scale range is factory defined. Please contact SensorDynamics for setting different ranges. Maximum full scale
 factor is 4096°/s
 Bandwidth is factory defined. Please contact SensorDynamics for setting different ranges. Maximum bandwidth is
 150Hz

 I2C Address setting

 Pin          state        Device address

 MISO/ADDR    LOW          0x4E
 MISO/ADDR    HIGH         0x4F

 */

#include <Wire.h>
#define DEVICE 0x4F

byte buff[20] ;    //6 bytes buffer for saving data read from the device
char str[128];                      //string buffer to transform data before sending it to the serial port

//I2C Address A7

void setup(){

  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(57600);  // start serial for output

}


void loop(){

  int regAddress = 0x00;    //first axis-acceleration-data register on the ADXL345
  int x, y, z;

  readFrom(byte(DEVICE), regAddress, 8, buff);//receive data

  x = (((int)buff[2]) << 8) | buff[3];
  y = (((int)buff[4]) << 8) | buff[5];
  z = (((int)buff[6]) << 8) | buff[7];

//  we send the x y z values as a string to the serial port
//
  sprintf(str, "%d %d %d", x, y, z);
  Serial.print(str);
  Serial.print(10, BYTE);

//  It appears that delay is needed in order not to clog the port
  delay(100);

}

//---------------- Functions
//Writes val to address register on device
void writeTo(int device, byte address, byte val) {

  Wire.beginTransmission(device); //start transmission to device
  Wire.send(address);        // send register address
  Wire.send(val);        // send value to write
  Wire.endTransmission(); //end transmission

}

//reads num bytes starting from address register on device in to buff array
void readFrom(int device, byte address, int num, byte buff[]) {

  Wire.beginTransmission(device); //start transmission to device
  Wire.send(address);        //sends address to read from
  Wire.endTransmission(); //end transmission

  Wire.beginTransmission(device); //start transmission to device
  Wire.requestFrom(device, num);    // request 6 bytes from device

  int i = 0;
  while(Wire.available())    //device may send less than requested (abnormal)
  {
    buff[i] = Wire.receive(); // receive a byte
    i++;
  }
  Wire.endTransmission(); //end transmission

//  for(int j = 0;j < i;j ++){    //output all received bytes
//    Serial.print(buff[j],HEX);
//    Serial.print("\t");
//  }
//  Serial.print(10, BYTE);

}

Result

The serial port (baud rate 57600) outputs the x, y, z values read from the gyroscope in the format "x y z".

Additional Information

  • Warning: Please only use 3.3V to supply power to the Gyroscope.
  • Full scale range and bandwidth are factory defined; contact SensorDynamics for modifications.

Was this article helpful?

TOP