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);
}

@TS-Russell any chance you can test my code on another Main Double board fitted with ESP32 in F1 slot? :slight_smile:

Let me see if I have the wifi board…I have lots of micromod items but not everything

they’re so cheap I can buy one for you if need be :slight_smile:

Lol…alas, I do not have one…I also don’t have the F9P function either, so I’m only halfway there anyhow :-/

The only other idea I have is to try manually declaring the pin #s to use @ the serial.begin for the respective buses, or perhaps grabbing a different processor in case the teensy’s serial ports are already in use for something else?

Darn! I’m really keen to resolve this ESP32 comms issue before I decide to buy another set of Micromod teensy + main double + ZED-F9P + ESP32, and possibly a third set using the F9R. (The Bluetooth is critical for providing RTCM3 correction data).

FWIW I am prepared to buy a Micromod teensy + main double + ESP32 just so you can test the ESP32 comms before they are shipped to me (but not the ZED-F9P yet, it’s expensive! and irrelevant for this test anyway.)

Meanwhile can you elaborate on “manually declaring the pin #s to use @ the serial.begin for the respective buses ?”

A small clarification: I though I was communciating with F9P over Serial1 but after revisiting the schematic and my code I realised I was using I2C.

As a very last resort: What do you think my ealier suggestion of fitting a USB-C to USB-C cable between the ESP32 module in F1 and the ZED-F9P in F0? This provides the connection path for RTCM correction data, using my ESP32_echo_BT sketch which is working as mentioned, although my first attempts could not get RTK to lock in to the RTCM stream.
Do you think this should this work ?
Or do i need special USB-C cable wiring?
The neat aspect of this approach is it completely avoids the teensy-ESP32 comms, and the awkward correction data echoes via the teensy.

Lol

I’ll be ordering a Wifi board ASAP and should be able to test something next week sometime, barring anything unexpected

good stuff !

have you been able to test this yet @TS-Russell ?
I’m still deperate to resolve this.

In the meantime I swapped the ZED-F9P into Functione One (F1) slot and it worked fine, thus proving the Teensy > Serial2 path to F1 is good.

I also moved ESP32 in slot F0 and tried connecting using Teensy > Serial1, but once again no response (we already know Serial1 is also good as the ZED-F9P works there just fine).

There aren’t many possible causes left, the problem must be the ESP32 module itself, or the Boards package for the ESP32.

In my Boards Manager I have “esp32 by Espressif” installed, but “Arduino ESP32 Boards by Arduino” is not installed. Is this right?

Hoping you can suggest a solution real soon …
thanks

It’s underway! It was delayed a bit by absences, but hopefully I’ll have something for ya soon

Do you have a different processor you can test besides the Teensy?

Good day!
I have plenty of other Arduino and Teensy processors, but they’re not Micromod

I honestly don’t think this is a processor issue, as it’s only doing Serial port setup and comms, whcih I’ve proven for both F0 and F1 slots using the F9P

** note **
In my Boards Manager I have “esp32 by Espressif” installed, but “Arduino ESP32 Boards by Arduino” is not installed. And I select “ESP32 Dev Module” when compiling.

Is this right?
thanks

Ok, that’s probably it - the board is the processor for MicroMods… install the teensyduino add on MicroMod Teensy Processor Hookup Guide - SparkFun Learn and then select Teensy MicroMod

Then attempt the serial test :slight_smile:

You’re misunderstanding, I am talking about boards manager for the ESP32 board. I am experienced with Arduino (10+ years) and Teensy (5+ years) and have Teensyduino installed and working for many sketches, inlcuding the Micromod teensy. As I said: the processor is not the issue, it’s working great!

As I just posted on Gitter:
In the Arduino IDE Boards Manager I am using the “ESP32 by Espressif” to compile for the Sparkfun ESP32 Function Boards with the ESP32-WROOM-32E chip on board. Is this the right boards package? I can compile and upload a sketch that starts and works, but I have been unable to get Serial Comms over Serial1 or Serial2 port on the ESP32 board.

All we’re trying to prove is that Serial Comms from the Teensy Processor to the ESP32 is possible in the Main Double Board setup, whether the ESP32 is in F0 or F1 slot.

I have never seen this work, anywhere!

I definitely am. MicroMod WiFi Function Board - ESP32 Hookup Guide - SparkFun Learn You shouldn’t be using any esp32 board selection for the wifi function board…select the processor board controlling it.

The only way to customize the software on the function board is to change the firmware per the instructions in the guide above…you don’t access the esp32 directly. The function board is peripheral controlled by the processor’s sketch, and you should be selecting Teensy MM