Hi,
I purchased for my robot project the VEX Robotics Motor 393 with Integrated Encoder Module and am trying to read the velocity and position data with the mbed. All my attempts so far to get useful data out did not work. Following the description in https://vexforum.com/showthread.php?p=255691 and a template given for the Arduino (GitHub - alexhenning/I2CEncoder: Arduino library to interface with the Vex integrated encoders using I2C.) I managed to initialize the right encoder(http://www.kynix.com/Product/Cate/348.html) (LED light is blinking green), to disable the terminator to the left encoder and to initialize the left encoder (LED light is solid green) with:
// Assign address for right encoder:
char ChangeAddressCommand[2];
char Unterminate[2];
ChangeAddressCommand[0] = I2CENCODER_ADDRESS_CHANGE; //..=0x4D
ChangeAddressCommand[1] = RIGHT_NEW_ADDRESS; //New address (= 0x20) ...
//change the i2c address (I2CENCODER_DEFAULT_ADDRESS=0x60) :
i2c.write(I2CENCODER_DEFAULT_ADDRESS, ChangeAddressCommand,2); // Send command string
// Zero it on initialization
zero();
wait(0.5);
//...Unterminate the first encoder so can speak to second encoder...
Unterminate[0] = I2CENCODER_UNTERMINATE_REGISTER; //...=0x4B
Unterminate[1] = I2CENCODER_TERMINATE_REGISTER; //...=0x4C
i2c.write(RIGHT_NEW_ADDRESS, Unterminate, 2);
//Assign address for left encoder:
ChangeAddressCommand[0] = I2CENCODER_ADDRESS_CHANGE;
ChangeAddressCommand[1] = LEFT_NEW_ADDRESS; //New address (= 0x22)...
//change the i2c address (after this write the :
i2c.write(I2CENCODER_DEFAULT_ADDRESS, ChangeAddressCommand,2); // Send command string
// Zero it on initialization
zero();
After this initialization I try to read the velocity registers with:
char cmd[2];
cmd[0] = I2CENCODER_VELOCITY_REGISTER; //...= 0x44...
ack = i2c.read(RIGHT_NEW_ADDRESS, cmd, 2);
float echo1 = ((cmd[0] << 8) + cmd[1]); //R
As a result I get FFFF in echo1 which results in 0 speed. What am I doing wrong?
Thank you very much for any help.