Pages: [1]   Go Down
Author Topic: i2c on a gyro  (Read 922 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
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
#include "Wire.h"     
#define gyro_addr 0xD0 
#define magne_addr 0x3C 
#define acce_addr 0x30   
void setup()
  void getdata_gyro()
  void getdata_acce(byte *a, byte *b)
    Wire.requestFrom(acce_addr, 2); 
    *a = Wire.receive(); 
    *b = Wire.receive(); 
  void getdata_magne()
void loop()
 byte aa, bb;    //variables for storage
 getdata_acce(&aa, &bb); 
 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

Miramar Beach, Florida
Offline Offline
Faraday Member
Karma: 150
Posts: 6144
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:
byte rtnVal = Wire.endTransmission();
« Last Edit: October 27, 2011, 05:09:10 am by SurferTim » Logged

Worcester, MA
Offline Offline
God Member
Karma: 3
Posts: 623
Arduino rocks
View Profile
 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.

I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter

Pages: [1]   Go Up
Jump to: