Problem:
When I directly wire the 9DOF sensor tot he Trinket MO, then I can accurately read the sensor data. However, when I attempt to connect the sensor through the multiplexer, then I get an initial value but it does not update. Also, notice that the sensor isn't sending the Min Max Resolution values.
I'm using function tcaselect(int) to define the usable pin - choosing pin 0.
Output
This is the output of the code as viewed in the Com Monitor from the Arduino IDE
DiagramI2C Scanner
------------------------------------
Sensor: FXAS21002C
Driver Ver: 1
Unique ID: 0x21002C
Max Value: 0.00 rad/s
Min Value: 0.00 rad/s
Resolution: 0.00 rad/s
------------------------------------
X: 0.00 Y: 0.00 Z: 0.03 rad/s
X: 0.00 Y: 0.00 Z: 0.03 rad/s
X: 0.00 Y: 0.00 Z: 0.03 rad/s
X: 0.00 Y: 0.00 Z: 0.03 rad/s
X: 0.00 Y: 0.00 Z: 0.03 rad/s
X: 0.00 Y: 0.00 Z: 0.03 rad/s
X: 0.00 Y: 0.00 Z: 0.03 rad/s
X: 0.00 Y: 0.00 Z: 0.03 rad/s
X: 0.00 Y: 0.00 Z: 0.03 rad/s
X: 0.00 Y: 0.00 Z: 0.03 rad/s
X: 0.00 Y: 0.00 Z: 0.03 rad/s
X: 0.00 Y: 0.00 Z: 0.03 rad/s
Here is the fritzing diagram for the project. Apologies for the homemade Trinket MO ( I couldn't find it on the GitHub download).
http://fritzing.org/projects/multiplexer-with-fxas21002
Code
Here's the code for the sensor reading with attempt to route through the multiplexer:
Code: Select all
// Wire Master Reader
// by Nicholas Zambetti <http://www.zambetti.com>
// Demonstrates use of the Wire library
// Reads data from an I2C/TWI slave device
// Refer to the "Wire Slave Sender" example for use with this
// Created 29 March 2006
// This example code is in the public domain.
#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);
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);
}
#define TCAADDR 0x70
void tcaselect(uint8_t i) {
if (i > 7) return;
Wire.beginTransmission(TCAADDR);
Wire.write(1 << i);
Wire.endTransmission();
}
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
while (!Serial); // Leonardo: wait for serial monitor
Serial.println("\nI2C Scanner");
tcaselect(0);
displaySensorDetails();
}
void loop()
{
/* 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);
}