Photon + PCA9685 Library

Hello,

I am trying to figure out how to drive a servo with a Particle Photon via a PCM9685 board.

When I look in the Library of Particle Build, there is an existing library that looks like already does what I need!

I have been using the following diagram to figure out where the I2C wires should go.

Based on the library’s github page, I think I have the wiring correct

I have (Particle) wired to -> (PCM):
3V3 ->V+
GND -> GND
D0 -> SCA
D1 -> SCL

The motor controller is getting its own 5v power supply via a wall wart, and the photon is powered via USB connected to my laptop. I am not sure if the USB is necessary… it boots up when I have the 5v connected but I have read the external power is necessary due to fluctuations from servo power usage.

When I flash any of the examples (servo.ino from the PCM9685 library) the LED on the board eventually starts breathing green… indicating it’s not connected to the cloud anymore. I figured out how to USB flash the tinker app with particle-cli, which I have to do every time the servo sketches “crash” the board and make it go green.

I’m not sure how to debug this… it’s my first project with the Photon. Any suggestions on how to wire this or even better what I can do to debug what’s going on would be appreciated!

I tested the servo.ino example and it worked fine for me on a Photon running 0.5.0.

However, upon more carefully reading your problem, assuming you have the Adafruit 815 board, I think the problem is that you connected 3V3 to V+ on the breakout. Hopefully you didn’t damage your Photon. Breakout V+ is connected connected to the breakout external power supply. You want to connect the Photon 3V3 to the breakout VCC pin instead.

4 Likes

Thanks so much, the attached picture is a really great reference!

I’m hopeful that the board isn’t damaged because it still ran the LED blink sketch with no problem.

I’ll try wiring it up as per your instructions and post my findings later tonight.

I switched the 3V3 pin on the particle from V+ on the PCM to VCC and it worked like a charm!

I don’t think I’ve ever been so excited to get something so simple working.

Thank you so much!

2 Likes

Hello, I think I’m having exactly the same problem. Same setup and same problem (Photon starts breathing green after about 10 seconds), but I did make sure that 3V3 on Photon is connected to VCC on PCM9685. It’s a PCM9685 clone and it’s powered externally, though with 3.3V as I’m driving small vibrating motors instead of servos. Last I checked, I hadn’t damaged the Photon either; when it gets to the point when it breathes green, I put it in safe mode and can successfully flash the Tinker app on it. Photo of my set up below (minus the wiring to the motor). Would very much appreciate any suggestions on what to do.

@dirtybirdnj, is it still working perfectly for you up till now?

Breathing green usually means something in your code is preventing servicing the particle cloud for more than about 10 seconds. There are numerous ways to solve this problem:

  1. Make sure your code in loop() returns all the way out of loop frequently. This generally a good way to design your code, anyway.

  2. Or if there’s an inner loop inside loop(), call Particle.process() in it.

  3. Or call delay() in any inner loops which also handles processing Particle cloud events.

  4. Or use SYSTEM_THREAD(ENABLED); This doesn’t technically solve the problem of blocking loop, but it does allow the cloud processing to run independently of loop, so you won’t breathe green. It’s the easiest fix because you just need to paste one line in your code. But purists will scoff :slight_smile:
    https://docs.particle.io/reference/firmware/photon/#system-thread

Rick

2 Likes

Thank you; that was very helpful. Just a quick update: it looks like that it was indeed some code in the loop() section of the servo example that was causing the problem. I’m still trying to get the code to work…

BTW, I tried using SYSTEM_THREAD(ENABLED) but that caused a red light error. I can’t remember which error code it was, since I kind of panicked I just reset the Photon right away!

Hello all,

I have a custom board using the PCA9685. I have CA LED’s on the board. Powering this setup using VIN on the photon for testing. The LED’s light up but i cannot change colors. I have in the loop a simple blink test. The device is being detected by the i2cScanner. Any thoughts on what im doing wrong?

#include "Adafruit_PWMServoDriver.h"
#include "Particle.h"

SYSTEM_MODE(MANUAL);
SYSTEM_THREAD(ENABLED);

void startUp() { WiFi.selectAntenna(ANT_AUTO); }

STARTUP(startUp());
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x55);

void setup() {
  pwm.begin();
  pwm.setPWMFreq(1000);
}

void loop() {

  for (size_t i = 0; i < 16; i++) {
    pwm.setPin(i, 0);
  }
  delay(2000);
  for (size_t i = 0; i < 16; i++) {
    pwm.setPin(i, 4095);
  }
  delay(2000);
}

schematic attached
image

1 Like

Hey @Ali, It’s been a long time since you posted this, but I wonder:
Did you finally manage to make above sketch work?

I ordered a few PCA9685 chips, because they look promising for what I want to achieve…

Looking forward to your answer!

The issue on the schematic was the enable pin was improperly connected. I had to jump the wires.

1 Like

All right!
Thanks for your quick reply!
:pray:

Has anyone been able to use this pca 9685 board with a photon to power a servo? The current library only has an example for LED’s. Should I be using the same function, setVal() to control the servo as well?

Thanks!

Hi,
The library available on Web Ide is old like a coal (8 years !) and this setVal() function does not exist in original Adafruit library instead you can use setPin() which provide identical functionality but as name sugested is for a PIN I’ll use setPWM() for servos.
here is an example based on Adafruit lib which is more fresh (just 2 years old)
I didn’t test it as I don’t have PCA9685 but , is compiling fine and should work out of the box with no issue

and here some resources:

Best,
Arek

Arek,

Thanks for the reply and help! I’ll give that a try.

Best,
Jason

1 Like