Casharradan waa qayb ka mid ah: Matoorada Servo
Dhammaan fiidiyowyada la xiriira matoorada servo ee la xiriira, halkan ayaa lagu taxay. Xiriirinta fiidiyowyada kale waxay ku yaalliin maqaalkan hoose.
Koodhka Arduino iyo Fiidiyowga ee PCA9685 16-Kanaal 12-Bit Kontoroolaha Servo V1
Cashigarkani, waxaan sahamin doonaa sida loo isticmaalo kontoroolaha servo PCA9685 ee 16-kanal-ka ah ee 12-bit-ka ah ee NXP Semiconductor. Qalabkan wuxuu kuu ogolaanayaa inaad kontoroolo ilaa 16 servo ama aad hoos u dhigto koox LED ah si sax ah iyadoo la adeegsanayo habaynta ballaca xawliga (PWM). Marka aad dhammayso cashar-kan, waxaad yeelan doontaa qaab shaqeeya oo aad ku kontorooli karto servo badan si gooni gooni ah ama isku mar ah.

Si aan u caddeeyo nuxurka cashar-ka, waxaan kugu dhiirigelinayaa inaad daawato fiidiyowga la socda (fiidiyowga 00:00) si aad u aragto muujin muuqaal ah oo ku saabsan habaynta iyo habka koodhka.
Qalabka La Sharaxay
Qalabka PCA9685 waa loox yar oo kontorooli kara servo badan iyada oo loo marayo isgaarsiinta I2C. Wuxuu leeyahay 16 kanal, taas oo kuu ogolaanaysa inaad ku xidho ilaa 16 servo, mid kastaa wuxuu leeyahay calaamad kontorool oo u gaar ah. Qalabku wuxuu ku shaqeeyaa koronto 5V ah waxaana loo qaabeeyey inuu qabto calaamadaha PWM, kuwaas oo muhiim u ah kontoroolka saxda ah ee booska servo-yada.
Looxa waxaa ku jira biinooyin u go'an koronto (VCC), dhul (GND), iyo isgaarsiin (SDA iyo SCL). Biinka SDA waxaa loo isticmaalaa gudbinta xogta, halka biinka SCL uu yahay calaamadda saacadda, labaduba waxay ku xidhmaan biinooyinka analog-ga ah ee Arduino A4 iyo A5, siday u kala horreeyaan. Habayntani waxay hubinaysaa isgaarsiin lagu kalsoonaan karo oo u dhexeysa Arduino iyo qalabka PCA9685.
Faahfaahinta Xaashida Xogta
| Soo saaraha | NXP Semiconductor |
|---|---|
| Nambarka qaybta | PCA9685 |
| Korontada Logic/IO | 3.3 V ilaa 5.5 V |
| Korontada sahayda | 2.3 V ilaa 5.5 V |
| Korontada soo-saarka (kanal kasta) | 25 mA ugu badnaan |
| Korontada ugu sarreysa (kanal kasta) | 100 mA ugu badnaan |
| Hagaha soo noqnoqoshada PWM | 24 Hz ilaa 1.6 kHz |
| Heerarka caqabadaha gelinta | 0.3 V (hoose) / 0.7 V (sare) |
| Hoos u dhaca korontada / RDS(on) / dhereg | 0.5 V ugu badnaan |
| Xadka kulaylka | -40 °C ilaa 125 °C |
| Baakad | HTSSOP-28 |
| Qoraallo / noocyo kale | Kontoroolaha PWM ee 16-kanal |
- Hubi inaad haysato koronto 5V ah oo leh qulqulka ku filan (1A lagu taliyay).
- Ha ku shidin servo-yada si toos ah Arduino-ga si aad uga fogaato waxyeelada.
- Isticmaal biinooyinka I2C ee saxda ah: SDA ilaa A4 iyo SCL ilaa A5.
- Hagaaji qiyamka ballaca xawliga marka loo eego servo-yadaaga gaarka ah.
- Hubi fiilooyinka si loo helo jihooyin sax ah: GND, VCC, iyo calaamadda.
- Tixgeli kulayl-qaadista codsiyada qulqulka sare leh.
Habaynta Fiilooyinka

