Help me pls!

hello All Arduino Programmer

I am new in Arduino World. I have some questions and i need some tipps pls

i have one Arduino Due and i want to controll three deveices with I2C as Slave(ons deveice as Read from other slaves and write one them) and the two others (slave as Read) but i have no idee how i do this .

the register pins are 0x48, 0x49 and 0x69

I need your help and your tipps.

regards

Post links to the I2C devices that you wish to access and look for libraries of ready written code.

Did you add those smilleys in there? Don’t thin so, edit the post and use code tags, see How to use this forum. And while you’re at it. CHANGE THE TITLE TO SOMETHING USEFUL!

Please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum Your code is too long to study quickly without copying to a text editor.

…R

Maybe start with the short example sketch here for the MPU-6050, and when you get that going, extend it to cover the other devices. http://playground.arduino.cc/Main/MPU-6050

septillion: Did you add those smilleys in there? Don't thin so, edit the post and use code tags, see How to use this forum. And while you're at it. CHANGE THE TITLE TO SOMETHING USEFUL! [/quote] no i did not add this smilleys.

Okay, so why aren't you changing it?

septillion: Okay, so why aren't you changing it?

i know this code is toooo long and i am new here and i dont how to add the code readable here?

type ``` [code] ```

paste your code after that type ``` [/code] ``` after that

If the code is more than 9000 characters (give or take a few), you can attach it instead of including it as above.

TheTraveler: i know this code is toooo long and i am new here and i dont how to add the code readable here?

That's why there is a big fat stickey at the top of each board with How to use this forum ;)

the register pins are 0x48, 0x49 and 0x69

Did you mean the addresses were 0x48 etc?

AWOL: Did you mean the addresses were 0x48 etc?

yes this is the address

OP, please go back to your first post and type in the code tags as requested in reply #9, before and after your existing code to put it in its own window as seen in other posts.

Then edit the thread title to something useful that reflects what you are asking (as requested).

Following the forum rules and doing as requested by other members will get more help than ignoring the requests.

Weedpharma

Code:

#include "I2Cdev.h"
#include "MPU6050.h"
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
#include "Wire.h"
#endif


#define MPU 0x68          //Sensor MPU6050-GY
#define M1 0x47           // Motorcontroller Links
#define M2 0x48           //Motorcontroller Rechts

#define OUTPUT_READABLE_ACCELGYRO





int16_t ax, ay, az;    //Accelometer
int16_t gx, gy, gz;    //Gyroscope


void setup() {
  
    #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
        Wire.begin();
    #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
        Fastwire::setup(400, true);
    #endif
    
 Serial.begin(9600);
 Serial.println("Initialisierung von I2C Geraete...");
  accelgyro.initialize();

 Serial.println("Duchfuehrugstest von MPU6050...");
 Serial.println(accelgyro.testConnection() ? "MPU6050 Verbindung erfolgreich \n" : "MPU6050 Verbindung nicht Verfuegbar\n");
  
}


void loop() {

accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);  // Lesen/Schreiben raw accel/gyro measurements                from device
    
    accelgyro.getAcceleration(&ax, &ay, &az); //Mehtoden zum lesen
    accelgyro.getRotation(&gx, &gy, &gz);     //Acceleration und Rotation

    #ifdef OUTPUT_READABLE_ACCELGYRO
        
        Serial.print("Accel/Gryo: \t");   
        Serial.print(ax); Serial.print("\t");
        Serial.print(ay); Serial.print("\t");
        Serial.print(az); Serial.print("\t");
        Serial.print(gx); Serial.print("\t");
        Serial.print(gy); Serial.print("\t");
        Serial.println(gz);
    #endif

    #ifdef OUTPUT_BINARY_ACCELGYRO
        Serial.write((uint8_t)(ax >> 8)); Serial.write((uint8_t)(ax & 0xFF));
        Serial.write((uint8_t)(ay >> 8)); Serial.write((uint8_t)(ay & 0xFF));
        Serial.write((uint8_t)(az >> 8)); Serial.write((uint8_t)(az & 0xFF));
        Serial.write((uint8_t)(gx >> 8)); Serial.write((uint8_t)(gx & 0xFF));
        Serial.write((uint8_t)(gy >> 8)); Serial.write((uint8_t)(gy & 0xFF));
        Serial.write((uint8_t)(gz >> 8)); Serial.write((uint8_t)(gz & 0xFF));
    #endif

}

this my code for reading from the Accelometer and Gyroscop
and my problem ist, i dont know how to connect the Sensor-Deveice MPU6050 with the other deceice. i have no idee.

this Code is for the other deveice

#include<Wire.h>  //enthält die I2C Verbindung

//#include <usci/layout.h>
//#include <usci/isr.h>
//#ifdef __MSP430_HAS_EUSCI_B0__
//#include <msp430x20x3.h>

#define M 0x48
#define M 0x49
//byte x=0;





void setup() {

  Serial.begin(115200);             //start serielle Verbindung
  Wire.begin();                     // Initialisieren der I2C Verbindung

}


void loop() {
  
  Wire.beginTransmission(M);      // öffnen der Verbindung
  Wire.write("x is.... ");             // 
  Wire.write(0x00);                   // sends 0 byte
  Wire.endTransmission();           // Ende der Übertragung
  //delay(1000);

  Wire.beginTransmission(M);             // Übertragung
  Wire.write(0x01);                         // Send  Bit
  Wire.endTransmission();                 // Ende der Verbindung
  //delay(1000);


  //Wire.requestFrom(M,1);                  // Request 1 byte from the specified address
  //while(Wire.available()==0);
  //int c=Wire.read();                                      // Werte auslesen
  //Serial.print(c);



}

i want to controll the motor with the MPU6050 per I2C

septillion:
That’s why there is a big fat stickey at the top of each board with How to use this forum :wink:

ok now i added the code again

Still, the title is pretty useless and will not attract a lot of people.

When calling

Wire.beginTransmission(address);
//or
Wire.requestFrom(address,1);

You specify the address of the device you want to talk to. Simply use the address of the device YOU want to talk to :)

septillion:
Still, the title is pretty useless and will not attract a lot of people.

When calling

Wire.beginTransmission(address);

//or
Wire.requestFrom(address,1);



You specify the address of the device you want to talk to. Simply use the address of the device YOU want to talk to :)

thanks for tipps. but i have only one Arduino Due. and the question is, can i connect all deveices on the Arduino

If they respond to different addresses, yes. That's why it's called a bus.