极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 55416|回复: 14

arduino uno只能同时驱动2个舵机吗?

[复制链接]
发表于 2012-4-22 15:40:07 | 显示全部楼层 |阅读模式
本帖最后由 咱家宝的大胖熊 于 2012-4-22 15:42 编辑

使用arduono sensor shield v5.0连接6个mg995舵机。分别接在0~5引脚。
简单的改写sweep程序,让6个舵机同时摆动。可问题是
只有0,4会摆动。其他不动,请问是在呢么回事?
  1. #include <Servo.h>

  2. Servo myservo0;  // create servo object to control a servo
  3. Servo myservo1;
  4. Servo myservo2;                 
  5. Servo myservo3;
  6. Servo myservo4;
  7. Servo myservo5;

  8. int pos = 0;    // variable to store the servo position

  9. void setup()
  10. {
  11.   myservo0.attach(0);  // attaches the servo on pin 9 to the servo object
  12.   myservo1.attach(1);
  13.   myservo1.attach(2);
  14.   myservo1.attach(3);
  15.   myservo1.attach(4);
  16. }


  17. void loop()
  18. {
  19.   for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees
  20.   {                                  // in steps of 1 degree
  21.     myservo0.write(pos);    // tell servo to go to position in variable 'pos'
  22.     myservo1.write(pos);
  23.     myservo2.write(pos);
  24.     myservo3.write(pos);
  25.     myservo4.write(pos);
  26.     myservo5.write(pos);
  27.     delay(10);                       // waits 15ms for the servo to reach the position
  28.   }
  29.   for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
  30.   {                                
  31.     myservo0.write(pos);    // tell servo to go to position in variable 'pos'
  32.     myservo1.write(pos);
  33.     myservo2.write(pos);
  34.     myservo3.write(pos);
  35.     myservo4.write(pos);
  36.     myservo5.write(pos);
  37.     delay(10);                       // waits 15ms for the servo to reach the position
  38.   }
  39. }
复制代码
回复

使用道具 举报

发表于 2012-4-22 17:09:35 | 显示全部楼层
void setup()
{
  myservo0.attach(0);  // attaches the servo on pin 9 to the servo object
  myservo1.attach(1);
  myservo1.attach(2);
  myservo1.attach(3);
  myservo1.attach(4);
}

初始化有误
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-4-22 18:31:23 | 显示全部楼层
i7456 发表于 2012-4-22 17:09
void setup()
{
  myservo0.attach(0);  // attaches the servo on pin 9 to the servo object

呵呵,却是是这里有问题。我重新试验了6个舵机洗刷刷,ok了,感谢。
回复 支持 反对

使用道具 举报

发表于 2013-1-15 18:16:09 | 显示全部楼层
问一下,我是菜鸟,现在市面上所有的舵机控制板都兼容Arduino吗?
回复 支持 反对

使用道具 举报

发表于 2013-1-31 10:06:32 | 显示全部楼层
咱家宝的大胖熊 发表于 2012-4-22 18:31
呵呵,却是是这里有问题。我重新试验了6个舵机洗刷刷,ok了,感谢。

是什么问题啊
回复 支持 反对

使用道具 举报

发表于 2013-1-31 11:33:41 | 显示全部楼层
小美 发表于 2013-1-31 10:06
是什么问题啊


void setup()
{
   myservo0.attach(0);  // attaches the servo on pin 9 to the servo object
   myservo1.attach(1);
   myservo1.attach(2);
   myservo1.attach(3);
   myservo1.attach(4);
}
改为
void setup()
  {
    myservo0.attach(0);  // attaches the servo on pin 9 to the servo object
    myservo1.attach(1);
    myservo2.attach(2);
    myservo3.attach(3);
    myservo4.attach(4);
  }
回复 支持 反对

使用道具 举报

发表于 2013-2-1 13:53:10 | 显示全部楼层
smfox10 发表于 2013-1-31 11:33
void setup()
{
   myservo0.attach(0);  // attaches the servo on pin 9 to the servo object  ...

哦哦哦~谢谢~我看出来了 嘿嘿
回复 支持 反对

使用道具 举报

发表于 2013-2-1 13:53:28 | 显示全部楼层
smfox10 发表于 2013-1-31 11:33
void setup()
{
   myservo0.attach(0);  // attaches the servo on pin 9 to the servo object  ...

之前我二了 嘿嘿 居然没看出来
回复 支持 反对

使用道具 举报

发表于 2014-6-13 16:18:44 | 显示全部楼层
小美 发表于 2013-2-1 13:53
之前我二了 嘿嘿 居然没看出来

其实很正常,当运行结果和你的理想不符合的时候就看看代码。很多时候都是粗心大意照成的。
回复 支持 反对

使用道具 举报

发表于 2015-6-11 13:04:33 | 显示全部楼层
好东西,学习一下!!!!
回复 支持 反对

使用道具 举报

发表于 2015-7-20 10:48:35 | 显示全部楼层
亲,能否跟我讲一下电路怎么接,我是要做四轴飞行器的,谢谢
回复 支持 反对

使用道具 举报

发表于 2015-7-20 13:02:28 | 显示全部楼层
本质上库就是用软件模拟的,你拿2560来,每个IO接一个舵机都可以
回复 支持 反对

使用道具 举报

发表于 2015-7-30 11:22:56 | 显示全部楼层
可是还不好使呀
回复 支持 反对

使用道具 举报

发表于 2016-8-28 00:40:24 | 显示全部楼层
不用shield板也可以驱动6个的 只不过需要另外给舵机单独供电
回复 支持 反对

使用道具 举报

发表于 2019-12-1 16:00:10 | 显示全部楼层
impking 发表于 2016-8-28 00:40
不用shield板也可以驱动6个的 只不过需要另外给舵机单独供电

我用arduino控制六个舵机,都能单独正常工作,在一起工作会出现一些莫名其妙的动作
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-20 07:02 , Processed in 0.043224 second(s), 29 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表