首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Arduino电机屏蔽连接蓝牙屏蔽

使用Arduino电机屏蔽连接蓝牙屏蔽
EN

Stack Overflow用户
提问于 2013-02-25 06:33:26
回答 1查看 1.8K关注 0票数 1

希望这不会太具体,以保证一个问题的结束。

我和校园里的一个研究小组一起学习机器人和自动化。我目前的任务是学习Arduino发动机屏蔽的内部和外部,并将其与蓝牙屏蔽结合起来。

我们使用的是这个蓝牙盾牌这个电动机护罩。如果有必要,我们还可以访问这个电动机护罩

在大多数情况下,我当前的代码可以单独处理每个板,但是当我将它们组合在一起时,突然之间没有什么工作了。电机部分只有在蓝牙特定代码被注释掉时才能工作。这使我得出这样的结论,那就是存在着重大的冲突。话虽如此,我有什么办法让这件事起作用吗?任何工作,等等。

这是我正在使用的代码,以防我的代码出现问题。

代码语言:javascript
复制
#include <SoftwareSerial.h>   // Necessary to use the bluetooth Software Serial Port
#define RxD 7
#define TxD 6

#define DEBUG_ENABLED  1

SoftwareSerial bts(RxD,TxD);

int drive = 12;                    // Pin definitions
int brake = 9;
int power = 3;


const int DRIVE_F = 1;            // Command options returned from parseCommand
const int DRIVE_B = 2;
const int LEFT = 3;
const int RIGHT = 4;
const int STOP = 5;
const int NONE = 0;

void setup() 
{ 
  pinMode(RxD, INPUT);            // Set up pin modes
  pinMode(TxD, OUTPUT);
  pinMode(drive, OUTPUT);
  pinMode(brake, OUTPUT);
  analogWrite(power, 80);

  digitalWrite(drive, LOW);
  digitalWrite(brake, HIGH);
  setupBlueToothConnection();
} 

void loop() 
{ 
    switch(parseCommand())
    {
        case DRIVE_F:                            // Switch through command returns.
              forward();
              bts.println("Driving forward");
              delay(1000);
              fullStop();                        // Go ahead and stop. Don't want
              break;                             // the car to run infinitely yet.

        case DRIVE_B:
              backward();
              bts.println("Driving backward");
              delay(1000);
              fullStop();
              break;


         case LEFT:
              turnLeft();                        // These do nothing for now. Just here for later.
              break;

         case RIGHT:
              turnRight();
              break;


         case STOP:
             fullStop();
             bts.println("Stopping");            // Stop the car. Will be needed later.
             break;

         default:
             turnLeft();                        // If invalid command returned,
             delay(250);                        // wiggle wheels for an error message.
             turnRight();
             delay(250);
             turnStraight();
             break;
    }
} 

void setupBlueToothConnection()                // Not exactly sure why all this is needed. It was in the sample code, so I kept it all
{
  bts.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
  bts.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
  bts.print("\r\n+STNA=SeeedBTSlave\r\n"); //set the bluetooth name as "SeeedBTSlave"
  bts.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
  bts.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
  delay(2000); // This delay is required.
  bts.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable 
  Serial.println("The slave bluetooth is inquirable!");
  delay(2000); // This delay is required.
  bts.flush();
}

void forward()
{
    digitalWrite(drive, HIGH);
    digitalWrite(brake, LOW);
}

void backward()
{
    digitalWrite(drive, LOW);
    digitalWrite(brake, LOW);
}

void fullStop()
{
    digitalWrite(brake, HIGH);
}

void turnRight()
{

}

void turnLeft()
{

}

void turnStraight()
{

}

int parseCommand()
{
    String command = "";                        // String to hold the command
    char recvChar;                              // Char to hold each character.
    while(true)
    {
        if(bts.available())
        {
            recvChar = bts.read();
            if(recvChar == 13)
                bts.println();                // If char received is an ASCII 13, carriage-return/enter key
            else                              // print new line.
                bts.print(recvChar);          // Else, print received char to serial so user can see his/her input.


            if(recvChar != -1 && recvChar != 13)
                command += recvChar;        // If not -1 (no input received from read()) or 13, concat it with command

            if(recvChar == 13)
            {                               // If enter pressed, check the command variable.
                if( command == "forward" )
                    return DRIVE_F;
                else if( command == "back" || command == "backward")
                    return DRIVE_B;
                else if( command == "stop" )
                    return STOP;
                else
                {
                    bts.println("'" + command + "' is an invalid command.");
                    return NONE;           // If invalid, return NONE and print error.
                }
            }
        }


    }

}

先谢了。

EN

回答 1

Stack Overflow用户

发布于 2013-03-03 03:16:02

看看这两个屏蔽,我怀疑是与引脚6上的引脚冲突。Arduino电机屏蔽公开了“两个Aanlog输出的2个TinkerKit连接器(中间是橙色的),连接到D5和D6上的PWM输出。”他们可能有拉下或拉上电阻在D6上,这将干扰您的蓝牙UART通信。

有没有办法将你的蓝牙通信路由到引脚0和1上?如果你这样做的话,你将不得不使用蓝牙而不是USB。

也许一个更简单的方法是切换到一个电机屏蔽,这只是一个电机屏蔽,并采取较少的引脚。类似于只使用引脚的来自斯巴肯的阿杜莫托3、11、12和13

现在有了一个机器人专业小组

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15061334

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档