Wa Koodu

Koodu Arduino ati Fidio fun PCA9685 16-ikanni 12-Bit Servo Oludari V1

Koodu Arduino ati Fidio fun PCA9685 16-ikanni 12-Bit Servo Oludari V1

Nínú ẹ̀kọ́ yìí, a óò ṣàwárí bí a ṣe le lo PCA9685 16-channel 12-bit servo olùdarí láti ọ̀dọ̀ NXP Semiconductor. Module yìí gbà ọ́ láàyè láti darí àwọn servo tó tó 16 tàbí kí o ṣí àwọn LED ṣẹ́ pẹ̀lú ìwọ̀n pípé nípa lílo pulse width modulation (PWM). Ní ìparí ẹ̀kọ́ yìí, ìwọ óò ní ètò tí ó ṣiṣẹ́ tí ó lè darí ọ̀pọ̀lọpọ̀ servo ní ọ̀kọ̀ọ̀kan tàbí ní àkókò kan náà.

PCA9685 module-0

Láti túmọ̀ àkóónú ẹ̀kọ́ yìí síwájú sí i, mo rọ̀ ọ́ pé kí o wo fídíò tí ó wà pẹ̀lú rẹ̀ (nínú fídíò ní 00:00) fún ìfihàn tí a fojú rí ti ètò àti ìlànà kóòdù.

Ohun èlò Tí A Ṣàlàyé

Module PCA9685 jẹ́ pátákó tí ó kún fún àwọn ohun èlò tí ó lè darí ọ̀pọ̀lọpọ̀ servo nípasẹ̀ ìbánisọ̀rọ̀ I2C. Ó ní àwọn ikanni 16, tí ó gbà ọ́ láàyè láti so àwọn servo tó tó 16 pọ̀, ọ̀kọ̀ọ̀kan pẹ̀lú àmì ìdarí tirẹ̀. Module yìí ń ṣiṣẹ́ pẹ̀lú agbára 5V àti pé a ṣe é fún àwọn àmì PWM, tí ó ṣe pàtàkì fún ìdarí ipò servo ní ìwọ̀n pípé.

Pátákó náà ní àwọn pinni tí a yà sọ́tọ̀ fún agbára (VCC), ilẹ̀ (GND), àti ìbánisọ̀rọ̀ (SDA àti SCL). Pinni SDA ni a lò fún gbígbé data, nígbà tí pinni SCL jẹ́ àmì aago, èyí méjèèjì ni a so pọ̀ mọ́ àwọn pinni analog A4 àti A5 ti Arduino. Ètò yìí ṣe ìrànlọ́wọ́ láti rí i pé ìbánisọ̀rọ̀ tí ó gbẹ́kẹ̀lé wà láàrin Arduino àti module PCA9685.

Àwọn Àlàyé Datasheet

OlùṣeNXP Semiconductor
Nọ́mbà apáPCA9685
Fóltì Logic/IO3.3 V sí 5.5 V
Fóltì ìpèsè2.3 V sí 5.5 V
Ìjáde lọ́wọ́ (fún ikanni)25 mA tó pọ̀jù
Ìjáde tó ga jù (fún ikanni)100 mA tó pọ̀jù
Ìtọ́sọ́nà ìgbohùnsáfẹ́fẹ́ PWM24 Hz sí 1.6 kHz
Àwọn ìwọ̀n ìgbohùnsáfẹ́fẹ́ ìfidání0.3 V (rẹ̀lẹ̀) / 0.7 V (ga)
Ìdínkù fóltì / RDS(on) / ìkún0.5 V tó pọ̀jù
Àwọn ìwọ̀n ooru-40 °C sí 125 °C
ÀpótíHTSSOP-28
Àwọn àkíyèsí / oríṣiríṣi16-channel PWM olùdarí

  • Rí i pé ìpèsè agbára 5V wà pẹ̀lú ìjáde tó tó (1A ni a dábàá).
  • Má ṣe fi agbára Arduino ta àwọn servo ní tààrà láti yẹra fún ìbàjẹ́.
  • Lo àwọn pinni I2C tí ó tọ́: SDA sí A4 àti SCL sí A5.
  • Ṣàtúnṣe àwọn iye ìgbòkègbodò pulse gẹ́gẹ́ bí àwọn servo rẹ ṣe rí.
  • Ṣàyẹ̀wò ìsopọ̀ fún ìtọ́sọ́nà tí ó tọ́: GND, VCC, àti àmì.
  • Rò nípa gbígbé ooru kúrò fún àwọn ohun èlò tí ń lo agbára púpọ̀.

Àwọn Ìtọ́sọ́nà Ìsopọ̀

Arduino wiring for PCA9685 to control 16 servo motors
Arduino wiring for PCA9685 to control 16 servo motors

Láti so PCA9685 pọ̀ mọ́ Arduino rẹ, bẹ̀rẹ̀ nípa sísopọ̀ agbára àti ilẹ̀. So pinni VCC lórí PCA9685 pọ̀ mọ́ ìjáde 5V lórí Arduino. Lẹ́yìn náà, so pinni GND lórí PCA9685 pọ̀ mọ́ GND lórí Arduino. Ní àtẹ̀gùn, so pinni SDA lórí PCA9685 pọ̀ mọ́ pinni A4 lórí Arduino, àti pinni SCL pọ̀ mọ́ A5.

Fún àwọn servo, so okun àmì pọ̀ mọ́ ikanni tí ó bá mu lórí PCA9685 (bíi CH0 fún servo àkọ́kọ́), okun agbára pọ̀ mọ́ ìpèsè agbára ọ̀tọ̀ (nítorí àwọn servo lè nílò ìjáde tó pọ̀ ju èyí tí Arduino lè pèsè), àti okun ilẹ̀ pọ̀ mọ́ ilẹ̀ tí a pín pọ̀ pẹ̀lú PCA9685. Rí i pé àwọn okun àmì, agbára, àti ilẹ̀ wà ní ìtọ́sọ́nà tí ó tọ́ láti yẹra fún ìbàjẹ́ àwọn ohun èlò rẹ.

Àwọn Àpẹẹrẹ Kóòdù & Ìtọ́sọ́nà

Nínú apá ìṣètò kóòdù náà, a bẹ̀rẹ̀ module PCA9685 pẹ̀lú pwm.begin() àti a ṣètò ìgbohùnsáfẹ́fẹ́ PWM pẹ̀lú pwm.setPWMFreq(60);. Èyí ṣètò ìgbohùnsáfẹ́fẹ́ ìbánisọ̀rọ̀ fún àwọn servo.

void setup() {
  Serial.begin(9600);
  Serial.println("16 channel Servo test!");
  pwm.begin();
  pwm.setPWMFreq(60);  // Analog servos run at ~60 Hz updates
}

Nínú lúùpù náà, a darí àwọn servo nípa ṣíṣètò àwọn iye PWM tí ó bá àwọn igun tí a fẹ́ mu. Iṣẹ́ angleToPulse(int ang) ṣàwòrán igun sí ìgbòkègbodò pulse tí ó yẹ, èyí tí ó ṣe pàtàkì fún ìdarí ipò servo ní ìwọ̀n pípé.

void loop() {
  for( int angle =0; angle<181; angle +=20){
    delay(500);
    pwm.setPWM(0, 0, angleToPulse(angle) );
  }
}

Ní ìparí, iṣẹ́ angleToPulse(int ang) yí igun padà sí ìgbòkègbodò pulse nípa lílo àwọn ìwọ̀n pulse tí ó kéré jù àti tí ó tóbi jù tí a ṣàlàyé. Èyí gbà ọ́ láàyè láti darí ipò servo rẹ ní ìrọ̀rùn nípa igun tí o fẹ́ gba.

int angleToPulse(int ang){
   int pulse = map(ang,0, 180, SERVOMIN,SERVOMAX);
   Serial.print("Angle: ");Serial.print(ang);
   Serial.print(" pulse: ");Serial.println(pulse);
   return pulse;
}

Ìfihàn / Ohun Tí O Lè Retí

Nígbà tí ohun gbogbo bá ti sopọ̀ dáradára àti tí a ti gbé kóòdù náà sílẹ̀, ìwọ óò rí i pé servo ń gbé nípasẹ̀ àwọn igun tí a ṣàlàyé ní àwọn ìgbésẹ̀ 20 ìwọ̀n. Bí servo kò bá hùwà bí a ti retí, ṣàyẹ̀wò ìsopọ̀ fún àwọn ìsopọ̀ tí ó tọ́ àti rí i pé ìpèsè agbára tó (nínú fídíò ní 12:30).

Àwọn Àkókò Fídíò

  • 00:00 - Ìfihàn sí PCA9685
  • 02:30 - Àwọn ìtọ́sọ́nà ìsopọ̀
  • 05:00 - Ìtọ́sọ́nà kóòdù
  • 10:15 - Ìfihàn ìdarí servo
  • 12:30 - Yíyanjú àwọn ìṣòro tí ó wọ́pọ̀

Aworan

PCA9685 module-0
PCA9685 module-0
PCA9685 module-1
PCA9685 module-1
PCA9685 module-2
PCA9685 module-2
PCA9685 module-3
PCA9685 module-3
PCA9685 module
PCA9685 module
Arduino wiring for PCA9685 to control 16 servo motors
Arduino wiring for PCA9685 to control 16 servo motors
36-PCA9685 video V1: Arduino Code to control 16 servo motor, Basic
Ede: C++
/*
 * Original source: https://github.com/adafruit/Adafruit-PWM-Servo-Driver-Library
 * This is the Arduino code for the PCA9685 16-channel servo controller.
 * Watch the video for details and demo: http://youtu.be/y8X9X10Tn1k
 *  get code and wiring diagram from http://robojax.com/RTJ27
 
 * Watch the video for this code: 
 * 
 * Related Videos:
V5 video of PCA9685 32 Servo with ESP32 with WiFi: https://youtu.be/bvqfv-FrrLM
V4 video of PCA9685 32 Servo with ESP32 (no WiFi): https://youtu.be/JFdXB8Za5Os
V3 video of PCA9685: how to control 32 servo motors: https://youtu.be/6P21wG7N6t4
V2 Video of PCA9685: 3 different ways to control servo motors: https://youtu.be/bal2STaoQ1M
V1 Video introduction to PCA9685 to control 16 servos: https://youtu.be/y8X9X10Tn1k

 * Written by Ahmad Shamshiri for Robojax Video channel: www.Robojax.com
 * Date: December 16, 2017, in Ajax, Ontario, Canada
 * Permission granted to share this code, given that this
 * note is kept with the code.
 * Disclaimer: This code is "AS IS" and for educational purposes only.
 * This code has been downloaded from https://robojax.com
 * 
 */
/*************************************************** 
  This is an example for our Adafruit 16-channel PWM & Servo driver.
  Servo test - this will drive 16 servos, one after the other.

  Pick one up today in the Adafruit shop!
  ------> http://www.adafruit.com/products/815

  These displays use I2C to communicate; 2 pins are required to  
  interface. For Arduino UNOs, that's SCL -> Analog 5, SDA -> Analog 4.

  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution.
 ****************************************************/

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);

// Depending on your servo make, the pulse width min and max may vary; you 
// want these to be as small/large as possible without hitting the hard stop
// for max range. You'll have to tweak them as necessary to match the servos you
// have!
#define SERVOMIN  125 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX  575 // this is the 'maximum' pulse length count (out of 4096)

// our servo # counter
uint8_t servonum = 0;

void setup() {
  Serial.begin(9600);
  Serial.println("16 channel Servo test!");

  pwm.begin();
  
  pwm.setPWMFreq(60);  // Analog servos run at ~60 Hz updates

  //yield();
}

// the code inside loop() has been updated by Robojax
void loop() {


  for( int angle =0; angle<181; angle +=20){
    delay(500);
    pwm.setPWM(0, 0, angleToPulse(angle) );
  }

  delay(1000);
 
}

/*
 * angleToPulse(int ang)
 * gets angle in degrees and returns the pulse width.
 * Also prints the value on the serial monitor.
 * Written by Ahmad Shamshiri for Robojax, Robojax.com
 */
int angleToPulse(int ang){
   int pulse = map(ang,0, 180, SERVOMIN,SERVOMAX);// map angle of 0 to 180 to Servo min and Servo max 
   Serial.print("Angle: ");Serial.print(ang);
   Serial.print(" pulse: ");Serial.println(pulse);
   return pulse;
}
37-PCA9685 video V1: Arduino Code with mapping PWM
Ede: C++
/*
 * Original source: https://github.com/adafruit/Adafruit-PWM-Servo-Driver-Library
 * This is the Arduino code for the PCA9685 16-channel servo controller.
we have simple code with mapping PWM for simplicity explained in the video at 18:27

 * Watch the video for details and demo: http://youtu.be/y8X9X10Tn1k
 get this code and wiring from for this video:  http://robojax.com/RJT27

 * Written by Ahmad Nejrabi for Robojax Video channel: www.Robojax.com
 * Date: December 15, 2017, in Ajax, Ontario, Canada
 * Permission granted to share this code, given that this
 * note is kept with the code.
 * Disclaimer: This code is "AS IS" and for educational purposes only.
 * 
 */
/*************************************************** 
  This is an example for our Adafruit 16-channel PWM & Servo driver.
  Servo test - this will drive 16 servos, one after the other.

  Pick one up today in the Adafruit shop!
  ------> http://www.adafruit.com/products/815

  These displays use I2C to communicate; 2 pins are required to  
  interface. For Arduino UNOs, that's SCL -> Analog 5, SDA -> Analog 4.

  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
 ****************************************************/

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);

// Depending on your servo make, the pulse width min and max may vary; you 
// want these to be as small/large as possible without hitting the hard stop
// for max range. You'll have to tweak them as necessary to match the servos you
// have!
#define SERVOMIN  125 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX  575 // this is the 'maximum' pulse length count (out of 4096)

// our servo # counter
uint8_t servonum = 0;

void setup() {
  Serial.begin(9600);
  Serial.println("16 channel Servo test!");

  pwm.begin();
  
  pwm.setPWMFreq(60);  // Analog servos run at ~60 Hz updates

  //yield();
}

// the code inside loop() has been updated by Robojax
void loop() {

    pwm.setPWM(0, 0, 125 );
	delay(500);
    pwm.setPWM(0, 0, 255 );
	delay(500);
    pwm.setPWM(0, 0, 450 );
	delay(500);
    pwm.setPWM(0, 0, 575 );
	delay(500);	

 
}

Ohun ti o le nilo

Orisun & itọkasi

Ko si awọn orisun sibẹsibẹ.

Fáìlìs📁

Awọn ile-ikawe Arduino (zip)

Awọn faili miiran