How to communicate with MicroMod WiFi Function Board - ESP32?

I have the following set up:
Micromod Main Double Board with:
Processor board: Teensy
F0: ZED-F9P GNSS (on Serial1)
F1: ESP32-WROOM-32 WiFi/Bluetooth (on Serial2)

I am experienced with Arduino / Teensy, but not ESP32.
I set the IDE up for “ESP32 Dev Module” OK, and even succeeded in compiling, uploading and running a sketch on the ESP32 via the USB-C port. The sketch simply echos any serial data received by bluetooth (short texts from my mobile phone) to the USB-C port (Serial), and vice versa. And it works just fine.

But I need to echo the bluetooth data to the Teensy processor instead, and I don’t know how. Due to the fixed Micromod layout the data would have to be transmitted/received via pins 27/28 (IO16/IO17) on the ESP32-WROOM-32 and they are wired through the F1 micromod slot into the Teensy processor A2/A3 pins (i.e Serial 2).

IN fact how can I do a basic test that the Teensy is communicating with the ESP32 Function Board? I’ve not yet seen the ESP32 respond to any AT commands (like AT+GMR) via this same connection from Teensy Serial2. I did try Serial1,2,3,4 and a few different baud rates but no luck so far.

It feels like I’m missing some key documentaion, or hookup guide, on what firmware comes with the Sparkfun ESP32 Function Board, and how the two Serial ports behave.

with thanks in advance :slight_smile:

These is just a couple of stabs in the dark, but hopefully enough to get the ball rolling:

  1. Communication between ESP32 and Teensy: The ESP32 and Teensy should be able to communicate via the MicroMod pins as you described. Let’s start with a basic test to ensure this connection is working.

ESP32 and Teensy Communication Test
This code sets up a basic two-way communication test between the ESP32 and Teensy. Both devices will send a message every second and print any received messages to their respective USB Serial ports for debugging.

// ESP32 Code
void setup() {
  Serial.begin(115200);  // USB Serial for debugging
  Serial2.begin(115200); // UART connection to Teensy
}

void loop() {
  // Send a message to Teensy every second
  Serial2.println("Hello from ESP32");
  delay(1000);

  // Check for incoming messages from Teensy
  if (Serial2.available()) {
    String message = Serial2.readStringUntil('\n');
    Serial.println("Received from Teensy: " + message);
  }
}

// Teensy Code
void setup() {
  Serial.begin(115200);  // USB Serial for debugging
  Serial2.begin(115200); // UART connection to ESP32
}

void loop() {
  // Send a message to ESP32 every second
  Serial2.println("Hello from Teensy");
  delay(1000);

  // Check for incoming messages from ESP32
  if (Serial2.available()) {
    String message = Serial2.readStringUntil('\n');
    Serial.println("Received from ESP32: " + message);
  }
}
  1. ESP32 Firmware: The ESP32 Function Board from SparkFun typically comes with a default firmware that allows for basic functionality. However, when you upload your own sketch, it overwrites this firmware. This is why you’re not seeing responses to AT commands - your custom sketch is now running on the ESP32.
  2. Bluetooth to Teensy communication: To echo the Bluetooth data to the Teensy, you’ll need to modify your existing ESP32 sketch. Here’s a basic outline of how you can achieve this/second test sketch:
// ESP32 Code
#include "BluetoothSerial.h"

BluetoothSerial SerialBT;

void setup() {
  Serial.begin(115200);  // USB Serial for debugging
  Serial2.begin(115200); // UART connection to Teensy
  SerialBT.begin("ESP32test"); // Bluetooth device name
  Serial.println("Bluetooth device is ready to pair");
}

void loop() {
  // Check for incoming Bluetooth data
  if (SerialBT.available()) {
    String message = SerialBT.readString();
    Serial.println("Received via Bluetooth: " + message);
    Serial2.println(message); // Send to Teensy
  }

  // Check for incoming data from Teensy
  if (Serial2.available()) {
    String message = Serial2.readString();
    Serial.println("Received from Teensy: " + message);
    SerialBT.println(message); // Send back via Bluetooth
  }
}

// Teensy Code
void setup() {
  Serial.begin(115200);  // USB Serial for debugging
  Serial2.begin(115200); // UART connection to ESP32
  Serial.println("Teensy is ready");
}

void loop() {
  // Check for incoming messages from ESP32
  if (Serial2.available()) {
    String message = Serial2.readString();
    Serial.println("Received from ESP32: " + message);
    // Process or respond to the message as needed
    
    // Example: Echo the message back to ESP32
    Serial2.println("Teensy received: " + message);
  }
}

