Loading ...
Sorry, an error occurred while loading the content.

How to write into the registers of I2C devices?

Expand Messages
  • cacarreto
    Hello, Has anyone used the SD21 servo controller from Devantech with Intellibrain? The SD21 is accessed over the I2C bus at address 0xC2. There are three
    Message 1 of 3 , May 1, 2007
    • 0 Attachment
      Hello,

      Has anyone used the SD21 servo controller from Devantech with
      Intellibrain? The SD21 is accessed over the I2C bus at address 0xC2.
      There are three internal registers associated with each of the 21
      servo's (the speed, the low byte and the high byte of the position).
      The position (low byte/high byte) is a 16 bit number which directly
      sets the output pulse width in uS. For example, 1500 (1500uS or 1.5mS)
      will sets the servo to its center position.

      How can we write the 2 bytes into the position registers?

      SD21 Technical Specification: http://www.robot-
      electronics.co.uk/htm/sd21tech.htm

      Thank you,
      Carlos
    • RidgeSoft
      Carlos, You need to do something like this: public void setSpeed(I2CMaster i2cMaster, int servoNumber, int speed) throws IOException { i2cMaster.transfer(0xC2,
      Message 2 of 3 , May 1, 2007
      • 0 Attachment
        Carlos,

        You need to do something like this:

        public void setSpeed(I2CMaster i2cMaster, int servoNumber, int speed)
        throws IOException {
        i2cMaster.transfer(0xC2, new byte[] {(byte)(servoNumber * 3 + 1),
        (byte)speed, (byte)(speed >> 8)}, null);
        }

        You can fetch the I2C bus master object like this:

        I2CMaster i2cMaster = IntelliBrain.getI2CMaster();

        This code hasn't been tested, but it should give you a sense of what you
        need to do.

        RidgeSoft Support


        --- In intellibrain@yahoogroups.com, "cacarreto" <ccarreto@...> wrote:
        >
        > Hello,
        >
        > Has anyone used the SD21 servo controller from Devantech with
        > Intellibrain? The SD21 is accessed over the I2C bus at address 0xC2.
        > There are three internal registers associated with each of the 21
        > servo's (the speed, the low byte and the high byte of the position).
        > The position (low byte/high byte) is a 16 bit number which directly
        > sets the output pulse width in uS. For example, 1500 (1500uS or 1.5mS)
        > will sets the servo to its center position.
        >
        > How can we write the 2 bytes into the position registers?
        >
        > SD21 Technical Specification: http://www.robot-
        > electronics.co.uk/htm/sd21tech.htm
        >
        > Thank you,
        > Carlos
        >
      • cacarreto
        Thank you for the example. Here is a tested code that moves servo 1 and servo 21 in sequence. Regards, Carlos import com.ridgesoft.io.I2CMaster; import
        Message 3 of 3 , May 3, 2007
        • 0 Attachment
          Thank you for the example.

          Here is a tested code that moves servo 1 and servo 21 in sequence.

          Regards,
          Carlos


          import com.ridgesoft.io.I2CMaster;
          import com.ridgesoft.intellibrain.IntelliBrain;
          import java.io.IOException;

          public class SD21 {
          public static void main(String args[]) {
          try {
          I2CMaster i2cMaster = IntelliBrain.getI2CMaster();

          int p1 = 1000;
          int p2 = 2000;
          while(true) {
          setMove(i2cMaster, 0, 0, p1);
          Thread.sleep(1000);
          setMove(i2cMaster, 20, 0, p2);
          Thread.sleep(1000);
          int aux = p1;
          p1 = p2;
          p2 = aux;
          }
          }
          catch (Throwable t) {
          t.printStackTrace();
          }
          }

          public static void setMove(I2CMaster i2cMaster, int servoNumber,
          int speed, int position) throws IOException {
          i2cMaster.transfer(0xc2, new byte[] {(byte)(servoNumber * 3),
          (byte)speed,
          (byte)position,
          (byte)position >> 8)},
          null);
          }
          }
        Your message has been successfully submitted and would be delivered to recipients shortly.