I have the following set up:
Micromod Main Double Board with:
Processor board: Teensy
F0: ZED-F9P GNSS (on teensy Serial1)
F1: ESP32-WROOM-32E WiFi/Bluetooth (on teensy Serial2)
Running the sketch below on the ESP32 echos data received via Bluetooth Serial to the USB-C Serial port (Serial) on the ESP32, and vice versa.
It also attempts to echo all the data to the Micromod teensy processor, but I have been unab le to get this to work using Serial1 or Serial2 on the ESP32 (OUTport in my sketch),
Test setup:
Run on the MicroMod ESP32-WROOM-32 module, as follows:
- Compile for 'ESP32 Dev Module'
- Upload via the USB-C port on the ESP32
- press Reset (or Boot) during dots (.....) to complete flashing
Set up "Serial Bluetooth Terminal" (SBT) App on a mobile phone and pair it with
the ESP32. Open Serial Monitor to USB-C port on ESP32. Type a short text string
into the SBT and it should be echoed on the Serial Monitor (and OUTport), and vice versa.
If needed I am prepared to butcher the esp32 cores under:
... AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.6\cores\esp32
to add /modify the definition for the second Serial port but I don't know which files in the cores to change.
Any suggestions much appreciated.
#include <Streaming.h>
#include "BluetoothSerial.h"
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig`
#endif
BluetoothSerial BT;
#define OUTport Serial2 // ESP32 port to MM Teensy processor
void setup() {
Serial.begin(115200);
while (!Serial && millis() < 1000);
Serial << "\n\n======== ESP32_echo_BT.G ========\n";
Serial << " * Open OUTport to Teensy : ";
OUTport.begin(115200);
while (!OUTport && millis() < 1000);
if (OUTport) Serial << "OK\n";
else Serial << "** BAD **\n";
Serial << " * Init BT (on 'ESP32_MM'): ";
BT.begin("ESP32_MM"); //Bluetooth device name
if (BT) Serial << "OK\n";
else {Serial << "FAILED ** program HALTED **\n"; while(true){}; }
Serial << "------ setup done ------\n";
}
// Echo data from ESP32 Serial Monitor to Bluetooth Serial, and teensy
// Echo data from to Bluetooth Serial to ESP32 Serial Monitor, and teensy
void loop() {
if (Serial.available()) {
char c = Serial.read();
BT.write(c);
OUTport.write(c); // also copy to teensy
}
if ( BT.available()) {
char b = BT.read();
Serial.write(b);
OUTport.write(b); // also copy to teensy
}
//delay(20);
}