Octopus 3-Axis GYRO Sensor

From ElecFreaks
Jump to: navigation, search

Introduction

Octopus Electronic Bricks, you can use them build electronics projects just as easy as piling bricks. By using Octopus electronic bricks, you may connect Arduino/Freaduino compatible boards easily with various digital, analog and I2C/Uart interfaces. These the breadboard-less firm connection are prepared to extensive modules like poteniometers, sensors, relays, servos…even buttons, just plug and play.

3-Axis GYRO Sensor is a sensor module based on the IC ITG3205 axis gyro . ITG3205 is a digital output MEMS gyroscope (also called angular velocity sensor), with three 16-bit analog - digital converter (ADC), digital gyroscope output. Users can select the internal low-pass filter bandwidth, and high-speed I2C serial Interface (400KHZ) Additional features include a built-in temperature sensor and a 2% accurate internal oscillator.


OCTOPUS GYRO Module A.JPG OCTOPUS GYRO Module B.jpg

Model: EF04022

Parameter

  • the digital output X, Y, Z-axis angular value velocity sensor in a single circuit, with the least significant 16 bits (LSBs) ° / sec sensitivity and ± 2000 ° / sec full scale range.
  • the programmable digital low-pass filter
  • less than 6.5mA operating current, greatly extending battery life, standby current of only 5uA
  • VDD power supply range 2.1V-3.6V
  • the digital output temperature sensor
  • high-speed I2C serial interface (400KHZ)
  • Power supply needs: 3.3V/5V
  • Fast response and High sensitivity
  • Simple drive circuit
  • Stable and long life

Schematic

OCTOPUS GYRO Module D.JPG

Specification

Pin definition and Rating

GND VCC Signal
GND VCC Signal

Usage

  • 3P buckled wires connector

Soil-OB-07.jpg


Hardware Installation

3-Axis GYRO Sensor.jpg

Programming

Includes important code snippet. Demo code like :


       //The Wire library is used for I2C communication
#include <Wire.h>

//This is a list of registers in the ITG-3200. Registers are parameters that determine how the sensor will behave, or they can hold data that represent the
//sensors current status.
//To learn more about the registers on the ITG-3200, download and read the datasheet.
char WHO_AM_I = 0x00;
char SMPLRT_DIV= 0x15;
char DLPF_FS = 0x16;
char GYRO_XOUT_H = 0x1D;
char GYRO_XOUT_L = 0x1E;
char GYRO_YOUT_H = 0x1F;
char GYRO_YOUT_L = 0x20;
char GYRO_ZOUT_H = 0x21;
char GYRO_ZOUT_L = 0x22;

//This is a list of settings that can be loaded into the registers.
//DLPF, Full Scale Register Bits
//FS_SEL must be set to 3 for proper operation
//Set DLPF_CFG to 3 for 1kHz Fint and 42 Hz Low Pass Filter
char DLPF_CFG_0 = 1<<0;
char DLPF_CFG_1 = 1<<1;
char DLPF_CFG_2 = 1<<2;
char DLPF_FS_SEL_0 = 1<<3;
char DLPF_FS_SEL_1 = 1<<4;

//I2C devices each have an address. The address is defined in the datasheet for the device. The ITG-3200 breakout board can have different address depending on how
//the jumper on top of the board is configured. By default, the jumper is connected to the VDD pin. When the jumper is connected to the VDD pin the I2C address
//is 0x69.
char itgAddress = 0x69;

    //In the setup section of the sketch the serial port will be configured, the i2c communication will be initialized, and the itg-3200 will be configured.
void setup()
{
  //Create a serial connection using a 9600bps baud rate.
  Serial.begin(9600);
  
  //Initialize the I2C communication. This will set the Arduino up as the 'Master' device.
  Wire.begin();
  
  //Read the WHO_AM_I register and print the result
  char id=0; 
  id = itgRead(itgAddress, 0x00);  
  Serial.print("ID: ");
  Serial.println(id, HEX);
  
  //Configure the gyroscope
  //Set the gyroscope scale for the outputs to +/-2000 degrees per second
  itgWrite(itgAddress, DLPF_FS, (DLPF_FS_SEL_0|DLPF_FS_SEL_1|DLPF_CFG_0));
  //Set the sample rate to 100 hz
  itgWrite(itgAddress, SMPLRT_DIV, 9);
}

       //The loop section of the sketch will read the X,Y and Z output rates from the gyroscope and output them in the Serial Terminal
