SKU: OT2057-C46 Numéro d’article: AA217 EAN: 4247196800434
Dimensions
Longueur : 6,9cm
Largeur : 2,5cm
Hauteur : 1,5cm
Voici comment connecter le Driver servo PWM 12 bits 16 canaux I2C à un Arduino UNO ou à un ESP32, avec un exemple de sketch que tu peux téléverser directement.
Cet exemple communique avec le driver PWM 12 bits PCA9685 16 canaux via I2C. L'Arduino initialise la carte à 50 Hz et fait balayer le signal PWM sur Channel 0 d'avant en arrière, parfait pour tester des servos standards ou le fondu de LED. Ouvrez le Serial Monitor à 115200 baud pour voir les valeurs d'impulsion actuelles.
/*
* ==================================================================
* Generated by Codey.online — https://www.codey.online
* ==================================================================
* Project : PCA9685 16-Channel PWM Servo Driver Demo
* Board : Arduino UNO (arduino:avr:uno)
* Parts : 16 Channel 12-Bit PWM Servo Driver I2C
* Libraries : Adafruit PWM Servo Driver Library 3.0.3
*
* Codey Online is an AI-powered browser IDE for Arduino and ESP32.
* Describe your project and Codey writes the code, draws the wiring
* diagram and uploads it to your board, straight from the browser.
* This code is free to use, modify and share, without warranty.
* ==================================================================
*/
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// Pulse length bounds for standard 50Hz servos
const uint16_t SERVOMIN = 150; // ~0.75 ms pulse (0 degrees)
const uint16_t SERVOMAX = 600; // ~2.25 ms pulse (180 degrees)
void setup() {
Serial.begin(115200);
Serial.println(F("PCA9685 16-Channel Servo Driver Demo"));
pwm.begin();
pwm.setOscillatorFrequency(27000000);
pwm.setPWMFreq(50); // 50 Hz PWM for hobby servos
delay(10);
}
void loop() {
Serial.println(F("Moving to 0 degrees..."));
for (uint16_t pulse = SERVOMIN; pulse < SERVOMAX; pulse += 5) {
pwm.setPWM(0, 0, pulse);
delay(20);
}
delay(500);
Serial.println(F("Moving to 180 degrees..."));
for (uint16_t pulse = SERVOMAX; pulse > SERVOMIN; pulse -= 5) {
pwm.setPWM(0, 0, pulse);
delay(20);
}
delay(500);
}
Bibliothèques nécessaires : Adafruit PWM Servo Driver Library 3.0.3
Wiring diagram and example code generated by Codey.online — https://www.codey.online
Ce projet commande un servomoteur à l'aide du driver PWM 12 bits à 16 canaux PCA9685 via I2C. Comme le PCA9685 et les servos fonctionnent en 5V, un convertisseur de niveau logique bidirectionnel à 4 canaux protège les broches I2C 3.3V de l'ESP32 (GPIO 21 et GPIO 22). Le sketch initialise le PCA9685 et fait balayer en continu le servo sur Channel 0 d'avant en arrière.
/*
* ==================================================================
* Generated by Codey.online — https://www.codey.online
* ==================================================================
* Project : PCA9685 16-Channel PWM Servo Driver Demo
* Board : ESP32 DEVKIT V1 (esp32:esp32:esp32doit-devkit-v1)
* Parts : 16 Channel 12-Bit PWM Servo Driver I2C
* Libraries : Adafruit PWM Servo Driver Library 3.0.3
*
* Codey Online is an AI-powered browser IDE for Arduino and ESP32.
* Describe your project and Codey writes the code, draws the wiring
* diagram and uploads it to your board, straight from the browser.
* This code is free to use, modify and share, without warranty.
* ==================================================================
*/
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
// Default I2C address is 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x40);
// 12-bit pulse lengths (out of 4096) for standard 50Hz servos
#define SERVOMIN 150 // Minimum pulse length (~0.75 ms / 0 degrees)
#define SERVOMAX 600 // Maximum pulse length (~2.25 ms / 180 degrees)
#define SERVO_FREQ 50 // Standard analog servo frequency (50 Hz)
const uint8_t servoChannel = 0;
void setup() {
Serial.begin(115200);
Serial.println("PCA9685 Servo Driver Demo");
// Initialize I2C on ESP32 pins (SDA=GPIO 21, SCL=GPIO 22)
Wire.begin(21, 22);
pwm.begin();
pwm.setOscillatorFrequency(27000000);
pwm.setPWMFreq(SERVO_FREQ);
delay(10);
Serial.println("Ready! Sweeping servo on Channel 0...");
}
void loop() {
// Sweep from 0 to 180 degrees
for (uint16_t pulselen = SERVOMIN; pulselen <= SERVOMAX; pulselen += 5) {
pwm.setPWM(servoChannel, 0, pulselen);
delay(15);
}
delay(500);
// Sweep back from 180 to 0 degrees
for (uint16_t pulselen = SERVOMAX; pulselen >= SERVOMIN; pulselen -= 5) {
pwm.setPWM(servoChannel, 0, pulselen);
delay(15);
}
delay(500);
}
Bibliothèques nécessaires : Adafruit PWM Servo Driver Library 3.0.3
Wiring diagram and example code generated by Codey.online — https://www.codey.online