From c8cd28f5197c443806b7c393fa3db5387730d5e4 Mon Sep 17 00:00:00 2001 From: Dominik Bartsch Date: Thu, 10 Jun 2021 20:19:25 +0200 Subject: [PATCH] pca9685 --- platformio.ini | 2 +- src/main.cpp | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/platformio.ini b/platformio.ini index cf72ee8..8dd2a92 100644 --- a/platformio.ini +++ b/platformio.ini @@ -25,4 +25,4 @@ upload_flags = lib_deps = # The exact version - ottowinter/PCA9685 16-Channel PWM Driver Module Library @ 1.2.9 \ No newline at end of file + ottowinter/PCA9685 16-Channel PWM Driver Module Library @ 1.2.9 diff --git a/src/main.cpp b/src/main.cpp index 820f052..a7e0906 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,6 +11,9 @@ #include "wifi_credentials.h" +#include +#include "PCA9685.h" + const char* ssid = STASSID; const char* password = STAPSK; @@ -99,7 +102,7 @@ void setup_webserver() { - +PCA9685 pwmController; void setup() { Serial.begin(115200); @@ -107,6 +110,9 @@ void setup() { WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); + Wire.begin(); // Wire must be started first + Wire.setClock(400000); // Supported baud rates are 100kHz, 400kHz, and 1000kHz + while (WiFi.waitForConnectResult() != WL_CONNECTED) { Serial.println("Connection Failed! Rebooting..."); delay(5000); @@ -158,6 +164,15 @@ void setup() { Serial.println(WiFi.localIP()); setup_webserver(); + + pwmController.resetDevices(); // Software resets all PCA9685 devices on Wire line + + pwmController.init(B000000); // Address pins A5-A0 set to B000000 + pwmController.setPWMFrequency(100); // Default is 200Hz, supports 24Hz to 1526Hz + + pwmController.setChannelPWM(0, 128 << 4); // Set PWM to 128/255, but in 4096 land + + Serial.println(pwmController.getChannelPWM(0)); // Should output 2048, which is 128 << 4 }