Shop OBEX P1 Docs P2 Docs Learn Events
PCA9685 with the propeller? — Parallax Forums

PCA9685 with the propeller?

Hey guys, noob here.
Is there any way to use the PCA9685 i2c port expender with the propeller?
https://www.adafruit.com/product/815
Thanks!

Comments

  • kwinnkwinn Posts: 8,697
    pico wrote: »
    Hey guys, noob here.
    Is there any way to use the PCA9685 i2c port expender with the propeller?
    https://www.adafruit.com/product/815
    Thanks!

    Yes. I2C is used often on the propeller. Several objects in the OBEX.
  • Indeed -- and you don't have to give up any IO pins, either, as you can share the SDA and SCL pins used by the EEPROM.
  • @anybody
    or if possible: Jérôme Decock

    I found code on the obex for a PCA9685.
    Going to try it soon. No instructions as to supposedly control individual servos.
    Any simple ideas?
    Thank you in advance.
    Martin

  • @jeromelab

    Hello. I have downloaded your code for the PCA9685. Wondering If you are still around and
    If you could give me some simple instructions as to get started. I will be using two servos
    on this device.
    Thank you.
    Martin

  • JonnyMacJonnyMac Posts: 9,620
    edited 2026-01-26 15:38

    If you're only needing to control two servos -- and you have cog to spare -- you can easily do that in Spin (or any other P1 language). The CTRx module (in every cog) has two counters which will let your run two servos (without reconfiguring), and you get nice precision with your pulses (1us in this simple code). I've attached an easy, 2-servo object. it uses the PWM/NCO mode of the counter to create the servo pulses. The code as is lets you set the position in microseconds, but with the resolution of the system counter you could do sub-microsecond (e.g., 0.1) pulses if you like.

    Here's quick check of the object output setting servo channel 0 to 1000us and servo channel 1 to 2000us.

    If you're set on the PCA9685 you should start with downloading the datasheet. You'll need to learn the register assignments for controlling the PWM frequency and the settings for each pin/channel. I think I found the object you reference (which handles the gory details -- and is based on an Adafruit library that has documentation/examples); with the datasheet you should be able to suss out how things work, and get confirmation from an AI agent.

    Link to my PCA9685 chat: https://chatgpt.com/share/6976dc93-4fd0-8006-97ca-524d29b35fb3

    One thing to notice in that chat: with the PCA9685 your position resolution is 4.88us, roughly 5x chunkier than the 1us you can have with easy P1 code. In some applications this won't matter, but if you're looking for very fin control, you may not want to use the PCA9685.

    Edit (26 JAN 26): Over coffee this morning I made some minor improvements to the simple 2-servo object (version is now 1.0.1).

  • JonnyMacJonnyMac Posts: 9,620

    No instructions as to supposedly control individual servos.

    There is a hint in the demo code.

    SERVO.setPWM(servonum, 0, pulselen)
    

    The problem is that pulselen is not in microseconds as we're used to when dealing with servos. If I were going to use the PCA9685 I'd be inclined to add this method to simplify code conversion

    pub us_to_counts(us) : counts
    
    '' Convert microseconds to PCA9685 channel "on" counts
    
      counts := 4096 * us / 20_000
    
Sign In or Register to comment.