0

parts

  1. Three-axis rate gyro on breakout board: gyro datasheet, breakout board "datasheet"
  2. Arduino Uno: pinout

goal: I want to periodically read a single axes' angular rate. As rvbarreto pointed out, Adafruit built an Arduino library for this sensor, so I'm playing around with its example file.

configuration: poor man's EE schematic

I have a 5600 Ohm pull-up connected to the SDA and SCL pins each on the Arduino. The internal pull-ups of the Arduino are too weak according to this thread.

code: (Adafruit library's sensorapi example)

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_FXAS21002C.h>

/* Assign a unique ID to this sensor at the same time */
Adafruit_FXAS21002C gyro = Adafruit_FXAS21002C(0x0021002C);
//Adafruit_FXAS21002C gyro = Adafruit_FXAS21002C(0x21);

void displaySensorDetails(void)
{
  sensor_t sensor;
  gyro.getSensor(&sensor);
  Serial.println("------------------------------------");
  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
  Serial.print  ("Unique ID:    0x"); Serial.println(sensor.sensor_id, HEX);
  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" rad/s");
  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" rad/s");
  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" rad/s");
  Serial.println("------------------------------------");
  Serial.println("");
  delay(500);
}

void setup(void)
{
  Serial.begin(9600);

  /* Wait for the Serial Monitor */
  while (!Serial) {
    delay(1);
  }

  Serial.println("Gyroscope Test"); Serial.println("");

  /* Initialise the sensor */
  if(!gyro.begin())
  {
    /* There was a problem detecting the FXAS21002C ... check your connections */
    Serial.println("Ooops, no FXAS21002C detected ... Check your wiring!");
    while(1);
  }

  /* Display some basic information on this sensor */
  displaySensorDetails();
} 

void loop(void)
{
  /* Get a new sensor event */
  sensors_event_t event;
  gyro.getEvent(&event);

  /* Display the results (speed is measured in rad/s) */
  Serial.print("X: "); Serial.print(event.gyro.x); Serial.print("  ");
  Serial.print("Y: "); Serial.print(event.gyro.y); Serial.print("  ");
  Serial.print("Z: "); Serial.print(event.gyro.z); Serial.print("  ");
  Serial.println("rad/s ");
  delay(500);
}

NOTE: I noticed that Adafruit's Github had removed a line of code (line 67) in their library's main .cpp file. I edited my library code to reflect that change.

problem: I keep getting the "Ooops, no FXAS21002C detected ... Check your wiring!" error message.

questions:

  1. Am I connecting my pull-up resistors correctly?
  2. Should I not power VDD and VDD_IO on the same rail? Can they even be powered by the Uno?
  • I'm assuming that the gyro is on a breakout board of some sort? Linking the manual/schematic might be helpful. – uint128_t Apr 17 '17 at 3:58
  • 3
    Your I2C resistors are at least 10 times to large, and your code seemingly has nothing to do with this sensor, or at least not with it's "gyro-ness". If you are new to this, you'd probably do best to pick a part for which others have already devised wiring and Arduino code, otherwise you'll need to make your own deep dive into I2C basics and data sheet fundamentals. – Chris Stratton Apr 17 '17 at 4:49
  • The arduino Wire library activates the 10k internal pull-up resistors of the TWI and SCK pins. – jms Apr 17 '17 at 9:36
  • 1
    There is a library for this sensor made by Adafruit available at Arduino IDE. If you have an up-to-date version of Arduino IDE, go to Sketch > Include Library > Manage Library and then type "FXAS21002C" and you will see it. Just install it and you will have the library and examples to test, explore and get this working. – rvbarreto Apr 17 '17 at 19:03
  • The 0x20 is the 7-bit address. Or 0x21 if you opt to configure it for that address. The full slave address byte is either 0x40 or 0x41 depending on if it's write or read. You should look at table 9 on page 12. – Majenko Apr 17 '17 at 19:31
0

I needed to connect the gyro's reset input to V_DD_IO. See gyro datasheet, table 1, pin 4. This corresponds to pin 7/RST_21002 on the breakout board. The gyro works like a charm now!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.