ኮድ ይፈልጉ

የ Arduino ኮድ እና ቪዲዮ ለ PCA9685 16-ቻናል 12-ቢት ሰርቮ መቆጣጠሪያ V1

የ Arduino ኮድ እና ቪዲዮ ለ PCA9685 16-ቻናል 12-ቢት ሰርቮ መቆጣጠሪያ V1

በዚህ ትምህርት ውስጥ፣ ከNXP Semiconductor የሆነውን PCA9685 16-ሰርጥ 12-ቢት ሰርቮ መቆጣጠሪያን እንዴት መጠቀም እንደምንችል እንመረምራለን። ይህ ሞጁል እስከ 16 ሰርቮዎችን ለመቆጣጠር ወይም የLED ባንክን በ pulse width modulation (PWM) በመጠቀም በትክክል ለማደብዘዝ ያስችልዎታል። በዚህ ትምህርት መጨረሻ፣ ብዙ ሰርቮዎችን በተናጠል ወይም በአንድ ጊዜ መቆጣጠር የሚችል የሚሰራ ዝግጅት ይኖርዎታል።

PCA9685 module-0

የትምህርቱን ይዘት የበለጠ ለማብራራት፣ የዝግጅቱን እና የኮድ አጻጻፍ ሂደትን በእይታ ለማሳየት ተጓዳኝ ቪዲዮውን (በቪዲዮ 00:00) እንዲመለከቱ አበረታታለሁ።

ሃርድዌር ተብራርቷል

የPCA9685 ሞጁል በI2C ግንኙነት አማካኝነት ብዙ ሰርቮዎችን መቆጣጠር የሚችል የታመቀ ቦርድ ነው። 16 ሰርጦች ያሉት ሲሆን፣ እያንዳንዱም የራሱ የቁጥጥር ምልክት ያለው፣ እስከ 16 ሰርቮዎችን ለማገናኘት ያስችልዎታል። ሞጁሉ በ5V የኃይል አቅርቦት ይሰራል እና የሰርቮዎችን አቀማመጥ በትክክል ለመቆጣጠር አስፈላጊ የሆኑትን የPWM ምልክቶችን ለማስተናገድ የተነደፈ ነው።

ቦርዱ ለኃይል (VCC)፣ ለመሬት (GND) እና ለግንኙነት (SDA እና SCL) የተሰጡ ፒኖችን ያካትታል። የSDA ፒን ለውሂብ ማስተላለፊያ የሚያገለግል ሲሆን፣ የSCL ፒን ደግሞ የሰዓት ምልክት ነው፣ ሁለቱም ከአርዱኖው የአናሎግ ፒኖች A4 እና A5 ጋር ይገናኛሉ። ይህ ዝግጅት በአርዱኖ እና በPCA9685 ሞጁል መካከል አስተማማኝ ግንኙነትን ያረጋግጣል።

የዳታሼት ዝርዝሮች

አምራችNXP Semiconductor
የክፍል ቁጥርPCA9685
የሎጂክ/IO ቮልቴጅ3.3 V እስከ 5.5 V
የአቅርቦት ቮልቴጅ2.3 V እስከ 5.5 V
የውጤት ኤሌክትሪክ (በአንድ ሰርጥ)25 mA ከፍተኛ
ከፍተኛ ኤሌክትሪክ (በአንድ ሰርጥ)100 mA ከፍተኛ
የPWM ድግግሞሽ መመሪያ24 Hz እስከ 1.6 kHz
የግቤት ሎጂክ ገደቦች0.3 V (ዝቅተኛ) / 0.7 V (ከፍተኛ)
የቮልቴጅ ጠብታ / RDS(on) / ሙሌት0.5 V ከፍተኛ
የሙቀት ገደቦች-40 °C እስከ 125 °C
ፓኬጅHTSSOP-28
ማስታወሻዎች / ልዩነቶች16-ሰርጥ PWM መቆጣጠሪያ

  • በቂ ኤሌክትሪክ ያለው (1A ይመከራል) የ5V የኃይል አቅርቦት ያረጋግጡ።
  • ጉዳት ለማስወገድ ሰርቮዎቹን በቀጥታ ከአርዱኖ አያብሩ።
  • ትክክለኛዎቹን የI2C ፒኖች ይጠቀሙ፡ SDA ወደ A4 እና SCL ወደ A5።
  • የ pulse width እሴቶችን እንደ ልዩ ሰርቮዎችዎ ያስተካክሉ።
  • ለትክክለኛ የፖላሪቲ ግንኙነት ያረጋግጡ፡ GND፣ VCC እና ሲግናል።
  • ለከፍተኛ ኤሌክትሪክ አፕሊኬሽኖች የሙቀት መስጫ (heat-sinking) ግምት ውስጥ ያስገቡ።

