Бұл оқулық бөлігі болып табылады: Servo Motors
All videos related to servo motors that are related, listed here. Links to other videos are below this article.
Ардуино коды және PCA9685 16-арналы 12-биттік серво контроллері V1 бейнежазбасы
Бұл оқулықта біз NXP Semiconductor компаниясының PCA9685 16-арналы 12-биттік серво контроллерін қалай пайдалану керектігін қарастырамыз. Бұл модуль импульстік ені модуляциясын (PWM) қолдана отырып, 16 сервоны басқаруға немесе LED шоғырын дәлдікпен күңгірттеуге мүмкіндік береді. Осы оқулықтың соңында сізде бірнеше сервоны жеке немесе бір уақытта басқара алатын жұмыс істейтін қондырғы болады.

Оқулық мазмұнын одан әрі нақтылау үшін, қондырғы мен кодтау процесінің көрнекі демонстрациясын көру үшін ілеспе бейнені (00:00-дегі бейнеде) көруге кеңес беремін.
Аппараттық құрал түсіндірмесі
PCA9685 модулі - I2C байланысы арқылы бірнеше сервоны басқара алатын ықшам тақта. Ол 16 арнадан тұрады, бұл әрқайсысының өз басқару сигналы бар 16 сервоны қосуға мүмкіндік береді. Модуль 5В қуат көзімен жұмыс істейді және серволардың орнын дәл басқару үшін маңызды PWM сигналдарын өңдеуге арналған.
Тақтада қуат (VCC), жер (GND) және байланыс (SDA және SCL) үшін арнайы түйреуіштер бар. SDA түйреуіші деректерді беру үшін қолданылады, ал SCL түйреуіші сағат сигналы болып табылады, екеуі де Arduino-ның аналогтық A4 және A5 түйреуіштеріне сәйкесінше қосылады. Бұл қондырғы Arduino мен PCA9685 модулі арасында сенімді байланысты қамтамасыз етеді.
Деректер парағының мәліметтері
| Өндіруші | NXP Semiconductor |
|---|---|
| Бөлшек нөмірі | PCA9685 |
| Логика/IO кернеуі | 3.3 В - 5.5 В |
| Қуат кернеуі | 2.3 В - 5.5 В |
| Шығыс тогы (әр арна) | 25 мА макс |
| Шың тогы (әр арна) | 100 мА макс |
| PWM жиілігі бойынша нұсқау | 24 Гц - 1.6 кГц |
| Кіріс логикалық шектері | 0.3 В (төмен) / 0.7 В (жоғары) |
| Кернеу төмендеуі / RDS(on) / қанығу | 0.5 В макс |
| Жылулық шектер | -40 °C - 125 °C |
| Қаптама | HTSSOP-28 |
| Ескертулер / нұсқалар | 16-арналы PWM контроллері |
- Жеткілікті токпен (1А ұсынылады) 5В қуат көзін қамтамасыз етіңіз.
- Зақымдануды болдырмау үшін серволарды тікелей Arduino-дан қуаттандырмаңыз.
- Дұрыс I2C түйреуіштерін қолданыңыз: SDA-ны A4-ке, SCL-ді A5-ке жалғаңыз.
- Импульс ені мәндерін өз серволарыңызға сәйкес реттеңіз.
- Сымдардың полярлығын тексеріңіз: GND, VCC және сигнал.
- Жоғары ток қолданатын қолданбалар үшін жылу таратқышты қарастырыңыз.
Сымдарды жалғау нұсқаулары

