Pages: [1]   Go Down
Author Topic: i2c on a gyro  (Read 847 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 hi everyone i try to program my RM-G146 chip with acce, gyro and magnetometer and this is my code...i only tried to get data from my accelerometer but my ouput is always zero... and i dont know whats wrong... please help...this is the device http://www.roboard.com/G146.html
#include "Wire.h"     
#define gyro_addr 0xD0 
#define magne_addr 0x3C 
#define acce_addr 0x30   
 
 
void setup()
{
  Wire.begin();     
  Serial.begin(9600);
}
 
 
  void getdata_gyro()
  {
  }
   
 
  void getdata_acce(byte *a, byte *b)
  {
   
    Wire.beginTransmission(acce_addr);
    Wire.send(0);   
    Wire.endTransmission();
 
   
    Wire.requestFrom(acce_addr, 2); 
    *a = Wire.receive(); 
    *b = Wire.receive(); 
  }
 
  void getdata_magne()
  {
  }
   
void loop()
{
 byte aa, bb;    //variables for storage
 
 getdata_gyro();
 getdata_acce(&aa, &bb); 
 getdata_magne();
 
 
 Serial.print("a= ");
 Serial.print(aa, HEX);    //prints the value of aa
 Serial.print("\n b=");
 Serial.print(bb, HEX);    //prints the value of bb
}
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 115
Posts: 5380
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wire.endTransmission returns a status value of the send. '0' is success. Anything else is an error. That should give you a place to start troubleshooting. Try something like this:
Code:
byte rtnVal = Wire.endTransmission();
Serial.println(rtnVal,DEC);
http://arduino.cc/en/Reference/WireEndTransmission
« Last Edit: October 27, 2011, 05:09:10 am by SurferTim » Logged

Worcester, MA
Offline Offline
God Member
*****
Karma: 2
Posts: 623
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It looks like you're using the 8 bit I2C addresses for the device, when using Wire you need to use the 7 bit address only.  Divide each of the addresses by 2 and use those numbers.
Logged

I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter

Pages: [1]   Go Up
Jump to: