Best way for Communication Teensy 4.1 and Esp32

gary01

Member
Good Day

I have a tennsy 4,1 and an esp32, I need to pass data along between them, mainly teensy to esp 32, but esp32 to teesny as well. I need to send about 500 bytes of Data between the Teensy and ESP, mainly sensor values that the ESP will then translate into Json and transmit to a server.

I have tried Serial Communication on URT2 on the teensy, I do get response on the ESP so no wire crossed, sometimes i get the full package and sometimes just a []. The baud rates are the same.

i have tired, rates of 9600 to 115200 same type of errors, IF and while (serial available()) methods as well as well as various delays. I have tired the PowerBroker2/SerialTransfer Lib, but i keep getting CRC_ERRORS,

is there any suggestions on another way i can pass clumps of data between these boards. I have tired Structs, Char[] all with similar issues. The big thing is it must be bidirectional, as the esp will receive some data from from the server it must pass to the teensy.

I really am stuck.
 
Not much to go on,

For example an example code that is not working.


Maybe showing a picture might help. Are the pins and/or wires soldered between the two boards? Do you have a common ground wire between them?

I have a few ESP32s around here somewhere, but I have not used them much, so not sure what their limitations on communicates are. Don't know if you would need to hook up some form of RTS/CTS pins between them to transfer 500 bytes or not. But again I don't know what the best approach for your case be.

I know that for example Adafruit Airlift boards are an ESP32, with some additional circuitry and I believe they communicate with the host, using SPI instead of Serial... I also have one of these around which I have not tried yet.

Good luck
 
Not much to go on,

For example an example code that is not working.


Maybe showing a picture might help. Are the pins and/or wires soldered between the two boards? Do you have a common ground wire between them?

I have a few ESP32s around here somewhere, but I have not used them much, so not sure what their limitations on communicates are. Don't know if you would need to hook up some form of RTS/CTS pins between them to transfer 500 bytes or not. But again I don't know what the best approach for your case be.

I know that for example Adafruit Airlift boards are an ESP32, with some additional circuitry and I believe they communicate with the host, using SPI instead of Serial... I also have one of these around which I have not tried yet.

Good luck

Thanks,


I am trying to connect with the TTgo T Call ESP32 Dev Board, with the Simcom 800L chip. this board on its won works very well and have had a lot of success with it.

SIM800L_AXP192.jpg

Becuse the ESP only has 2 Exposed UARTs, USB and the Second one is used for the simcom modem,(Serial(USB), Serial1(SIMCOM) Serial2(custom) I am making use of the 3rd Serial Port, as offered by the ESP. With the ESP you can Change the pin Assignments, so on the ESP Code i Set it up as such

Code:
// on the setup on the ESP32
#define S2Tx 18
#define S2Rx 19

 Serial2.begin(9600,SERIAL_8N1,S2Rx,S2Tx);

//In the main loop

char data2[499];
    if(Serial2.available())
    {
      delay(2000);
      Serial.println("Serial 2 is av");

      Serial2.readBytes(data2,499);
      
    
   }
    Serial.print(data2);

The first time it will execute i might get a full printout, the second time and from there on i get the [] in the console or nothing.

on the Teensy 4.1 SIDE

Code:
// Setup
Serial2.begin(9600);

delay(10);


/// in main loop // USE the Arduino JSON library here, but it just serializes it to a Char[] data 1 with size of 499

String json;
char data1 [499];
serializeJson(doc, json);

json.toCharArray(data1,499);

Serial2.write(data1,499);

delay(1000); // i have tired various Delays here


Wiring is correct and solid, as i do get some data, sometimes, and share a common ground. I have tried the SerialTransfer Library Examples

Delays before and after read/write dies not seem to help much. i have tired many combinations and variations. I have tired with various sizes of char arrays, from 100 to 500. all with similar issues.

your assistance is greatly appreciated.
 
Possibly the esp32 side has a too small buffer. Can you reliably send a short ascii string using similar code?
 
Again I would probably break this down to get an idea of where it may be failing.

And I don't see full code here so hard to know, where.

For example in your T4.1 side, I would probably try replacing the Serial2.write with a write to Serial.print(data1); and see if the data prints correctly.
For example maybe json.toCharArray is not working properly or maybe it needs to reset the array somehow.

But again I would start off simply seeing if the Teensy side generates the correct data multiple times.

Also if my quick calculations is correct, it will take over a half second to send your 499 bytes to the ESP32...

Plus on the ESP32 side, you have a 2 second wait... After you have received something on Serial2... So the Teensy will try to send multiple packets of data to the ESP32. Now very likely the ESP32 Serial ports may not have 500 byte RX buffers let alone 1000 byte RX buffers.

What happens if you simply remove that 2 second wait? Note: I have not looked at ESP32 sources in awhile, but I am assuming the ReadBytes also works like normal Arduino Stream code and it has a timeout for reading in each character and it should return how many bytes that it actual read... So I would probably look at that value...

Also Do you really want 499 bytes to be sent every time or just a string value? That is can you simply send the string between the two with a trailing NULL character?
And on the ESP32 you could maybe simply use Serail2.readString(499);
Which again will create a string object max 499....

Or use Serial2.readBytesUntil(0, data2,499);
Which will read until it gets a null character...
 
Based on that pinout chart, it looks like the ESP supports SPI and I2C. If you can't get serial running, my next bet would be either of those. Failing that, you could talk directly over GPIO, although that is more involved. Are these boards both using the same voltage?
 
Generically (as in not necessarily a T4/ESP32), what is the feasibility of getting higher speed (perhaps 40 mhz), lower overhead (for one end, the other has to do bit-banging) and more flexibility by using SWD or JTAG for inter-processor communications?

https://github.com/PaulFreund/libSWD-esp32
 
I guess anything can be used as a serial port, if you want to try hard enough. The simplest method of communication is I2C (two wires, sorta fast) followed by SPI (three or four wires, pretty fast.) You have to transfer 500 bytes, but how frequently?
 
Is it possible to get ~100 Mbps with ethernet without magnetics? For example, can two teensy 4.1s be connected directly with a few inches of wire - rx to tx?
 
I'm currently communicating between a Teensy 3.2 and an ESP8266--data is going from Teensy to ESP, here's what I did

1. i'm using UART for communication (Teenst Rx - ESP Tx and vice versa)
2. i have a data structure to store, send and receive data using good old fashioned
ESerial.write((uint8_t*) &Data, PacketSize );
and
ESerial.readBytes((uint8_t*) &Data, PacketSize);
3. Because different MCU will pack the structure differently i' use <EasyTransfer.h> library

I'm sending 58 bytes every second and system works fine.

Hope this helps.
 
Hi @KrisKasprzak, could you give me the full code please? Iam very need to like that, I have array in sketch on esp32 and I need to send this array to teensy. any advice please?
 
Back
Top