void loop()
{
  //Create variables to hold the output rates.
  int xRate, yRate, zRate;

  //Read the x,y and z output rates from the gyroscope.
  xRate = readX();
  yRate = readY();
  zRate = readZ();

  //Print the output rates to the terminal, seperated by a TAB character.
  Serial.print(xRate);
  Serial.print('\t');
  Serial.print(yRate);
  Serial.print('\t');
  Serial.println(zRate);  

  //Wait 10ms before reading the values again. (Remember, the output rate was set to 100hz and 1reading per 10ms = 100hz.)
  delay(10);
}
     //This function will write a value to a register on the itg-3200.
//Parameters:
//  char address: The I2C address of the sensor. For the ITG-3200 breakout the address is 0x69.
//  char registerAddress: The address of the register on the sensor that should be written to.
//  char data: The value to be written to the specified register.
void itgWrite(char address, char registerAddress, char data)
{
  //Initiate a communication sequence with the desired i2c device
  Wire.beginTransmission(address);
  //Tell the I2C address which register we are writing to
  Wire.send(registerAddress);
  //Send the value to write to the specified register
  Wire.send(data);
  //End the communication sequence
  Wire.endTransmission();
}

//This function will read the data from a specified register on the ITG-3200 and return the value.
//Parameters:
//  char address: The I2C address of the sensor. For the ITG-3200 breakout the address is 0x69.
//  char registerAddress: The address of the register on the sensor that should be read
//Return:
//  unsigned char: The value currently residing in the specified register
unsigned char itgRead(char address, char registerAddress)
{
  //This variable will hold the contents read from the i2c device.
  unsigned char data=0;
  
  //Send the register address to be read.
  Wire.beginTransmission(address);
  //Send the Register Address
  Wire.send(registerAddress);
  //End the communication sequence.
  Wire.endTransmission();
  
  //Ask the I2C device for data
  Wire.beginTransmission(address);
  Wire.requestFrom(address, 1);
  
  //Wait for a response from the I2C device
  if(Wire.available()){
    //Save the data sent from the I2C device
    data = Wire.receive();
  }
  
  //End the communication sequence.
  Wire.endTransmission();
  
  //Return the data read during the operation
  return data;
}

//This function is used to read the X-Axis rate of the gyroscope. The function returns the ADC value from the Gyroscope
//NOTE: This value is NOT in degrees per second. 
//Usage: int xRate = readX();
int readX(void)
{
  int data=0;
  data = itgRead(itgAddress, GYRO_XOUT_H)<<8;
  data |= itgRead(itgAddress, GYRO_XOUT_L);  
  
  return data;
}

//This function is used to read the Y-Axis rate of the gyroscope. The function returns the ADC value from the Gyroscope
//NOTE: This value is NOT in degrees per second. 
//Usage: int yRate = readY();
int readY(void)
{
  int data=0;
  data = itgRead(itgAddress, GYRO_YOUT_H)<<8;
  data |= itgRead(itgAddress, GYRO_YOUT_L);  
  
  return data;
}

//This function is used to read the Z-Axis rate of the gyroscope. The function returns the ADC value from the Gyroscope
//NOTE: This value is NOT in degrees per second. 
//Usage: int zRate = readZ();
int readZ(void)
{
  int data=0;
  data = itgRead(itgAddress, GYRO_ZOUT_H)<<8;
  data |= itgRead(itgAddress, GYRO_ZOUT_L);  
  
  return data;
}





Demo 2

#include <Wire.h>  //调用arduino自带的I2C库
#include <LiquidCrystal.h>   //调用arduino自带的LiquidCrystal库
 
// 定义ITG3200陀螺仪常量
#define GYRO 0x68 // 设置IIC地址,AD0与GND相接,二进制数值为11101000.
#define G_SMPLRT_DIV 0x15
#define G_DLPF_FS 0x16
#define G_INT_CFG 0x17
#define G_PWR_MGM 0x3E
 
#define G_TO_READ 8 // x, y, z 每个轴输出为2个字节
 
LiquidCrystal lcd(10, 8,  9);//设置LCD接口
 
//  XYZ三轴偏移量修正
int g_offx = 28;  // 修正X轴误差
int g_offy = 53;   // 修正Y轴误差
int g_offz = -15;   // 修正Z轴误差
int hx, hy, hz, turetemp;
 
