I am using a teensy-lc to control IMUs to record data into Matlab. I've been doing research and I discovered that I can use a MUX4051 multiplexer to control 3 IMUs. I'm not sure how to do this, can someone please help?
Hi and welcome.
Another possibility for you to research: you may be able to connect all 3 devices directly to the teensy. The teensy already has 2 i2c interfaces. Some mpu6050 breakout boards have an AD0 pad that allows you to use 2 devices on the same i2c bus. This would allow up to 4 6050 devices to be connected to the teensy with no extra hardware.
Paul
Hey Paul, I thought about that, but I can't figure out how to use the SDA1 and SCL1 along with the SDA0 and the SCL0 ports at the same time. If you could help that'd be great!
dshah3:
Hey Paul, I thought about that, but I can't figure out how to use the SDA1 and SCL1 along with the SDA0 and the SCL0 ports at the same time. If you could help that'd be great!
Well, I don't own an teensy 3/LC, but a google search gave this as the first suggested link. Seems to be straight forward enough in itself...
...however, the more difficult part may be getting the 6050 library to utilise both i2c interfaces. I suspect this would be true for your 4051 mux idea too.
Do you have code working for a single 6050 yet? If so, can you post it and include links to the libraries used?
#include "Wire.h"
// I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files
// for both classes must be in the include path of your project
#include "I2Cdev.h"
#include "MPU6050.h"
// class default I2C address is 0x68
// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default for InvenSense evaluation board)
// AD0 high = 0x69
//MPU6050 accelgyro;
MPU6050 accelgyroIC1(0x68);
MPU6050 accelgyroIC2(0x69);
int16_t ax1, ay1, az1;
int16_t gx1, gy1, gz1;
int16_t ax2, ay2, az2;
int16_t gx2, gy2, gz2;
#define LED_PIN 13
bool blinkState = false;
void setup() {
// join I2C bus
Wire.begin();
// initialize serial communication
// (38400 chosen because it works as well at 8MHz as it does at 16MHz, but
// it's really up to you depending on your project)
Serial.begin(38400);
// initialize device
Serial.println("Initializing I2C devices...");
//accelgyro.initialize();
accelgyroIC1.initialize();
accelgyroIC2.initialize();
// verify connection
Serial.println("Testing device connections...");
Serial.println(accelgyroIC1.testConnection() ? "MPU6050 #1 connection successful" : "MPU6050 connection failed");
Serial.println(accelgyroIC2.testConnection() ? "MPU6050 #2 connection successful" : "MPU6050 connection failed");
// configure Arduino LED for
pinMode(LED_PIN, OUTPUT);
}
void loop() {
// read raw accel/gyro measurements from device
accelgyroIC1.getMotion6(&ax1, &ay1, &az1, &gx1, &gy1, &gz1);
accelgyroIC2.getMotion6(&ax2, &ay2, &az2, &gx2, &gy2, &gz2);
// these methods (and a few others) are also available
//accelgyro.getAcceleration(&ax, &ay, &az);
//accelgyro.getRotation(&gx, &gy, &gz);
// display tab-separated accel/gyro x/y/z values
Serial.print("MPU1:\t");
Serial.print(ax1); Serial.print("\t");
Serial.print(ay1); Serial.print("\t");
Serial.print(az1); Serial.print("\t");
Serial.print(gx1); Serial.print("\t");
Serial.print(gy1); Serial.print("\t");
Serial.println(gz1);
// display tab-separated accel/gyro x/y/z values
Serial.print("MPU2:\t");
Serial.print(ax2); Serial.print("\t");
Serial.print(ay2); Serial.print("\t");
Serial.print(az2); Serial.print("\t");
Serial.print(gx2); Serial.print("\t");
Serial.print(gy2); Serial.print("\t");
Serial.println(gz2);
// blink LED to indicate activity
blinkState = !blinkState;
digitalWrite(LED_PIN, blinkState);
}
This is my code for having two imus on SDA0 and SCL0
Edit that post and put code tags in please! It should like
this.
Its the </> icon. (We get so fed up of telling everybody about that. No-one ever reads the "Read This" post...)
Also include the other thing I asked for.
I fixed it. Sorry Paul. The code gets the raw sensor data from two pus.
http://www.i2cdevlib.com/devices/mpu6050#source
MPU 6050 Lib
http://diyhacking.com/projects/MPU6050.zip
Hmm... those two libraries are very long & complicated and they will both have to be significantly modified to run with 2 x i2c busses. They were both written for chips with only one i2c bus.
I'm certain it can be done, but you will need someone who is very fluent in C++ and has all the same hardware as you to be able to test the mods they make.
Perhaps there is a way to make this work without modifying the libraries. Maybe it will be possible to fool them into using one i2c bus or the other by changing things around "behind the scenes", so that the libraries never need to know there is more than one bus.
If you read through the libraries, when they need to send or receive data over the i2c bus, they use the "Wire" object. In your case you will have two objects corresponding to the two busses, perhaps called "Wire1" and "Wire2". Maybe you can set the "Wire" object to refer to either "Wire1" or "Wire2" just before you call the library functions to read the mpu readings.