Serial Comunication (esp32, app developer)

For general Flowcode discussion that does not belong in the other sections.
Post Reply
Oscar_T
Posts: 89
http://meble-kuchenne.info.pl
Joined: Wed Dec 02, 2020 10:06 am
Location: Italy
Has thanked: 37 times
Been thanked: 10 times

Serial Comunication (esp32, app developer)

Post 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.
Attachments
Flowcode_example.fcfx
(12.14 KiB) Downloaded 134 times
APP_PC.fcsx
(14.01 KiB) Downloaded 114 times

BenR
Matrix Staff
Posts: 1786
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 455 times
Been thanked: 621 times

Re: Serial Comunication (esp32, app developer)

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

Oscar_T
Posts: 89
Joined: Wed Dec 02, 2020 10:06 am
Location: Italy
Has thanked: 37 times
Been thanked: 10 times

Re: Serial Comunication (esp32, app developer)

Post 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

Post Reply