Wish I need a wrapper for my I2C 1 to 16 servo board

Cableguy

Expert
Licensed User
Longtime User
Hi Guys,

I need a wrapper for this board:
815-06.jpg


Here is oficial docs:

https://learn.adafruit.com/downloads/pdf/16-channel-pwm-servo-driver.pdf
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Try the attached library.

B4X:
Sub Process_Globals
   Public Serial1 As Serial
   Public driver As Adafruit_PWMServoDriver
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   driver.Initialize(0x40)
   driver.SetPWMFreq(1600)
   
End Sub
 

Attachments

  • rAdafruit_PWMServoDriver.zip
    4.8 KB · Views: 449

Cableguy

Expert
Licensed User
Longtime User
It seems to work OK...

I'm just having trouble understanding the SetPin and SetPWM methods... I can't understand the logic behind the values
 

Michael1968

Active Member
Licensed User
Longtime User
hi Cableguy,

If i understand it right...

setPWM writes the values to the register of the pca9685
B4X:
void Adafruit_PWMServoDriver::setPWM(uint8_t num, uint16_t on, uint16_t off) {
  //Serial.print("Setting PWM "); Serial.print(num); Serial.print(": "); Serial.print(on); Serial.print("->"); Serial.println(off);

  WIRE.beginTransmission(_i2caddr);
  WIRE.write(LED0_ON_L+4*num);
  WIRE.write(on);
  WIRE.write(on>>8);
  WIRE.write(off);
  WIRE.write(off>>8);
  WIRE.endTransmission();
}

setpin set the values for the on/off registers for the given Channel
B4X:
void Adafruit_PWMServoDriver::setPin(uint8_t num, uint16_t val, bool invert)
{
  // Clamp value between 0 and 4095 inclusive.
  val = min(val, 4095);
  if (invert) {
    if (val == 0) {
      // Special value for signal fully on.
      setPWM(num, 4096, 0);
    }
    else if (val == 4095) {
      // Special value for signal fully off.
      setPWM(num, 0, 4096);
    }
    else {
      setPWM(num, 0, 4095-val);
    }
  }
  else {
    if (val == 4095) {
      // Special value for signal fully on.
      setPWM(num, 4096, 0);
    }
    else if (val == 0) {
      // Special value for signal fully off.
      setPWM(num, 0, 4096);
    }
    else {
      setPWM(num, 0, val);
    }
  }
}

Michael
 

roberto64

Active Member
Licensed User
Longtime User
hi, this is the Adafruit_PWM_Servo_Driver_Library v.2.4.0 update.
regards
 

Attachments

  • rAdafruit_PWMServoDriver.zip
    20.1 KB · Views: 250
Last edited:
Top