Search code examples
compiler-errorsesp32arduino-esp32lorasoftware-serial

Compilation error when trying to use SoftwareSerial and BluetoothSerial on esp32


I need to use SoftwareSerial for a little board I made with an M5Stamp and a LoRa board. I also was planning to use Bluetooth, but it gives me a compilation error if I try to use both libraries. Couldn't find much help online.

C:\Path...\AppData\Local\Temp\arduino-sketch-C3A1C31318E964BF44FA1E35A7FE7344\libraries\espsoftwareserial-main\SoftwareSerial.cpp.o: in function std::function<void ()>::operator()() const': c:\Path...\arduino15\packages\m5stack\tools\xtensa-esp32-elf-gcc\gcc8_4_0-esp-2021r2-patch5\xtensa-esp32-elf\include\c++\8.4.0\bits/std_function.h:686:(.iram1.66[_ZNK8delegate6detail12DelegateImplIPvvEclEv]+0x24): dangerous relocation: l32r: literal placed after use: .literal._ZNK8delegate6detail12DelegateImplIPvvEclEv collect2.exe: error: ld returned 1 exit status

Basically, I just need SoftwareSerial on pins 21, 22 of the M5Stamp pico (which are connected to a LoRa board) to work with a Bluetooth library, so I could use my phone for serial data with the board. So any help to make these libraries work or another library recommendation would be appreciated.

I haven't tried much other than searching for answers online and checking out other Bluetooth libraries. But I could couldn't find another library that could send serial data.

This is my first question here.

#include <BluetoothSerial.h>
#include <SoftwareSerial.h>
SoftwareSerial radio(21, 22); //rx, tx
BluetoothSerial SerialBT;

Solution

  • Here is the answer I found online for the m5stamp. No serial library was needed after all:

    for UART you should be able to use any available GPIO for RX and TX like this:

    Serial2.begin(115200, SERIAL_8N1, <RX>, <TX>);

    for I2C you should be able to use any available GPIO for SDA and SCL like this:

    Wire.begin(<SDA>, <SCL>);