Reputation: 41
I want my arduino to be able to comunicate with my phone via Bluetooth. I have done this same thing in past and it has worked. I need it for snake game on arduino. Here is my code
#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);
}
Do not mind unrelated stuff, it is code from my recent project.
Here is the error: * Arduino: 1.8.12 (Windows Store 1.8.33.0) (Windows 10), Vývojová doska:"Arduino Nano, ATmega328P"
libraries\SoftwareSerial\SoftwareSerial.cpp.o (symbol from plugin): In function `SoftwareSerial::read()':
(.text+0x0): multiple definition of `__vector_3'
sketch\KarOl-Alpha0-0-1.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here
libraries\SoftwareSerial\SoftwareSerial.cpp.o (symbol from plugin): In function `SoftwareSerial::read()':
(.text+0x0): multiple definition of `__vector_4'
sketch\KarOl-Alpha0-0-1.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here
libraries\SoftwareSerial\SoftwareSerial.cpp.o (symbol from plugin): In function `SoftwareSerial::read()':
(.text+0x0): multiple definition of `__vector_5'
sketch\KarOl-Alpha0-0-1.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
exit status 1
*
Upvotes: 0
Views: 4806
Reputation: 4946
The SoftwareSerial and EnableInterrupt libraries are not compatible.
The EnableInterrupt FAQ explicitly calls this out and offers AltSoftSerial as an alternative. From https://github.com/GreyGnome/EnableInterrupt/wiki/FAQ#no-really-the-enableinterrupt-library-does-not-work-with-the-software-serial-library:
No really, the EnableInterrupt library does not work with the Software Serial library.
Don't use that library. Use Paul Stoffregen's AltSoftSerial library at https://github.com/PaulStoffregen/AltSoftSerial. The Software Serial library (including the NewSoftwareSerial library), for one thing, ties up your processor with delays; furthermore, those delays are within its ISR. The ISR reads in the bits off the line, reading an entire byte (including delays) before returning! This is a horrible practice for an interrupt routine. The AltSoftSerial uses the ATmega's timer circuitry. It is much, much friendlier to the CPU and allows your main program to run at the time between serial signal transitions, which is most of the time during a serial data transmission.
If you do need to use both libraries then you can try to manage which ports EnableInterrupt uses. This can be done by defining EI_NOTPORTx
macros.
See https://github.com/GreyGnome/EnableInterrupt/wiki/SaveMemory#howto
There are some discussions on this specific issue on the EnableInterrupt issues list. See https://github.com/GreyGnome/EnableInterrupt/issues/15 and https://github.com/GreyGnome/EnableInterrupt/issues/7
Upvotes: 1
Reputation: 2989
This is particularly likely if you use multiple libraries, especially if one is the SoftwareSerial library. The explanation is that different libraries may try to share the same "resource" such as a pin-change interrupt, or a timer. The work-around is not always simple. If two libraries both need Timer 2, for example, then they both can't have it. So use either HardwareSerial or find the conflict - so if it has worked in an older version of the IDE (and the standard libs) there might be breaking changes in it.
Upvotes: 0