How to send to i2c PCA9685 PWM driver from Pure Data patch

I am trying to work out how to set up my Pd patch to send to 16 leds on a PCA9685 PWM Driver over I2C. I Have written a custom .json using the field.json as reference, but don’t know how to turn on the led and set brightness from within the Pure Data patch itself….

Is it like any other output from within Pd? [s led_14 @hvparam]

I know the PCA9685 accepts various brightness formats (float, 8 bit gamma corrected, raw) - hoping to work out how to format and send a brightness value from within the Pd patch also….

Any help greatly appreciated! Learning so much, but still feeling so clueless…!!!

Correct, you’d send a float value between 0 and 1 to [s led_14 @hv_param] and it should set the level accordingly.

This is how it works on the Field at least.

1 Like

love it - thats easy. thanks for the quick response!

1 Like

Hello,

Trying to muddle through setting up a PCA9686 PWM driver using plugdata and custom .json. I am able to compile to the daisy, and i have set an audio oscillator in the patch to make sure it is up and running (it sings properly), but the PCA9685 just turns all the leds on and isn’t seeming to communicate with the daisy or the patch….

Are there any tricks anyone has found to get I2C working through Pd patch and custom .json? I copied the .json I2C parts from the field .json, and am sending 0-1 range float outputs [s led1 @hvparamhvparamhvparamhvparamhvparamhvparamhvparamhvparam] from within the Pd patch. But its not working. Are there any other steps to set up the PCA9685, like addressing within the Pd patch, setting PWM rate, .json settings I need to assign, or other I2C settings….?

I have the .json link below if anyone can look it over sometime…. or is it better if i paste it into the post?

Thanks so much - can’t seem to work out what I am doing wrong. ….so much to learn!!!

{
    "name": "ledtrial",
    "som": "seed",
    "audio": {
        "channels": 2
    },
    "parents": {
        "i2c": {
            "component": "i2c",
            "pin": {
                "scl": 11,
                "sda": 12
            }
        },
        "led_driver": {
            "component": "PCA9685",
            "address": "{0x40}",
            "parent": "i2c",
            "driver_count": 1
        }
    },
    "components": {
        "lfo1": {
            "component": "AnalogControl",
            "pin": 15
        },
        "led1": {
            "component": "PCA9685Led",
            "index": 0,
            "parent": "led_driver"
        },
        "led2": {
            "component": "PCA9685Led",
            "index": 1,
            "parent": "led_driver"
        },
        "led3": {
            "component": "PCA9685Led",
            "index": 2,
            "parent": "led_driver"
        },
        "led4": {
            "component": "PCA9685Led",
            "index": 3,
            "parent": "led_driver"
        },
        "led5": {
            "component": "PCA9685Led",
            "index": 4,
            "parent": "led_driver"
        },
        "led6": {
            "component": "PCA9685Led",
            "index": 5,
            "parent": "led_driver"
        },
        "led7": {
            "component": "PCA9685Led",
            "index": 6,
            "parent": "led_driver"
        },
        "led8": {
            "component": "PCA9685Led",
            "index": 7,
            "parent": "led_driver"
        },
        "led9": {
            "component": "PCA9685Led",
            "index": 8,
            "parent": "led_driver"
        },
        "led10": {
            "component": "PCA9685Led",
            "index": 9,
            "parent": "led_driver"
        },
        "led11": {
            "component": "PCA9685Led",
            "index": 10,
            "parent": "led_driver"
        },
        "led12": {
            "component": "PCA9685Led",
            "index": 11,
            "parent": "led_driver"
        },
        "led13": {
            "component": "PCA9685Led",
            "index": 12,
            "parent": "led_driver"
        },
        "led14": {
            "component": "PCA9685Led",
            "index": 13,
            "parent": "led_driver"
        },
        "led15": {
            "component": "PCA9685Led",
            "index": 14,
            "parent": "led_driver"
        },
        "led16": {
            "component": "PCA9685Led",
            "index": 15,
            "parent": "led_driver"
        }
    }
}

It’s [s led1 @hv_param] notice the underscore.

Can you share a minimal patch? without that it’s impossible to help debug.

If it compiles then your json is correct.

(and please format the json code when you share it. use the “preformatted text” option. had to edit your message to make it readable)

1 Like

apologies for the formatting, and thankyou for the tips. ….that stupid mistake was on one entire patch missing the underscore - thanks for reminding me.

i needed to send reversed values to get the leds working properly - 0 to light them and 1 to turn them off. don’t know what i have done to make it that way, but that is going out the [s led1 @hv_param] in the patch. perhaps it is in the hardware? but it works. : ) i will try to be more regular and vigilant, and keep on learning!

thanks again for your help. patch and .json below for completeness….

trial led ring patch

{
  "name": "trial",
  "som": "seed",
  "audio": {
    "channels": 2
  },
  "parents": {
    "i2c": {
      "component": "i2c",
      "pin": {
        "scl": 11,
        "sda": 12
      }
    },
    "led_driver": {
      "component": "PCA9685",
      "address": "{0x40}",
      "parent": "i2c",
      "driver_count": 1
    }
  },
"components": {
    "knob_1": {
      "component": "AnalogControl",
      "pin": 15
    },
    "led_1": {
      "component": "PCA9685Led",
      "index": 0,
      "parent": "led_driver"
    },
    "led_2": {
      "component": "PCA9685Led",
      "index": 1,
      "parent": "led_driver"
    },
    "led_3": {
      "component": "PCA9685Led",
      "index": 2,
      "parent": "led_driver"
    },
    "led_4": {
      "component": "PCA9685Led",
      "index": 3,
      "parent": "led_driver"
    },
    "led_5": {
      "component": "PCA9685Led",
      "index": 4,
      "parent": "led_driver"
    },
    "led_6": {
      "component": "PCA9685Led",
      "index": 5,
      "parent": "led_driver"
    },
    "led_7": {
      "component": "PCA9685Led",
      "index": 6,
      "parent": "led_driver"
    },
    "led_8": {
      "component": "PCA9685Led",
      "index": 7,
      "parent": "led_driver"
    },
    "led_9": {
      "component": "PCA9685Led",
      "index": 8,
      "parent": "led_driver"
    },
    "led_10": {
      "component": "PCA9685Led",
      "index": 9,
      "parent": "led_driver"
    },
    "led_11": {
      "component": "PCA9685Led",
      "index": 10,
      "parent": "led_driver"
    },
    "led_12": {
      "component": "PCA9685Led",
      "index": 11,
      "parent": "led_driver"
    },
    "led_13": {
      "component": "PCA9685Led",
      "index": 12,
      "parent": "led_driver"
    },
    "led_14": {
      "component": "PCA9685Led",
      "index": 13,
      "parent": "led_driver"
    },
    "led_15": {
      "component": "PCA9685Led",
      "index": 14,
      "parent": "led_driver"
    },
    "led_16": {
      "component": "PCA9685Led",
      "index": 15,
      "parent": "led_driver"
    }
  }
}

Double check on your electronics? We’ve seen people make reverse connections before :wink:

Sounds like the pd/heavy side works correctly though!

1 Like

Btw instead of resetting the counter you can also just put [% 16] :wink:

1 Like

cheers @dreamer there are so many tricks i need to keep at the front of my brain with Pd. it will only get better!
will post the finished effects unit when it is all working - it will have 3 daisies inside, and more spaghetti in my Pd patches than an all weekend italian festival….

1 Like