Teensy3.6 + MPU6050 + Wire1 problem

Status
Not open for further replies.

Ozgok

Member
It's been 3 years since I started using Teensy 3.6. Thank you very much for designing such a card. I have come up to date without any problems. However, there is a problem I could not solve for 10 days. I'm exhausted.
I want to do angular control on my robot using MPU6050 with my Teensy 3.6 card. I use J. Rowberg's library. I can read data from SDA0 and SCL0 (18,19) pins. But on the card I designed, SDA and SCL pins are connected to pins 38 and 37. So SDA1 and SCL1.
I can use SDA0 and SCL0 (18,19) pins with Wire.begin (). Logically, I should be able to use SDA1 and SCL1pins with Wire1.begin (). But no data is displayed on the serial screen.
I read all the articles I could find in the forum. I worked 10 days in Wire, i2c_t3, i2cdev and mpu6050 libraries. But I did not get any results. SDA and SCL pins were pulled up with both 2.7kohm and 4.7kohm resistors. There is no problem with electronic connection because it works with SDA0 and SCL0. I would be grateful if you tell me how to use pins 38 and 37 as SDA and SCL. Thank you all so much in advance.
Code:
#include "I2Cdev.h"
#include "MPU6050.h"
//#define I2CDEV_IMPLEMENTATION == I2CDEV_TEENSY_3X_WIRE
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
#include "Wire.h"
#endif

MPU6050 accelgyro;
int16_t ax, ay, az;
int16_t gx, gy, gz;
float t1 = 0, t2 = 0;
float gyroZt1 = 0;
float gyroZt2 = 0;
float aciZ = 0;
int steta, teta, hata;

void setup() {
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
  Wire.begin();
  Serial.begin(115200);
  accelgyro.initialize();
  accelgyro.setXAccelOffset(-649);
  accelgyro.setYAccelOffset(507);
  accelgyro.setZAccelOffset(1429);
  accelgyro.setXGyroOffset(58);
  accelgyro.setYGyroOffset(31);
  accelgyro.setZGyroOffset(100);
  delay(5000);
  digitalWrite(13, LOW);
  gyroZt2 = gyroZt1;
  t2 = t1;
  t1 = millis();
  accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
  gyroZt1 = gx;
  aciZ = aciZ + 0.00000001 + ((t1 - t2) * (gyroZt1 + gyroZt2 )) * 0.00000382;
  steta = int(aciZ + 180.0);
  Serial.print("aciZ\t");
  Serial.print(aciZ);
  Serial.print("\t");
  Serial.print("steta\t");
  Serial.println(steta);
  delay(1000);
}

void loop()
{
  gyroZt2 = gyroZt1;
  t2 = t1;
  t1 = millis();
  accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
  gyroZt1 = gx;
  aciZ = aciZ +  ((t1 - t2) * (gyroZt1 + gyroZt2 )) * 0.00000382;  //0.00000001
  teta = int(aciZ + 180.0);
  Serial.print("teta\t");
  Serial.println(teta);
}
 
Its been a while since I used Jeff Rowberg's i2cdevlib with the MPU6050. :)

Going over his i2cdev.cpp file again it looks like he has Wire hardcoded for reading/writing MPU6050 device registers. Where he has Wire in he functions yo will probably have to change to use Wire1. WARNING> This was not an in-depth review but just quick observation.
 
Thanks for your attention mjs513. But i tryed changing Wire to Wire1 in I2Cdev files.
I am at home now. Tomorrow, i will try and check again at my lab. I would be grateful for any help..
 
Know this is probably an obvious question but did you change Wire.begin to Wire1.begin in your sketch?
 
Another obvious question. The Teensy needs pull-up resistors on each of the i2c buses. Do you have pull-up resistors on the 2nd I2C pins? These are resistors that connect the SDA and SCL pins in parallel with 3.3v. Typically on 3.3v systems, 2.2K resistors are appropriate, but if you have a complex I2C layout, you might need other values.

Now, you only need one set up pull-up resistors on each i2c bus. If you have other i2c devices on the main I2C bus those devices might have the necessary pull-up resistors. Similarly, if you are using either the audio shield or either of the prop shields, those boards all include pull-up resistors. So you might try adding pull-up resistors for second i2c bus.
 
Only other thing I would add is to run the PRJC I2C scanner to make sure it sees the device on Wire1 - you will need to edit that sketch to go from Wire to Wire1
 
Hi Michael! The MPU6050 has pullup resistors (2.2k) on its board as you see at the photo attachment. I also connect nothing to main i2c bus. I work on breadboard just now. If i succeed i move teensy and mpu to my main card that i designed before. There isn’t an electronic problem. I think i have to change some codes on libraries. But i couldn’t find. There is something out of my sight. Thanks...
7B4CFEA1-A902-4059-8792-EC7FC8F21F03.jpg
 
Thanks a lot mjs513. I change again Wire to Wire1 in I2Cdev files. Job done. But still i don't understand what was wrong before. May be there was something out of my sight. Thanks all. Have a nice day.
 
Status
Not open for further replies.
Back
Top