Go Down

Topic: i2c on a gyro (Read 976 times) previous topic - next topic

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
}

SurferTim

#1
Oct 27, 2011, 12:01 pm Last Edit: Oct 27, 2011, 12:09 pm by SurferTim Reason: 1
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: [Select]
byte rtnVal = Wire.endTransmission();
Serial.println(rtnVal,DEC);

http://arduino.cc/en/Reference/WireEndTransmission

wayneft

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.
I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy