Page 1 of 1

Serial Comunication (esp32, app developer)

Posted: Wed May 26, 2021 9:07 pm
by Oscar_T
Hello everybody

I have a question about serial communication (com port)

I am currently using esp32 devkit to build a small test station. The program is very simple and is based on sending and receiving data from the esp32.

The problem arises when I have to send and receive LONG or FLOAT data. If I send a single data (such as the reading of an adc) I have no problems, but if I want to send more then I get lost.

For example in the attached program I try to send 3 float values ​​consecutively from the esp32 card and these values ​​must be saved in the program. files are not saved or data does not arrive.


Another thing I noticed that when I send the data from the PC, in the console are sent doubles (only when I send the floats or number). This does not happen if I send a single byte

I would like to understand if it is a timing issue or the way I send and receive data is wrong.

Re: Serial Comunication (esp32, app developer)

Posted: Fri May 28, 2021 12:13 pm
by BenR
Hello,

You could solve this one of two ways.

1) After transmitting each float transmit a ',' character or something else none numeric ( '0' - '9' ) so the routine to receive the float has a delimiter to know when one value ends and the next begins. You might also need a delay after sending each comma to allow the conversion of the ASCII string back into a float format to avoid flooding the MCU UART receive buffer (not likely on the ESP hardware but very likely on something like a PIC/AVR).

2) Instead of using the SendFloat and ReceiveFloat functions you could use the SendBinaryFloat and ReceiveBinaryFloat as this has a fixed with of 4 bytes and so no delimiter character would be required. It won't be readable in the console / terminal emulator but it will be more efficient in terms of less bytes being transmitted and less numeric manipulation to get to and from the float variable.

Hope this helps ;)

Re: Serial Comunication (esp32, app developer)

Posted: Fri May 28, 2021 2:07 pm
by Oscar_T
Hi Ben

I try to implement the recommendations and let you know!

Edit

With the first solution I was lucky and by inserting a character I can send floats in sequence.

Unfortunately not with the second solution.

In the next few days I will try to understand why it doesn't work