Skip to content

Loading…

Update Adafruit_PWMServoDriver.cpp Fixed setPWM - beginTransmission now works #3

Merged
merged 1 commit into from

2 participants

@larz99

Hi!

So happy to be able to contribute.

Corrected setPWM.  Transmission now works.

Line 53:  Set MODE1 register to " old mode or 0xA1"
This enables autoincrement allowing multibyte transmissions to be sent.

Can now set a sequence of regsiters in one transmission.

@larz99 larz99 Update Adafruit_PWMServoDriver.cpp
Corrected setPWM.  Transmission now works.

Line 53:  Set MODE1 register to " old mode or 0xA1"
This enables autoincrement allowing multibyte transmissions to be sent.

Can now set a sequence of regsters in one transmission.
118557f
@ladyada
Adafruit Industries member

Thanks!!!

@ladyada ladyada merged commit 3606610 into adafruit:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 18, 2012
  1. @larz99

    Update Adafruit_PWMServoDriver.cpp

    larz99 committed
    Corrected setPWM.  Transmission now works.
    
    Line 53:  Set MODE1 register to " old mode or 0xA1"
    This enables autoincrement allowing multibyte transmissions to be sent.
    
    Can now set a sequence of regsters in one transmission.
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 5 deletions.
  1. +8 −5 Adafruit_PWMServoDriver.cpp
View
13 Adafruit_PWMServoDriver.cpp
@@ -50,13 +50,14 @@ void Adafruit_PWMServoDriver::setPWMFreq(float freq) {
write8(PCA9685_PRESCALE, prescale); // set the prescaler
write8(PCA9685_MODE1, oldmode);
delay(5);
- write8(PCA9685_MODE1, oldmode | 0x80);
+ //write8(PCA9685_MODE1, oldmode | 0x80);
+ write8(PCA9685_MODE1, oldmode | 0xa1); // This sets the MODE1 register to turn on auto increment.
+ // This is why the beginTransmission below was not working.
// Serial.print("Mode now 0x"); Serial.println(read8(PCA9685_MODE1), HEX);
}
void Adafruit_PWMServoDriver::setPWM(uint8_t num, uint16_t on, uint16_t off) {
- /*
- // hmm doesnt work, whyso?
+ // hmm doesnt work, whyso? ( Not in AI mode. See line 54 above. ( Works now!! :D )
Wire.beginTransmission(_i2caddr);
Wire.write(LED0_ON_L+4*num);
Wire.write(on);
@@ -64,11 +65,13 @@ void Adafruit_PWMServoDriver::setPWM(uint8_t num, uint16_t on, uint16_t off) {
Wire.write(off);
Wire.write(off>>8);
Wire.endTransmission();
- */
+
+/*
write8(LED0_ON_L+4*num, on);
write8(LED0_ON_H+4*num, on >> 8);
write8(LED0_OFF_L+4*num, off);
- write8(LED0_OFF_H+4*num, off >> 8);
+ write8(LED0_OFF_H+4*num, off >> 8);
+*/
}
uint8_t Adafruit_PWMServoDriver::read8(uint8_t addr) {
Something went wrong with that request. Please try again.