PCA9685-ті Arduino-ға қосу үшін алдымен қуат пен жерді жалғаудан бастаңыз. PCA9685-тегі VCC түйреуішін Arduino-дағы 5V шығысына қосыңыз. Содан кейін PCA9685-тегі GND түйреуішін Arduino-дағы GND-ге қосыңыз. Әрі қарай, PCA9685-тегі SDA түйреуішін Arduino-дағы A4 түйреуішіне, ал SCL түйреуішін A5-ке қосыңыз.
Серволар үшін сигнал сымын PCA9685-тегі сәйкес арнаға қосыңыз (мысалы, бірінші серво үшін CH0), қуат сымын бөлек қуат көзіне (серволар Arduino бере алатыннан көбірек ток қажет етуі мүмкін), ал жер сымын PCA9685-пен ортақ жерге қосыңыз. Компоненттеріңізді зақымдамау үшін сигнал, қуат және жер сымдарының дұрыс тураланғанына көз жеткізіңіз.
Код мысалдары мен түсіндірме
Кодтың баптау бөлімінде біз PCA9685 модулін pwm.begin() арқылы инициализациялаймыз және PWM жиілігін pwm.setPWMFreq(60); арқылы орнатамыз. Бұл серволар үшін байланыс жиілігін орнатады.
void setup() {
Serial.begin(9600);
Serial.println("16 арналы Серво тесті!");
pwm.begin();
pwm.setPWMFreq(60); // Аналогтық серволар ~60 Гц жаңартумен жұмыс істейді
}
Цикл ішінде біз қажетті бұрыштарға сәйкес PWM мәндерін орнату арқылы серволарды басқарамыз. angleToPulse(int ang) функциясы бұрышты тиісті импульс еніне келтіреді, бұл сервоның дәл позициялануы үшін маңызды.
void loop() {
for( int angle =0; angle<181; angle +=20){
delay(500);
pwm.setPWM(0, 0, angleToPulse(angle) );
}
}
Соңында, angleToPulse(int ang) функциясы анықталған минималды және максималды импульс ұзақтықтарын қолдана отырып, бұрышты импульс еніне түрлендіреді. Бұл қол жеткізгіңіз келетін бұрышқа негізделген сервоның орнын оңай басқаруға мүмкіндік береді.
int angleToPulse(int ang){
int pulse = map(ang,0, 180, SERVOMIN,SERVOMAX);
Serial.print("Бұрыш: ");Serial.print(ang);
Serial.print(" импульс: ");Serial.println(pulse);
return pulse;
}
Демонстрация / Не күтуге болады
Барлығы дұрыс жалғанып, код жүктелгеннен кейін, сервоның 20 градус қадамдармен көрсетілген бұрыштар арқылы қозғалатынын көруіңіз керек. Егер серво күтілгендей әрекет етпесе, сымдардың дұрыс жалғануын тексеріңіз және қуат көзінің жеткілікті екеніне көз жеткізіңіз (12:30-дағы бейнеде).
Бейне уақыт белгілері
- 00:00 - PCA9685-ке кіріспе
- 02:30 - Сымдарды жалғау нұсқаулары
- 05:00 - Кодты түсіндіру
- 10:15 - Серво басқару демонстрациясы
- 12:30 - Жиі кездесетін мәселелерді шешу
Бұл оқулық бөлігі болып табылады: Servo Motors
- Ардуино арқылы түймелермен сервоны басқару
- 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)
- Ардуино көмегімен потенциометр арқылы сервоны басқару
- Ардуино көмегімен потенциометр және LCD1602 арқылы сервоны басқару
- Ардуино арқылы инфрақызыл қашықтан басқару пультімен сервоқозғалтқыштарды басқару
- Arduino сервомоторын потенциометр арқылы басқару
- Arduino үшін қол қимылдарымен сервоприводтың орнын басқару
- Controlling Two or More Servos with Potentiometers Using an Arduino
- How to Control a 360° Servo with Three Push-Button Switches
- Үздіксіз 360° сервоны Arduino-мен қалай пайдалану керек
- Ардуино серво қосқышын итеру түймесімен жасаңыз
/*
* 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);
}
Сізге қажет болуы мүмкін нәрселер
-
АмазонкаPurchase PCA9685 from Amazonamzn.to
-
eBayPurchase PCA9685 from eBayebay.us
-
AliExpressPurchase PCA9685 from AliExpresss.click.aliexpress.com
-
BanggoodPurchase PCA9685 from Banggoodbanggood.com
Ресурстар мен сілтемелер
Әлі ресурстар жоқ.
Файлдар📁
Arduino кітапханалары (zip)
-
Adafruit-PWM-Servo-Driver-Library-master
Adafruit-PWM-Servo-Driver-Library-master.zip0.02 MB
Басқа файлдар
-
PCA9685 деректер парағы
robojax_PCA9685.pdf0.39 MB -
PCA9685 Adafruit кітапханасы
robojax_PCA9685-Adafruit-Library.zip0.01 MB