// 初始化陀螺仪
void initGyro()
{
  /*****************************************
  * ITG 3200
  * 电源管理设置:
  * 时钟选择为内部振荡器
  * 无复位、无睡眠模式
  * 无待机模式
  * 采样率 = 1KHz
  * 参数为+ / - 2000度/秒
  * 低通滤波 = 5Hz
  * 没有中断
  ******************************************/
  writeTo(GYRO, G_PWR_MGM, 0x00);
  writeTo(GYRO, G_SMPLRT_DIV, 0x07); // EB, 50, 80, 7F, DE, 23, 20, FF
  writeTo(GYRO, G_DLPF_FS, 0x1E); // +/- 2000 dgrs/sec, 1KHz, 1E, 19
  writeTo(GYRO, G_INT_CFG, 0x00);
}
 
 
void getGyroscopeData(int * result)
{
  /**************************************
  Gyro ITG-3200 I2C
  注册:
  temp MSB = 1B, temp LSB = 1C
  x axis MSB = 1D, x axis LSB = 1E
  y axis MSB = 1F, y axis LSB = 20
  z axis MSB = 21, z axis LSB = 22
  *************************************/
 
  int regAddress = 0x1B;
  int temp, x, y, z;
  byte buff[G_TO_READ];
 
  readFrom(GYRO, regAddress, G_TO_READ, buff); // 从ITG3200读取数据
 
  result[0] = ((buff[2] << 8) | buff[3]) + g_offx;
  result[1] = ((buff[4] << 8) | buff[5]) + g_offy;
  result[2] = ((buff[6] << 8) | buff[7]) + g_offz;
  result[3] = (buff[0] << 8) | buff[1]; // 温度
 
}
 
void setup()
{
  lcd.begin(16, 2);  //初始化LCD
  delay(100);
  Wire.begin();  //初始化I2C
  delay(100);
  lcd.setBacklight(HIGH);
  initGyro();
  Serial.begin(9600);
}
 
void loop()
{
  int gyro[4];
  getGyroscopeData(gyro);
  hx = gyro[0] / 14.375; // 输出值转换为角速度,单位是度/秒
  hy = gyro[1] / 14.375;
  hz = gyro[2] / 14.375;
  turetemp = 35+ ((double) (gyro[3] + 13200)) / 280; // 输出值转换为摄氏度
 
  lcd.clear(); //清屏
  lcd.print("X="); //使屏幕显示文字X=
  lcd.print(hx);
  Serial.print("X=");
  Serial.print(hx);
  lcd.setCursor(8, 0);
  lcd.print("Y=");
  lcd.print(hy);
  Serial.print("Y=");
  Serial.print(hy);
  lcd.setCursor(0, 1);
  lcd.print("Z=");
  lcd.print(hz);
  Serial.print("Z=");
  Serial.print(hz);
  lcd.setCursor(8, 1);
  lcd.print("F=");
  Serial.print("F=");
  Serial.print(turetemp);
  Serial.println("C");
  lcd.print(turetemp);
  lcd.print((char)223);
  lcd.print("C");
  delay(100);  //延时0.1秒,刷新频率这里进行调整
}
 
//---------------- 函数
// 将值写入累加器中的地址寄存器
void writeTo(int DEVICE, byte address, byte val) {
   Wire.beginTransmission(DEVICE); // 开始传输数据到累加器
   Wire.send(address);        //  发送寄存器地址
   Wire.send(val);        //  发送要写入的值
   Wire.endTransmission(); // 结束传输
}
 
 
// 从累加器的地址寄存器中读取buff数组数据
void readFrom(int DEVICE, byte address, int num, byte buff[]) {
  Wire.beginTransmission(DEVICE); // 开始传输数据到累加器
  Wire.send(address);        // 发送读取的地址
  Wire.endTransmission(); // 结束传输
 
  Wire.beginTransmission(DEVICE); // 开始传输数据到累加器
  Wire.requestFrom(DEVICE, num);    //  从累加器请求6个字节数据
 
  int i = 0;
  while(Wire.available())    
  { 
    buff[i] = Wire.receive(); // 接收一个字节
    i++;
  }
  Wire.endTransmission(); // 结束传输
}

Example

The projects and application examples.

OCTOPUS GYRO Module C.JPG


OB.jpg

Soil-OB-06.jpg



SHD IOE01 6.jpg


PushButtonS-07.jpg

Version Tracker

Revision Descriptions Release
v0.9b Initial public release date

Bug Tracker

Bug Tracker is the place you can publish any bugs you think you might have found during use. Please write down what you have to say, your answers will help us improve our products.

Resources

How to buy

Click here to buy:http://www.elecfreaks.com/estore/octopus-3-axis-gyro-sensor.html

See Also

Other related products and resources.

Licensing

This documentation is licensed under the Creative Commons Attribution-ShareAlike License 3.0 Source code and libraries are

licensed under GPL/LGPL, see source code files for details.

External Links

Links to external webpages which provide more application ideas, documents/datasheet or software libraries