Si aad ugu xidho PCA9685 Arduino-gaaga, waxaad ku bilaabaysaa isku xidhka korontada iyo dhulka. Ku xidh biinka VCC ee PCA9685 soo-saarka 5V ee Arduino. Kadib ku xidh biinka GND ee PCA9685 GND-ga Arduino. Marka xigta, ku xidh biinka SDA ee PCA9685 biinka A4 ee Arduino, iyo biinka SCL biinka A5.
Servo-yada, ku xidh fiilada calaamadda kanalka u dhigma ee PCA9685 (tusaale, CH0 servo-ga koowaad), fiilada korontada koronto gaar ah (maxaa yeelay servo-yada waxaa laga yaabaa inay u baahdaan qulqul ka badan inta Arduino bixin karo), iyo fiilada dhulka dhulka wadaaga ah ee PCA9685. Hubi in fiilooyinka calaamadda, korontada, iyo dhulka si sax ah u toosan yihiin si aad uga fogaato waxyeelada qaybahaaga.
Tusaalooyinka Koodhka & Sharaxaad
Qaybta habaynta ee koodhka, waxaan ku bilaabaynaa qalabka PCA9685 iyada oo la adeegsanayo pwm.begin() waxaana dejinaynaa soo noqnoqoshada PWM iyada oo la adeegsanayo pwm.setPWMFreq(60);. Tani waxay dejinaysaa soo noqnoqoshada isgaarsiinta ee servo-yada.
void setup() {
Serial.begin(9600);
Serial.println("16 channel Servo test!");
pwm.begin();
pwm.setPWMFreq(60); // Servo-yada analog-ga ah waxay ku shaqeeyaan ~60 Hz cusboonaysiin
}
Gudaha loop-ka, waxaan kontoroolaynaa servo-yada iyada oo la dejinayo qiyamka PWM ee u dhigma xaglaha la doonayo. Shaqada angleToPulse(int ang) waxay u qaabaysaa xagasha ballaca xawliga ku habboon, taas oo muhiim u ah boos celinta saxda ah ee servo-ga.
void loop() {
for( int angle =0; angle<181; angle +=20){
delay(500);
pwm.setPWM(0, 0, angleToPulse(angle) );
}
}
Ugu dambeyntii, shaqada angleToPulse(int ang) waxay u beddeshaa xagasha ballaca xawliga iyada oo la adeegsanayo dhererka xawliga ugu yar iyo ugu weyn ee la qeexay. Tani waxay kuu ogolaanaysaa inaad si fudud u kontoroolo booska servo-ga iyadoo lagu salaynayo xagasha aad rabto inaad gaadho.
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;
}
Muujin / Waxa Lagu Filan Karaa
Marka wax walba si sax ah loo xidho oo koodhka la soo geliyo, waxaad arki doontaa servo-ga oo u dhaqaaqaya xaglaha la cayimay iyada oo lagu kordhinayo 20 darajo. Haddii servo-ga uusan u dhaqmin sidii la filayay, hubi fiilooyinka inay sax yihiin oo hubi in korontada sahaydu ku filan tahay (fiidiyowga 12:30).
Waqtiyada Fiidiyowga
- 00:00 - Hordhac ku saabsan PCA9685
- 02:30 - Habaynta fiilooyinka
- 05:00 - Sharaxaad ku saabsan koodhka
- 10:15 - Muujinta kontoroolka servo-ga
- 12:30 - Xallinta dhibaatooyinka caadiga ah
Casharradan waa qayb ka mid ah: Matoorada Servo
- Xakamaynta Servo-ga iyadoo la isticmaalayo Buttons-ka Riixaya iyadoo la isticmaalayo Arduino
- Control a Servo Motor with a Push Button: Move Servo and Return SPB-1
- Control a Servo Motor with a Push Button: Move Servo in One Direction SPB-2
- Controlling a Servo Motor with a Push Button: Move Servo While Button Is Pressed (SPB-3)
- Xakamaynta Servo-ga iyadoo la isticmaalayo Potentiometer iyadoo la adeegsanayo Arduino
- Xakamaynta Servo-ga iyadoo la isticmaalayo Potentiometer iyo LCD1602 iyadoo la adeegsanayo Arduino
- Kontoroolka Matoorka Servo iyadoo la isticmaalayo Remote Infrared ah oo leh Arduino
- Xakameynta Moterka Servo ee Arduino iyadoo la adeegsanayo Potentiometer
- Xakameynta Meesha Servo iyadoo la adeegsanayo Gacmaha ee Arduino
- Controlling Two or More Servos with Potentiometers Using an Arduino
- How to Control a 360° Servo with Three Push-Button Switches
- Sida loo isticmaalo Servo 360° oo joogto ah oo leh Arduino
- Dhis Arduino Servo Toggle Switch ku sameeyo oo leh Push Button
/*
* 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;
}
/*
* 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);
}
Waad u baahan tahay
-
AmaazonPurchase PCA9685 from Amazonamzn.to
-
eBayPurchase PCA9685 from eBayebay.us
-
AliExpressPurchase PCA9685 from AliExpresss.click.aliexpress.com
-
BanggoodPurchase PCA9685 from Banggoodbanggood.com
Kheyraadka & Tixraacyada
Wali wax kaydsan ah oo weli ma jiro.
Faylasha📁
Arduino Libraries (zip)
-
Adafruit-PWM-Servo-Driver-Library-master
Adafruit-PWM-Servo-Driver-Library-master.zip0.02 MB
Faylal kale
-
PCA9685 Warbixinta
robojax_PCA9685.pdf0.39 MB -
Maktabada Adafruit ee PCA9685
robojax_PCA9685-Adafruit-Library.zip0.01 MB