Hello all,
I have a 12 LED neopixel ring, which works fine with the Adafruit_NeoPixel.h library using an ESP32.
Since the ESP32 has limited gpio pins for my project I purchased a PCA9685 Module Controller 16 Channel 12 Bit PWM Servo Driver, I know it is called a servo driver but effectively it is a pwm expander and there's no reason why it shouldn't work for other pwm devices. I've seen instances of people controlling single LEDs with it but not neopixel ring. However, in most cases people use Adafruit_PWMServoDriver.h and wire.h library and which does not provide enough parameters to pass to the Adafruit_NeoPixel.h library.
Here is an example of my devices:
Here is my code which works without using a pwm expander:
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN 5 // On Trinket or Gemma, suggest changing this to 1
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 12 //16 Popular NeoPixel ring size
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 500 // Time (in milliseconds) to pause between pixels
byte loopcoloursvariable = 0;
byte runonce = 0;
String command;
void setup() {
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
// END of Trinket-specific code.
Serial.begin(9600);
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
pixels.clear(); // Set all pixel colors to 'off'
}
void loop() {
if (runonce == 0){
runonce = 1;
}
if (Serial.available()) {
command = Serial.readStringUntil('\n');
command.trim();
if (command.equals("1"))
{
setpixelon();
}
if (command.equals("2"))
{
setpixeloff();
}
}
}
void setpixelon(){
//pixels.setPixelColor(0, is zero based, so for a 12 ring neopixel go from 0 - 11
pixels.setPixelColor(0, pixels.Color(0, 0, 50));
pixels.setPixelColor(1, pixels.Color(0, 0, 50));
pixels.setPixelColor(2, pixels.Color(0, 0, 50));
pixels.setPixelColor(3, pixels.Color(0, 0, 50));
pixels.setPixelColor(4, pixels.Color(0, 0, 50));
pixels.setPixelColor(5, pixels.Color(0, 0, 50));
pixels.setPixelColor(6, pixels.Color(0, 0, 50));
pixels.setPixelColor(7, pixels.Color(0, 0, 50));
pixels.setPixelColor(8, pixels.Color(0, 0, 50));
pixels.setPixelColor(9, pixels.Color(0, 0, 50));
pixels.setPixelColor(10, pixels.Color(0, 0, 50));
pixels.setPixelColor(11, pixels.Color(0, 0, 50));
//
pixels.show();
}
void setpixeloff(){
loopcoloursvariable = 0;
pixels.clear(); // Set all pixel colors to 'off'
pixels.setPixelColor(1, pixels.Color(0, 0, 0));
pixels.setPixelColor(2, pixels.Color(0, 0, 0));
pixels.setPixelColor(3, pixels.Color(0, 0, 0));
pixels.show();
}
I would much appreciate any advice on getting these components working together.