Hopefully that’s enough of a scaffold for ya

Ahah, very helpful to know that loading a sketch overwites the firmware, thanks. That explains why the ESP32 responded to “AT+GMR” request a few weeks back, before I uploaded a sketch. I even posted my success on this forum. If you look at My previous post you’ll see the sketch I used at the time, via Serial2. But that sketch doesn’t work now.

Thanks also for confirming the port from ESP32 to teensy is Serial2. I wonder what Serial1 is?

Perhaps if explain what I’m trying to achieve … I’ve got the ZED-F9P in F0 slot working well, and I’ve connected to it using u-center, which has an in-built “NTRIP Client” that I have feeding RTCM3 correction data from a government service provider to the ZED-F9P GNSS through the USB-C port, and I regularly get RTK lock and very high accuracy. So that’s all working great good.

But I will be using the GNSS on a bike=, so no PC available. My plan is to run an NTRIP Client on my mobile and feed RTCM3 data by Bluetooth to the ESP32 in F1 on the Micromod assembly.

My initial plan (Option A) was to echo all data received on bluetooth to the teensy (over Serial2) and then have the Teensy echo it on to the ZED-F9P via Serial1 on the teensy.

But after using u-center’s client I’ve realised I may be able to simply connect the ESP32 USB-C to the ZED-F9P USB-C and have the RTCM3 data sent by that path (Option B) .
I did try this today but I haven’t succeeded yet (due to other problems with the Lefebure NTRIP Client App on my mobile).

Meanwhile I also tried you’re two sketches, running one on ESP32 and one on the teensy processor, but i still get no responses. Your sketches are similar in principle to sketches I have been using to echo bluetooth Serial between to the USB-C on ESP32, and vice versa.
I’ve attached that sketch below. You’ll see it also tries to send data to the teensy (via OUTPort).
The echo to USB-C works, but to OUTport doesn’t. I wonder why? Even if I get OPTION B working I would still like to get ESP32 comms to teensy working.

Lastly, if I need to reflash the ESP32 with the original firmware, how would I do that?

thanks in advance…

/* from Random Nerd Tutorial: https://randomnerdtutorials.com/esp32-bluetooth-classic-arduino-ide/ 

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

Echos commands received on Bluetooth Serial to the USB-C Serial port (Serial), and 
vice versa, and to Micromod teensy processor (Serial1/2 ? )

*/

#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.D ======\n";
  Serial << " * Opening OUTport: ";
  OUTport.begin(115200); 
  while (!OUTport && millis() < 1000);
  if (OUTport)  Serial << "OK\n";
  else          Serial << "** BAD **\n"; 
  Serial << " * Initialise 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 << "\t--- setup done ---\n";
  }

void loop() {
// Echo data from  ESP32 Serial Monitor (USB_C) to Bluetooth Serial, and teensy
  if (Serial.available())  {
    char c = Serial.read();
    BT.write(c); 
    OUTport.write(c);             // also copy to teensy 
    }
// Echo data from to Bluetooth Serial to ESP32 Serial Monitor (USB_C), and teensy
  if ( BT.available()) {
    char b = BT.read(); 
    Serial.write(b); 
    OUTport.write(b);             // also copy to teensy
    }
  //delay(20);
  }

You can modify the loop() to send a message on OUTport and read it back to see if it was correctly received:

void loop() {
  OUTport.print("Test");
  delay(1000);
  if (OUTport.available()) {
    char c = OUTport.read();
    Serial.write(c); // Should print "Test" back to Serial Monitor
  }
}

aliarifat74 I tried that code suggestion, but Serial2 still doesn’t respond :frowning:

FYI this is how I test when running my ESP32_echo_BT sketch:

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 wll be (should be!) echoed on the Serial Monitor, and vice versa.

This is the sketch I’m running on the teensy:

(sorry about the format …
the ‘insert as code’ button has dissappeared from the editor? weird!)


#include <Streaming.h>

#define ESP Serial2

void setup() {
Serial.begin(115200);
while (!Serial && millis() < 1000);
Serial << “\n\n======= t4_echo_ESP32.D ======\n”;
Serial << " * Open Serial2 to ESP32: ";
ESP.begin(115200);
while (!ESP && millis() < 1000);
if (ESP) Serial << “OK\n”;
else Serial << “** BAD **\n”;
Serial << “--------- setup done ---------\n”;
}

void loop() {
if (Serial.available()) { ESP.write(Serial.read()); }
if ( ESP.available()) { Serial.write( ESP.read()); }
delay(10);
}