የወልና መመሪያዎች

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

PCA9685ን ከአርዱኖዎ ጋር ለማገናኘት፣ በመጀመሪያ ኃይልን እና መሬትን በማገናኘት ይጀምሩ። በPCA9685 ላይ ያለውን የVCC ፒን በአርዱኖ ላይ ካለው የ5V ውጤት ጋር ያገናኙ። ከዚያም በPCA9685 ላይ ያለውን የGND ፒን በአርዱኖ ላይ ካለው GND ጋር ያገናኙ። በመቀጠል፣ በPCA9685 ላይ ያለውን የSDA ፒን በአርዱኖ ላይ ካለው ፒን A4 ጋር፣ እና የSCL ፒንን ደግሞ ከA5 ጋር ያገናኙ።

ለሰርቮዎቹ፣ የሲግናል ሽቦውን በPCA9685 ላይ ካለው ተጓዳኝ ሰርጥ ጋር (ለምሳሌ፣ ለመጀመሪያው ሰርቮ CH0)፣ የኃይል ሽቦውን ወደ ተለየ የኃይል አቅርቦት (ሰርቮዎቹ ከአርዱኖ ሊሰጠው ከሚችለው በላይ ኤሌክትሪክ ሊፈልጉ ስለሚችሉ)፣ እና የመሬት ሽቦውን ደግሞ ከPCA9685 ጋር ከሚጋራው የጋራ መሬት ጋር ያገናኙ። ክፍሎችዎን ላለማበላሸት የሲግናል፣ የኃይል እና የመሬት ሽቦዎች በትክክል መደረደራቸውን ያረጋግጡ።

የኮድ ምሳሌዎች እና ማብራሪያ

በኮዱ የማዋቀሪያ ክፍል ውስጥ፣ የPCA9685 ሞጁሉን በpwm.begin() እንጀምራለን እና የPWM ድግግሞሹን በpwm.setPWMFreq(60); እናዘጋጃለን። ይህ ለሰርቮዎቹ የግንኙነት ድግግሞሽን ያዘጋጃል።

void setup() {
  Serial.begin(9600);
  Serial.println("16 channel Servo test!");
  pwm.begin();
  pwm.setPWMFreq(60);  // አናሎግ ሰርቮዎች በ~60 Hz ዝማኔዎች ይሰራሉ
}

በሉፕ ውስጥ፣ ከተፈለጉት ማዕዘኖች ጋር የሚዛመዱ የPWM እሴቶችን በማዘጋጀት ሰርቮዎቹን እንቆጣጠራለን። ተግባሩ angleToPulse(int ang) ማዕዘኑን ወደ ተገቢው የ pulse width ይቀይረዋል፣ ይህም ለትክክለኛ የሰርቮ አቀማመጥ አስፈላጊ ነው።

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

በመጨረሻም፣ ተግባሩ angleToPulse(int ang) የተገለጹትን ዝቅተኛ እና ከፍተኛ የ pulse ርዝመቶችን በመጠቀም ማዕዘኑን ወደ pulse width ይቀይረዋል። ይህ ሊያሳኩት በሚፈልጉት ማዕዘን ላይ በመመስረት የሰርቮውን አቀማመጥ በቀላሉ እንዲቆጣጠሩ ያስችልዎታል።

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;
}

ማሳያ / ምን እንደሚጠበቅ

ሁሉም ነገር በትክክል ከተገናኘ እና ኮዱ ከተጫነ በኋላ፣ ሰርቮው በ20 ዲግሪ ጭማሪዎች በተገለጹት ማዕዘኖች ሲንቀሳቀስ ማየት ይኖርብዎታል። ሰርቮው እንደተጠበቀው ባይሰራ፣ ግንኙነቶቹ ትክክለኛ መሆናቸውን ለማረጋገጥ የወልናውን ያረጋግጡ እና የኃይል አቅርቦቱ በቂ መሆኑን ያረጋግጡ (በቪዲዮ 12:30)።

የቪዲዮ ጊዜ አመልካቾች

  • 00:00 - ለPCA9685 መግቢያ
  • 02:30 - የወልና መመሪያዎች
  • 05:00 - የኮድ ማብራሪያ
  • 10:15 - የሰርቮ ቁጥጥር ማሳያ
  • 12:30 - የተለመዱ ችግሮችን መፍታት

ምስሎች

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
ቋንቋ: 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
ቋንቋ: 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);	

 
}

እንደሚያስፈልግዎት ይችላል

ምንጮች እና ምንጮች

አሁን ምንም ምንጮች የለም።

ፋይሎች📁

Arduino ቤተ መዝገቦች (zip)

ሌላ ፋይሎች