Home Forums EasyTransfer Library Support Forum Problems with EasyTransferI2C

Tagged: ,

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #3143
    Anonymous
    Inactive

    Hello,

    I’m having a problem trying to get two Arduinos to talk to each other over an I2C interface using what I believe is the latest version of your EasyTransferI2C library, dated 13 February 2014.

    I have a Mega acting as a Master controller for a mobile robot passing, in this version, velocity and rotation commands to an old Arduino Duemilanove via an I2C link. The Demilanove, in turn, passes data to the motor controllers.

    I have attached copies of the programmes for the Master (i.e. Mega) and Secondary (i.e. Duemilanove) below.

    The output displayed on the monitor is of the form:-

    .
    .
    .
    Start of loop()
    Start of loop()
    Start of loop()

    Start Byte = 15
    Velocity = 0
    Rotation = 0
    Encoders = 0

    Start of loop()
    Start of loop()
    Start of loop()
    .
    .
    .

    I don’t understand why only the first value (the Start Byte) is getting through and not the other values. Any suggestions appreciated.

    *****************************************************************************************
    Master Software

    /*
    * A mini version of Master 2.1.0 with everything stripped out except for that required to pass
    * the necessary information to the secondary controller.
    *
    * Uses the EasyTransferI2C library to transfer data.
    */

    #include<Wire.h> // Add a replacement Wire Library.
    #include<EasyTransferI2C.h> // Library to aid the transfer of data
    #include<SoftwareSerial.h>
    #include<Streaming.h>

    // Create EasyTransfer object
    EasyTransferI2C ET;

    // Secondary Control Data message format
    struct SCP
    {
    byte startByte;
    int velocity;
    int rotation;
    byte resetEncoders;
    };

    // Naming the group of data
    SCP mcp;

    const byte startByte = 0x0F;
    #define slaveI2CAddress 0x02

    byte velocity = 0;
    byte rotation = 0;
    byte resetEncoders = 20;

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

    ET.begin(details(mcp), &Wire);

    digitalWrite(SCL, HIGH);
    digitalWrite(SDA, HIGH);

    delay(2000);
    }

    void loop()
    {
    velocity = 120;
    rotation = 20;

    mcp.startByte = startByte;
    mcp.velocity = velocity;
    mcp.rotation = rotation;
    mcp.resetEncoders = resetEncoders;

    ET.sendData(slaveI2CAddress);

    Serial <<(“Velocity = “) << _DEC(velocity) <<endl <<endl;

    delay(1000);

    velocity = 0;
    rotation = 0;

    mcp.startByte = startByte;
    mcp.velocity = velocity;
    mcp.rotation = rotation;
    mcp.resetEncoders = resetEncoders;

    ET.sendData(slaveI2CAddress);

    delay(1000);
    }

    ***************************************************************************************

    Secondary Software

    /*
    * A quick program to interface with the Mega and pass new values for velocity and rotation
    * to the Kangaroo controller.
    */

    #include<Wire.h>
    #include<EasyTransferI2C.h>
    #include<Kangaroo.h>
    #include<SoftwareSerial.h>
    #include<Streaming.h>

    // create object
    EasyTransferI2C ET;

    // Secondary Control Data message format
    struct SCP
    {
    byte startByte;
    int velocity;
    int rotation;
    byte resetEncoders;
    };

    // Naming the group of data
    SCP mcp;

    #define startByte 0x0F
    #define slaveI2CAddress 0x02

    // Kangaroo Serial Port. (By default, the mixed mode channels on the Kangaroo are ‘D’ and ‘T’.)

    SoftwareSerial SerialPort(10, 11);
    KangarooSerial K(SerialPort);
    KangarooChannel Drive(K, ‘D’);
    KangarooChannel Turn(K, ‘T’);

    int velocity = 0; // The commanded velocity (i.e. Speed or ‘Drive’)
    int rotation = 0; // The commanded rotation (i.e. ‘Turn’)
    byte resetEncoders = 0;

    void setup()
    {
    Serial.begin(9600);
    Serial <<(“Started Setup”) <<endl;

    Wire.begin(slaveI2CAddress);
    ET.begin(details(mcp), &Wire);
    Wire.onReceive(command);

    SerialPort.begin(9600); // Open link to the Kangaroo controller
    SerialPort.listen();

    Drive.start(); // Dummy commands to the controller
    Turn.start();

    Drive.s(0); // Ensure no initial motion
    Turn.s(0);

    Serial << (“Initial Velocity = “) << _DEC(velocity) <<endl <<endl;

    delay(1000); // Let everything settle down
    }

    void loop()
    {
    Serial <<(“Start of loop()”) <<endl;
    if(ET.receiveData())
    {
    Drive.s(velocity);
    Turn.s(rotation);

    Serial << endl;
    Serial << (“Start Byte = “) <<_DEC(startByte) <<endl;
    Serial << (“Velocity = “) << _DEC(velocity) <<endl;
    Serial << (“Rotation = “) << _DEC(rotation) <<endl;
    Serial << (“Encoders = “) << _DEC(resetEncoders) <<endl <<endl;
    }
    }

    void command(int numBytes) {}

    ***************************************************************************************

    Knowing me, the problem is probably something stupid I’ve done or not done but it’s been driving me nuts trying to resolve it.

    Thanks in anticipation.

    Freddie

    #3145
    Anonymous
    Inactive

    Sorry, I’ve just realised there is an error in the “Secondary Software” listed in my first message. I should not have defined the value of the startByte. It was this declared value that was being printed out by the monitor. Having removed that declaration, the messages are being printed out as:-

    .
    .
    .
    Start of loop()
    Start of loop()
    Start of loop()

    Start Byte = 0
    Velocity = 0
    Rotation = 0
    Encoders = 0

    Start of loop()
    Start of loop()
    Start of loop()
    .
    .
    .

    This suggests to me that the Master software is not transmitting the data in the first place.

    Oh well, back to the drawing board or, at least, the heap of wiring, motors, batteries etc., that make up this design.

    Freddie

    #3146
    Anonymous
    Inactive

    BANG……(ouch)

    Bang……(ouch)

    Bang……(My head)

    repeat as required.

    The banging you hear is my head making violent contact with the adjacent wall as I realise the stooopid mistake I made.

    I failed to define the variables velocity and rotation after their receipt by the secondary processor. The loop() has now been rewritten as

    void loop()
    {
    if(ET.receiveData())
    {
    velocity = mcp.velocity;
    rotation = mcp.rotation;

    Drive.s(velocity);
    Turn.s(rotation);
    }
    }

    and the system works as it should.

    (Images of Johnny 5 leaping up and shouting “I’m ALIVE!!”.

    Now to see if I can a data package to go the other way.

    Freddie

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.