این آموزش بخشی است از: کنترل سروو موتور ۱۶ یا ۳۲ با PCA9685
این مجموعه آموزش به همراه ویدیو به شما کمک میکند تا ۳۲ یا تعداد بیشتری سروو موتور را با استفاده از آردوینو UNO، نانو، مینی یا ESP32 کنترل کنید. تمام کدها ارائه شده است.
Controlling 16 Servo Motors Using a PCA9685 Module and Arduino V2 Sketch #3: All Servos Together
In this video, we learn how to control 16 servo motors using a PCA9685 PWM controller with I2C.
This code shows how to control all servos at once.
Servos are numbered from 0 to 15.
این آموزش بخشی از: کنترل سروو موتور ۱۶ یا ۳۲ با PCA9685
- شِفر (کود) آردوینو و ویدیو برای کنترلکننده سروو PCA9685، 16 کاناله، 12 بیتی، V1
- کنترل 16 موتور سروو با استفاده از ماجیول PCA9685 و شِفر (کود) آردوینو V2 نمونه #1: یکی یکی
- کنترل ۲۴ موتور سروو با استفاده از ماجیول PCA9685 و شِفر (کود) Arduino V2: کنترل موتور سروو فردی
- کنترل یک سروو موتور ۳۲ با استفاده از ماجیول PCA9685 و برنامه آردوینو V3 طرح #۱: همه سرووها با هم
- کنترل یک موتور سرو 32 با استفاده از ماجیول PCA9685 و یک ESP32 V4
- کنترل ۳۲ سروو از راه Wi-Fi با استفاده از ESP32 و PCA9685 از طریق دسکتاپ یا گوشی موبایل V5
269-Code #3: Arduino code to run two or all servos together
زبان: C++
/*
* Original sourse: https://github.com/adafruit/Adafruit-PWM-Servo-Driver-Library
*
* This is the Arduino code PAC6985 16 channel servo controller
* watch the video for details (V1) and demo http://youtu.be/y8X9X10Tn1k
* This code is #3 for V2 Video Watch the video :
* I have got 3 codes as follow:https://youtu.be/bal2STaoQ1M
*
#1-Arduino Code to run one by one all servos from 0 to 180°
#2-Arduino Code to control specific servos with specific angle
#3-Arduino Code to run 2 or all servos at together
* Written/updated by Ahmad Shamshiri for Robojax Video channel www.Robojax.com
* Date: Dec 16, 2017, in Ajax, Ontario, Canada
* Permission granted to share this code given that this
* note is kept with the code.
* Watch 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 Servo https://youtu.be/y8X9X10Tn1k
* Disclaimer: this code is "AS IS" and for educational purpose only.
* this code has been downloaded from https://robojax.com
* Get this code and other Arduino codes from Robojax.com
Learn Arduino step by step in structured course with all material, wiring diagram and library
all in once place. Purchase My course on Udemy.com http://robojax.com/L/?id=62
****************************
Get early access to my videos via Patreon and have your name mentioned at end of very
videos I publish on YouTube here: http://robojax.com/L/?id=63 (watch until end of this video to list of my Patrons)
****************************
or make donation using PayPal http://robojax.com/L/?id=64
* * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.*
* This code has been download from Robojax.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#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!
// Watch video V1 to understand the two lines below: http://youtu.be/y8X9X10Tn1k
#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() {
//watch video for details: https://youtu.be/bal2STaoQ1M
for( int angle =0; angle<181; angle +=10){
delay(50);
for(int i=0; i<16; i++)
{
pwm.setPWM(i, 0, angleToPulse(angle) );
}
}
// robojax PCA9865 16 channel Servo control
delay(1000);
}
/*
* angleToPulse(int ang)
* gets angle in degree and returns the pulse width
* also prints the value on seial 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;
}
مواردی که ممکن است به آنها نیاز داشته باشید
-
آمازون
-
ایبیخرید PCA9685 از eBayebay.us
-
علیاکسپرسخرید PCA9685 از علیاکسپرسs.click.aliexpress.com
-
بنگ گودپیش خرید PCA9685 از بانگودbanggood.com
منابع و مراجع
هنوز هیچ منبعی موجود نیست.
فایلها📁
کتابخانههای آردوینو (zip)
-
کتابخانه-درایور-سروو-پیدبلیوام-آدافروت-اصلی
Adafruit-PWM-Servo-Driver-Library-master.zip0.02 MB