Arduino Softwareserial表示向量的多种定义

问题描述 投票:0回答:1

我希望我的arduino能够通过蓝牙与我的手机通信。我在过去也做过同样的事情,并且它已经成功了。我需要它在arduino上玩蛇游戏,这是我的代码。

#include <SoftwareSerial.h>
#include <Otto9.h> //Ottova kniznica
#include <EnableInterrupt.h> 

#define RX 11
#define TX 10
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Otto9 Otto; //Toto je Otik XD
SoftwareSerial bluetooth(TX, RX);

void setup() {


  bluetooth.begin(9600);
  delay(500); 

}

void loop() {
  byte BluetoothData;
  if (bluetooth.available() > 0) {

    BluetoothData=bluetooth.read();

    // dekódování přijatého znaku
    switch (BluetoothData) {
      case '0':
        bluetooth.println("Vypni LED diodu.");
        break;
      case '1':
        bluetooth.println("Zapni LED diodu.");
        break;
    }
  }
  delay(100);
}

不要介意无关的东西,这是我最近项目的代码。

下面是错误:*Arduino.1.8.12 (Windows Store 1.8.33.0) (Windows 10), Vývojová doska: "Arduino Nano"。1.8.12 (Windows Store 1.8.33.0) (Windows 10), Vývojová doska: "Arduino Nano, ATmega328P"

library/SoftwareSerial/SoftwareSerial.cpp.o(符号来自插件)。在函数`SoftwareSerial::read()'中。

(.text+0x0): `__vector_3'的多个定义。

sketch\KarOl-Alpha0-0-1.inio.cpp.o (符号来自插件):(.text+0x0): 第一次定义在这里。

library/SoftwareSerial/SoftwareSerial.cpp.o(符号来自插件)。在函数`SoftwareSerial::read()'中。

(.text+0x0): `__vector_4'的多个定义。

sketch\KarOl-Alpha0-0-1.inio.cpp.o (符号来自插件):(.text+0x0): 第一次定义在这里。

library/SoftwareSerial/SoftwareSerial.cpp.o(符号来自插件)。在函数`SoftwareSerial::read()'中。

(.text+0x0): `__vector_5'的多个定义。

sketch\KarOl-Alpha0-0-1.inio.cpp.o (符号来自插件):(.text+0x0): 第一次定义在这里。

collect2.exe: error: ld returned 1 exit status.

退出状态1

*

c++ arduino bluetooth
1个回答
0
投票

如果你使用多个库,尤其是当其中一个是SoftwareSerial库时,这种情况尤其可能发生。解释是不同的库可能会试图共享相同的 "资源",如引脚变化中断或定时器。解决办法并不总是简单的。例如,如果两个库都需要定时器2,那么它们都不能拥有它.所以使用HardwareSerial或者找到冲突--因此,如果它在旧版本的IDE(和标准库)中工作过,它可能会有突破性的变化。


0
投票

SoftwareSerial和EnableInterrupt库是不兼容的。

EnableInterrupt FAQ明确指出了这一点,并提供AltSoftSerial作为替代方案。来自 https:/github.comGreyGnomeEnableInterruptwikiFAQ#no-really theenableinterrupt-library-does-not-work-with-software-serial-library。:

真的不行,EnableInterrupt库不能和软件序列库一起使用。

不要使用那个库。使用Paul Stoffregen的AltSoftSerial库,地址是 https:/github.comPaulStoffregenAltSoftSerial。. 软件序列库(包括NewSoftwareSerial库),一是用延迟来束缚你的处理器;再者,这些延迟在其ISR内。ISR读取行外的位,在返回之前读取整个字节(包括延迟)!这对一个中断库来说是一个可怕的做法。对于一个中断例程来说,这是一种可怕的做法。AltSoftSerial使用ATmega的定时器电路。它对CPU更友好,允许你的主程序在串行信号转换之间的时间运行,这是串行数据传输过程中的大部分时间。

如果你确实需要使用这两个库,那么你可以尝试管理EnableInterrupt使用哪些端口。这可以通过定义 EI_NOTPORTx 宏。

参见 https:/github.comGreyGnomeEnableInterruptwikiSaveMemory#howto。

在EnableInterrupt问题列表上有一些关于这个特定问题的讨论。请看 https:/github.comGreyGnomeEnableInterruptissues15。https:/github.comGreyGnomeEnableInterruptissues7。

© www.soinside.com 2019 - 2024. All rights reserved.