Fishbot 四驱版使用PCA9685扩展PWM接口数量
-
板子本身舵机接口不够,可以使用PCA9685进行扩展,该版本价格10元左右,某宝均可购买。
驱动例程如下,PIO工程
platformio.ini
; PlatformIO Project Configuration File ; ; Build options: build flags, source filter ; Upload options: custom upload port, speed and extra flags ; Library options: dependencies, extra library storages ; Advanced options: extra scripting ; ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html [env:featheresp32] platform = espressif32 board = featheresp32 framework = arduino lib_deps = nachtravevl/PCA9685-Arduino@^1.2.15
main.cpp
#include "PCA9685.h" PCA9685 pwmController; // Library using default B000000 (A5-A0) i2c address, and default Wire @400kHz PCA9685_ServoEval pwmServo1; void setup() { Serial.begin(115200); // Begin Serial and Wire interfaces Wire.begin(18,19); pwmController.resetDevices(); // Resets all PCA9685 devices on i2c line pwmController.init(); // Initializes module using default totem-pole driver mode, and default disabled phase balancer pwmController.setPWMFreqServo(); // Set PWM freq to 100Hz (default is 200Hz, supports 24Hz to 1526Hz) for(int i=0;i<16;i++) { pwmController.setChannelPWM(i, pwmServo1.pwmForAngle(0+i*10)); // Set PWM to 128/255, shifted into 4096-land Serial.println(pwmController.getChannelPWM(i)); // Should output 2048, which is 128 << 4 } } void loop() { }