Reading VEX Integrated Encoder with mbed

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.

This website is for the VEXIQ product line, though the 393 motor is for EDR. https://vexforum.com/ will give you much better help.

Please, PLEASE tell me this isn’t a very advanced SPAM…

Try the VRC forum you linked, you’ll have better chance of meeting more experienced hackers there.
Anyway, your usage of MBED i2c API seems to be wrong - if you need to read a register over I2C, you first need to write the register address (in addition to the device address).
From top of my head, try this:


  char cmd[2];
  cmd[0] = I2CENCODER_VELOCITY_REGISTER; //...= 0x44...
  i2c.write(RIGHT_NEW_ADDRESS, cmd, 1);
  i2c.read(RIGHT_NEW_ADDRESS, cmd, 2);
  float echo1 = ((cmd[0] << 8) + cmd[1]); //R