KenHahn
Well-known member
This approach adds wireless capability to the Teensy 4.x by mounting an ESP32 directly onto the Teensy. After all, two brains are better than one - right?
Conceptually, this approach is the same as having a baseboard with both a Teensy and ESP32 on it that are connected together over a serial link as I do with some of my baseboards, but physically is is condensed down to just the Teensy footprint which can be handy for some applications.
This setup uses the Seeed Studio XAIO ESP32-C6 module. It was chosen for a few reasons:
All pins are connected between the Teensy and ESP32 except for the 3.3V and the Teensy GND / D0 pin on the ESP32.
Pin map overlay is shown below.
The ESP32 Serial1 pins are remapped in software to line up with the Teensy Serial5 pins to establish a high-speed serial link. 4Mbps has been tested and found to be very reliable. Theoretical maximum should be 5Mbps based on the ESP32 spec, but so far have gotten mixed results in testing at that max speed. @defragster has been assisting with some of that testing.
The rest of the ESP32 pins come up as inputs, but they are explicitly set as inputs and disconnected from the internal logic just to be sure there is no contention with the teensy pins. The final setup only consumes 2 of the Teensy pins (Serial5).
From the Teensy perspective, it can pretty much ignore the monkey on its back. Assuming it wants to be able to talk to it, then it needs to setup Serial5 at the same comm speed as the ESP32, perhaps setup a serial buffer to avoid overruns and of course, decide on a common communication protocol to talk to said monkey.
Of course, the role of some of the shared pins could be reversed with the Teensy pins set as inputs and the corresponding ESP32 pins used to drive something like an I2C display directly. One nice feature of the ESP32 is that almost any pin functionality can be remapped to almost any physical pin as we did with the Serial1.
On the downsides, this setup does block the USB Host port and is not compatible with the Audio Adapter since it uses pins 20 & 21 on the Teensy. On the Teensy 4.0, the ESP32 sits right over the NXP processor, so under worst-case heavy Wi-Fi transmission use, the ESP32 gets pretty warm and hence the Teensy CPU could get pretty warm as well. Not really an issue with the Teensy 4.1 setup.
This approach does require programming of both the ESP32 and the Teensy which can either be a good or bad thing depending on your perspective. In theory, it should be possible to modify the Espressif AT program binary to adapt it to this application (basically change the pins being use for the serial link) so that programming could be done from the Teensy side only.
Also to note is that the stack can be powered from either the Teensy USB, ESP32 USB or the Teensy 5V pin. There is no power switching circuitry, so only one power source should be connected at a time. If you wanted to hook up both USB ports at the same time, power from one needs to be removed. The Teensy USB power could be disconnected by cutting the VUSB/VIN trace. In my setup I use a USB data extender cable with a built-in power switch off of Amazon.
This setup could be done as a DIY project for those so inclined and of course I am also offering compete and tested assemblies as well for not much more than the retail price of the parts. More info can be found here: https://protosupplies.com/product/teensy4-esp32-stacks/
Conceptually, this approach is the same as having a baseboard with both a Teensy and ESP32 on it that are connected together over a serial link as I do with some of my baseboards, but physically is is condensed down to just the Teensy footprint which can be handy for some applications.
This setup uses the Seeed Studio XAIO ESP32-C6 module. It was chosen for a few reasons:
- Very small 14-pin footprint
- Good Wi-Fi 6 and Bluetooth capability
- Built-in support for Zigbee and Thread for home automation applications
- Overall excellent build quality and manufacturer documentation
- Software support for easily switching between internal or external antenna
- None of the edge pins have boot functionality that could cause issues with the Teensy pins at boot time.
- Seeed XAIO ESP32-C6 Wiki
All pins are connected between the Teensy and ESP32 except for the 3.3V and the Teensy GND / D0 pin on the ESP32.
Pin map overlay is shown below.
The ESP32 Serial1 pins are remapped in software to line up with the Teensy Serial5 pins to establish a high-speed serial link. 4Mbps has been tested and found to be very reliable. Theoretical maximum should be 5Mbps based on the ESP32 spec, but so far have gotten mixed results in testing at that max speed. @defragster has been assisting with some of that testing.
The rest of the ESP32 pins come up as inputs, but they are explicitly set as inputs and disconnected from the internal logic just to be sure there is no contention with the teensy pins. The final setup only consumes 2 of the Teensy pins (Serial5).
Code:
#define RX1 D7 // Teensy 4 Serial 5 is connected to serial port #1
#define TX1 D8
//===============================================================================
// Initialization
//===============================================================================
void setup()
{
Serial.begin(115200); // Init USB port if being used for serial communications.
// Disconnect unused I/O to avoid possible conflicts
gpio_reset_pin(GPIO_NUM_0);
gpio_reset_pin(GPIO_NUM_1);
gpio_reset_pin(GPIO_NUM_2);
gpio_reset_pin(GPIO_NUM_16);
gpio_reset_pin(GPIO_NUM_18);
gpio_reset_pin(GPIO_NUM_20);
gpio_reset_pin(GPIO_NUM_21);
gpio_reset_pin(GPIO_NUM_22);
gpio_reset_pin(GPIO_NUM_23);
Serial1.begin(4000000, SERIAL_8N1, RX1, TX1); //Initialize port connected to Teensy 4.1 and set for 4Mbps
From the Teensy perspective, it can pretty much ignore the monkey on its back. Assuming it wants to be able to talk to it, then it needs to setup Serial5 at the same comm speed as the ESP32, perhaps setup a serial buffer to avoid overruns and of course, decide on a common communication protocol to talk to said monkey.
Code:
#define ESP32SERIAL Serial5 // ESP32-C6 is attached to Serial5 port
// Create buffer to hold incoming characters from ESP32-C6
#define ESP32SERIAL_BUFFER_SIZE 1024
unsigned char esp32SerialBuffer[ESP32SERIAL_BUFFER_SIZE];
//===============================================================================
// Initialization
//===============================================================================
void setup() {
Serial.begin(115200); //Initialize USB serial port to computer
ESP32SERIAL.begin(4000000); //Initialize Seria1 5 connected to ESP32-C6 at same baud rate
// Setup extra memory for the ESP32 serial buffer to help avoid overruns
ESP32SERIAL.addMemoryForRead(esp32SerialBuffer, ESP32SERIAL_BUFFER_SIZE);
Of course, the role of some of the shared pins could be reversed with the Teensy pins set as inputs and the corresponding ESP32 pins used to drive something like an I2C display directly. One nice feature of the ESP32 is that almost any pin functionality can be remapped to almost any physical pin as we did with the Serial1.
On the downsides, this setup does block the USB Host port and is not compatible with the Audio Adapter since it uses pins 20 & 21 on the Teensy. On the Teensy 4.0, the ESP32 sits right over the NXP processor, so under worst-case heavy Wi-Fi transmission use, the ESP32 gets pretty warm and hence the Teensy CPU could get pretty warm as well. Not really an issue with the Teensy 4.1 setup.
This approach does require programming of both the ESP32 and the Teensy which can either be a good or bad thing depending on your perspective. In theory, it should be possible to modify the Espressif AT program binary to adapt it to this application (basically change the pins being use for the serial link) so that programming could be done from the Teensy side only.
Also to note is that the stack can be powered from either the Teensy USB, ESP32 USB or the Teensy 5V pin. There is no power switching circuitry, so only one power source should be connected at a time. If you wanted to hook up both USB ports at the same time, power from one needs to be removed. The Teensy USB power could be disconnected by cutting the VUSB/VIN trace. In my setup I use a USB data extender cable with a built-in power switch off of Amazon.
This setup could be done as a DIY project for those so inclined and of course I am also offering compete and tested assemblies as well for not much more than the retail price of the parts. More info can be found here: https://protosupplies.com/product/teensy4-esp32-stacks/