我对 Arduino 电路很陌生,我正在尝试将 DFPlayer Mini 连接到 Arduino Nano BLE 33 Sense。如果我理解正确,库“SoftwareSerial”在 BLE Sense 上不起作用,并且我无法找到使 DFPlayer 正常工作的方法(我也尝试使用 HardwareSerial,但由于某种原因它不起作用) . 你知道有什么方法可以修复连接或找到替换库吗?这是我的代码
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
//mp3
SoftwareSerial mySoftwareSerial(12, 11); // RX, TX (meno 11)
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
void setup(void) {
//mp3
if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.
Serial.println(F("Unable to begin:"));
Serial.println(F("1.Please recheck the connection!"));
Serial.println(F("2.Please insert the SD card!"));
while(true);
}
myDFPlayer.setTimeOut(500); //Set serial communictaion time out 500ms
//----Set volume----
myDFPlayer.volume(3);//et volume value (0~30).
myDFPlayer.volumeUp(); //Volume Up
myDFPlayer.volumeDown(); //Volume Down
//----Set device we use SD as default----
myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);
//----Set different EQ----
myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);
//mp3
static unsigned long timer = millis();
if (millis() - timer > 3000) {
timer = millis();
myDFPlayer.next(); //Play next mp3 every 3 second.
}
if (myDFPlayer.available()) {
printDetail(myDFPlayer.readType(), myDFPlayer.read()); //Print the detail message from DFPlayer to handle different errors and states.
}
// wait for a short amount of time -- sometimes a short delay of 5ms will help
// technically we only need to execute this one time, since we aren't changing the colors but we will build on this structure
//----Mp3 play----
//Play the first mp3
}
void loop(void) {
myDFPlayer.play(1);
}
//Mp3
void printDetail(uint8_t type, int value){
switch (type) {
case TimeOut:
Serial.println(F("Time Out!"));
break;
case WrongStack:
Serial.println(F("Stack Wrong!"));
break;
case DFPlayerCardInserted:
Serial.println(F("Card Inserted!"));
break;
case DFPlayerCardRemoved:
Serial.println(F("Card Removed!"));
break;
case DFPlayerCardOnline:
Serial.println(F("Card Online!"));
break;
case DFPlayerPlayFinished:
Serial.print(F("Number:"));
Serial.print(value);
Serial.println(F(" Play Finished!"));
break;
case DFPlayerError:
Serial.print(F("DFPlayerError:"));
switch (value) {
case Busy:
Serial.println(F("Card not found"));
break;
case Sleeping:
Serial.println(F("Sleeping"));
break;
case SerialWrongStack:
Serial.println(F("Get Wrong Stack"));
break;
case CheckSumNotMatch:
Serial.println(F("Check Sum Not Match"));
break;
case FileIndexOut:
Serial.println(F("File Index Out of Bound"));
break;
case FileMismatch:
Serial.println(F("Cannot Find File"));
break;
case Advertise:
Serial.println(F("In Advertise"));
break;
default:
break;
}
break;
default:
break;
}
}
我通过编译得到的错误是这个
Arduino: 1.8.16 (Mac OS X), Board: "Arduino Nano 33 BLE"
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:362:2: error: #error This version of SoftwareSerial supports only 20, 16 and 8MHz processors
#error This version of SoftwareSerial supports only 20, 16 and 8MHz processors
^~~~~
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp: In member function 'bool SoftwareSerial::listen()':
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:418:23: error: 'SREG' was not declared in this scope
uint8_t oldSREG = SREG;
^~~~
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:418:23: note: suggested alternative: 'SING'
uint8_t oldSREG = SREG;
^~~~
SING
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:419:5: error: 'cli' was not declared in this scope
cli();
^~~
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp: In member function 'void SoftwareSerial::setTX(uint8_t)':
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:593:22: error: 'digitalPinToBitMask' was not declared in this scope
_transmitBitMask = digitalPinToBitMask(tx);
^~~~~~~~~~~~~~~~~~~
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:593:22: note: suggested alternative: 'digitalPinToPinName'
_transmitBitMask = digitalPinToBitMask(tx);
^~~~~~~~~~~~~~~~~~~
digitalPinToPinName
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:595:27: error: 'portOutputRegister' was not declared in this scope
_transmitPortRegister = portOutputRegister(port);
^~~~~~~~~~~~~~~~~~
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:595:27: note: suggested alternative: '_transmitPortRegister'
_transmitPortRegister = portOutputRegister(port);
^~~~~~~~~~~~~~~~~~
_transmitPortRegister
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp: In member function 'void SoftwareSerial::setRX(uint8_t)':
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:604:21: error: 'digitalPinToBitMask' was not declared in this scope
_receiveBitMask = digitalPinToBitMask(rx);
^~~~~~~~~~~~~~~~~~~
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:604:21: note: suggested alternative: 'digitalPinToPinName'
_receiveBitMask = digitalPinToBitMask(rx);
^~~~~~~~~~~~~~~~~~~
digitalPinToPinName
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:606:26: error: 'portInputRegister' was not declared in this scope
_receivePortRegister = portInputRegister(port);
^~~~~~~~~~~~~~~~~
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp: In member function 'void SoftwareSerial::begin(long int)':
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:617:31: error: 'table' was not declared in this scope
for (unsigned i=0; i<sizeof(table)/sizeof(table[0]); ++i)
^~~~~
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:617:31: note: suggested alternative: 'tanl'
for (unsigned i=0; i<sizeof(table)/sizeof(table[0]); ++i)
^~~~~
tanl
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:633:9: error: 'digitalPinToPCICR' was not declared in this scope
if (digitalPinToPCICR(_receivePin))
^~~~~~~~~~~~~~~~~
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:633:9: note: suggested alternative: 'digitalPinToPort'
if (digitalPinToPCICR(_receivePin))
^~~~~~~~~~~~~~~~~
digitalPinToPort
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:635:46: error: 'digitalPinToPCICRbit' was not declared in this scope
*digitalPinToPCICR(_receivePin) |= _BV(digitalPinToPCICRbit(_receivePin));
^~~~~~~~~~~~~~~~~~~~
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:635:46: note: suggested alternative: 'digitalPinToPort'
*digitalPinToPCICR(_receivePin) |= _BV(digitalPinToPCICRbit(_receivePin));
^~~~~~~~~~~~~~~~~~~~
digitalPinToPort
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:635:42: error: '_BV' was not declared in this scope
*digitalPinToPCICR(_receivePin) |= _BV(digitalPinToPCICRbit(_receivePin));
^~~
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:635:42: note: suggested alternative: '_B'
*digitalPinToPCICR(_receivePin) |= _BV(digitalPinToPCICRbit(_receivePin));
^~~
_B
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:636:8: error: 'digitalPinToPCMSK' was not declared in this scope
*digitalPinToPCMSK(_receivePin) |= _BV(digitalPinToPCMSKbit(_receivePin));
^~~~~~~~~~~~~~~~~
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:636:8: note: suggested alternative: 'digitalPinToPort'
*digitalPinToPCMSK(_receivePin) |= _BV(digitalPinToPCMSKbit(_receivePin));
^~~~~~~~~~~~~~~~~
digitalPinToPort
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:636:46: error: 'digitalPinToPCMSKbit' was not declared in this scope
*digitalPinToPCMSK(_receivePin) |= _BV(digitalPinToPCMSKbit(_receivePin));
^~~~~~~~~~~~~~~~~~~~
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:636:46: note: suggested alternative: 'digitalPinToPort'
*digitalPinToPCMSK(_receivePin) |= _BV(digitalPinToPCMSKbit(_receivePin));
^~~~~~~~~~~~~~~~~~~~
digitalPinToPort
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp: In member function 'void SoftwareSerial::end()':
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:651:7: error: 'digitalPinToPCMSK' was not declared in this scope
if (digitalPinToPCMSK(_receivePin))
^~~~~~~~~~~~~~~~~
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:651:7: note: suggested alternative: 'digitalPinToPort'
if (digitalPinToPCMSK(_receivePin))
^~~~~~~~~~~~~~~~~
digitalPinToPort
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:652:45: error: 'digitalPinToPCMSKbit' was not declared in this scope
*digitalPinToPCMSK(_receivePin) &= ~_BV(digitalPinToPCMSKbit(_receivePin));
^~~~~~~~~~~~~~~~~~~~
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:652:45: note: suggested alternative: 'digitalPinToPort'
*digitalPinToPCMSK(_receivePin) &= ~_BV(digitalPinToPCMSKbit(_receivePin));
^~~~~~~~~~~~~~~~~~~~
digitalPinToPort
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:652:41: error: '_BV' was not declared in this scope
*digitalPinToPCMSK(_receivePin) &= ~_BV(digitalPinToPCMSKbit(_receivePin));
^~~
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:652:41: note: suggested alternative: '_B'
*digitalPinToPCMSK(_receivePin) &= ~_BV(digitalPinToPCMSKbit(_receivePin));
^~~
_B
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp: In member function 'virtual size_t SoftwareSerial::write(uint8_t)':
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:687:21: error: 'SREG' was not declared in this scope
uint8_t oldSREG = SREG;
^~~~
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:687:21: note: suggested alternative: 'SING'
uint8_t oldSREG = SREG;
^~~~
SING
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:688:3: error: 'cli' was not declared in this scope
cli(); // turn off interrupts for a clean txmit
^~~
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:692:26: error: 'XMIT_START_ADJUSTMENT' was not declared in this scope
tunedDelay(_tx_delay + XMIT_START_ADJUSTMENT);
^~~~~~~~~~~~~~~~~~~~~
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp: In member function 'virtual void SoftwareSerial::flush()':
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:735:21: error: 'SREG' was not declared in this scope
uint8_t oldSREG = SREG;
^~~~
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:735:21: note: suggested alternative: 'SING'
uint8_t oldSREG = SREG;
^~~~
SING
/Users/matteopaoli/Documents/Arduino/libraries/SoftwareSerial-master/SoftwareSerial.cpp:736:3: error: 'cli' was not declared in this scope
cli();
^~~
exit status 1
Error compiling for board Arduino Nano 33 BLE.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
先感谢您!