Photon + PCA9685 Library


#1

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!


#2

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.


#3

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.


#4

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!


#5

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?


#6

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


#7

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!


#8

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