Read serial data from esp32 through FTDI programmer

Hendrik R.
Bad Sassendorf,

Jul 13, 2022
26 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

Hi,
I am currently trying to read data from the ESP32.

I have programmed the ESP to send the string "Hello" continuously in an endless loop with a line break after each word.

Via the serial monitor of the Arduino IDE I get the correct data. Now I try to get the readout via ATEasy and the integrated module "COMM".


---------------------------------------CODE-------------------------------------------
i=50

iStatus = ComOpen(6)
if iStatus=-1
    error -100, "ComOpen() failed"
endif

redim byteArray[10000]

ComSetup(6, 9600, 8, aComParityEven, aComStopBits1, aComHandshakeHardware)

repeat
    ComReceive(6, "\n", 100, , byteArray[0])
    trace byteArray[0]
    i=i-1
    
until i=0

Sleep(2000)

ComClose(6)
---------------------------------------CODE-------------------------------------------

The strange thing is that I only see one command, both via the output using trace, and in the monitor. The data are also arbitrary characters.

I am grateful for any help,
Hendrik

DrATEasy (Ron Y.)
Mission Viejo, CA

Jul 13, 2022
358 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

Hi,

How is the data received supposed to look like?

The way you coded it it should look like
a\n
b\n
c\n
...

Also why are you using array instead of one byte?

Ronnie

Hendrik R.
Bad Sassendorf,

Jul 13, 2022
26 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

Hi Ronnie,

this is exactly the output I was expecting. Unfortunately, I only get a single arbitrary hex value via the monitor, which is directly converted to the corresponding characater. So for example "Þ" or "Ä".

I wanted to use the array so that I don't have to create a new variable for each value.

Preferably, I want the string "Hello" that comes from the ESP to be read completely and written to a single variable. Is this possible with the COMM module or is there another library/driver that is better suited for reading serial ports?

Otherwise, can you give me an example of how to use the COMM module correctly, both with ComSetup and with Write and Receive?

One last thing that I find a bit strange is that I only see the Receive command once in the monitor, even though I execute it 50 times in a loop.

Hendrik

DrATEasy (Ron Y.)
Mission Viejo, CA

Jul 14, 2022
358 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

The string

a\n
b\n
c\n
...

Is not the same as hello\n.

since hello does not have a terminator after each character. Also if you always read to the first element [0], you are overriding it every read.


You can just call:

ComReceive(6, "\n", 1000, , byteArray)


Ronnie

Hendrik R.
Bad Sassendorf,

Jul 15, 2022
26 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

That make sense. But i have the same error.
I only get one and wrong value in the monitor from the serial communication.

This is my current code
------------------CODE---------------------
i=20

iStatus=ComOpen(6)
if iStatus=-1
    error -100, "ComOpen() failed"
endif

redim byteArray[10000]

ComSetup(6, 9600, 8, aComParityEven, aComStopBits1, aComHandshakeHardware)

repeat
    ComReceive(6, "\n", 1000, , byteArray[i])
    
    trace byteArray[i]

    i=i-1
until i=0


ComClose(6)
---------------CODE---------------------

When I read with powershell, I get the correct result.
I also omitted the \n from the EOS parameter, but that did not lead to success either.

Please look at the image i have attached.

I also see there is a ComChat Example. I have tried this with the graphical interface and the standard setup, unfortunately also unsuccessfully. Same result, only one wrong value

Hendrik


File Attachment:
ATEasy_pic.png

Hendrik R.
Bad Sassendorf,

Jul 15, 2022
26 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

That make sense. But i have the same error.
I only get one and wrong value in the monitor from the serial communication.

This is my current code
------------------CODE---------------------
i=20

iStatus=ComOpen(6)
if iStatus=-1
    error -100, "ComOpen() failed"
endif

redim byteArray[10000]

ComSetup(6, 9600, 8, aComParityEven, aComStopBits1, aComHandshakeHardware)

repeat
    ComReceive(6, "\n", 1000, , byteArray[i])
    
    trace byteArray[i]

    i=i-1
until i=0


ComClose(6)
---------------CODE---------------------

When I read with powershell, I get the correct result.
I also omitted the \n from the EOS parameter, but that did not lead to success either.

Please look at the image i have attached.

I also see there is a ComChat Example. I have tried this with the graphical interface and the standard setup, unfortunately also unsuccessfully. Same result, only one wrong value

Hendrik


File Attachment:
ATEasy_pic.png

DrATEasy (Ron Y.)
Mission Viejo, CA

Jul 15, 2022
358 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

Your code reads one byte at the time and you are expecting \n after each byte; otherwise it fails.

ComReceive(6, "\n", 1000, , byteArray[i])

the 1000 will be ignored, since  byteArray[i] has a size of 1 it is the same as calling the function with 1.

You can change to strig and do the following:

ComReceive(6, "\n", 1000, , s)
sRead=sRead+s

if you still want it in byteArray, do at the end

byteArray=s

If that does not work, please post the power shell script.

Ronnie

Hendrik R.
Bad Sassendorf,

Jul 25, 2022
26 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

Hi Ronnie,
sorry for the late feedback.
I have adjusted the code accordingly, unfortunately without success. Also, I have done the reading via PowerShell, which works as desired (See image1).

My actual goal is to send commands and receive the responses generated by the commands.
Currently I am sending commands using ATEasy (See Image2), but I am getting a timeout and also the LEDs for TX and RX on the FTDI are not lit, which indicate sending and receiving data respectively.

I have sent the same command with the program "RealTerm". There I get the corresponding result (See picture3)
I need this information in ATEasy for further processing.


File Attachment:
picture_1.png

Hendrik R.
Bad Sassendorf,

Jul 25, 2022
26 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

picture_2


File Attachment:
picture_2.png

Hendrik R.
Bad Sassendorf,

Jul 25, 2022
26 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

picture_3


File Attachment:
picture_3.jpg

DrATEasy (Ron Y.)
Mission Viejo, CA

Jul 25, 2022
358 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

Try the following:

1. The eeprom sending should be out of the loop. The monitor shows sending of one eeprom followed by \r\n\r\n. So use
ComSend(15, "\r\n", 1000, , "eeprom\r\n")
2. ComSend, No need to pass 6 when sending the entire string will be send
3. Increase the timeout from 100 to 1000 for ComReceive and ComSend - does not matter for performance and safer.
4. Try to change ComSetup to use aComHandshakeNone


Ronnie

Hendrik R.
Bad Sassendorf,

Jul 26, 2022
26 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

The changes have partially worked. I now see on the FTDI that the data is being sent. However, when I listen on the channel with a serial sniffer, I see that there is a timeout when sending the commands. To try it out, I set the times for sending and receiving the messages to 10 seconds, unfortunately without success. Due to the timeout, I do not receive any messages. (See picture 4)

Hendrik


File Attachment:
picture_4.png

DrATEasy (Ron Y.)
Mission Viejo, CA

Jul 26, 2022
358 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

You need to take the ComSend out of the repeat loop (before the repeat).  Looking at picture 3, after sending from "eeprom\r\n", you are receiving 5 lines of data. Is that the case?

Ronnie

Paul T.
Maennedorf, Zurich

Jul 26, 2022
64 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

Hi Hendrik,

Could you please try the ComReceive with the “aioDisableComReceiveEarlyReturn” option ?
I remember I had a similar issue years ago, and this option really made it to work. :)

Best,
Paul

Hendrik R.
Bad Sassendorf,

Jul 27, 2022
26 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

I have now tried different things. The ComReceive with the aioDefault=0 as well as with the parameter which is to be seen on the picture. But also with all the others that I can select there. I also took the receive out of the loop to see if I receive anything at all. That is not the case. I always get the same result. The string that should be transmitted does not arrive and I do not receive anything, you can see that in the monitor of ATEasy. What you can see in picture 3 is the program "RealTerm" with which I can receive the data over the FTDI from the ESP over a serial monitor and different settings but also send the command like "eeprom". What you can see in picture 3 is the output of the ESP when I send the command "eeprom". And I would like to see this in ATEasy. But since I don't receive anything according to the monitor, it doesn't work yet.

As mentioned before, when I send the command "eeprom" via ATEasy, I get a timeout. Picture 5 shows the communication via ATEasy and the FTDI/ESP. For this I used a program that listens on the port as a silent observer. I have also tried to send the commands without the silent observer, in the assumption, which could disturb the communication, here also, unfortunately without success.

@Paul Thanks for the tip, unfortunately did not work for me :/

Hendrik


File Attachment:
picture5.png

Paul T.
Maennedorf, Zurich

Jul 27, 2022
64 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

Hi Hendrik,

Try it also without the „\r\n“ in the ComReceive command (otherwise, the receive stops as soon as you get this terminator), and also try it with a bigger timeout for ComReceive (like 3000, 5000…).

Best,
Paul

Paul T.
Maennedorf, Zurich

Jul 27, 2022
64 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

And after ComSetup(…), place a ComFlush(), to make sure you have clean buffers when you send something to your device.

Best,
Paul

Hendrik R.
Bad Sassendorf,

Jul 27, 2022
26 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

I have now tried different things. The ComReceive with the aioDefault=0 as well as with the parameter which is to be seen on the picture. But also with all the others that I can select there. I also took the receive out of the loop to see if I receive anything at all. That is not the case. I always get the same result. The string that should be transmitted does not arrive and I do not receive anything, you can see that in the monitor of ATEasy. What you can see in picture 3 is the program "RealTerm" with which I can receive the data over the FTDI from the ESP over a serial monitor and different settings but also send the command like "eeprom". What you can see in picture 3 is the output of the ESP when I send the command "eeprom". And I would like to see this in ATEasy. But since I don't receive anything according to the monitor, it doesn't work yet.

As mentioned before, when I send the command "eeprom" via ATEasy, I get a timeout. Picture 5 shows the communication via ATEasy and the FTDI/ESP. For this I used a program that listens on the port as a silent observer. I have also tried to send the commands without the silent observer, in the assumption, which could disturb the communication, here also, unfortunately without success.

@Paul Thanks for the tip, unfortunately did not work for me :/

Hendrik


File Attachment:
picture5.png

Paul T.
Maennedorf, Zurich

Jul 27, 2022
64 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

Hendrik,

You copy/pasted the same message from above.
But I wrote to you two new things to try (delete the „\r\n“ from ComReceive and increase the timeout).
Please take a look above.

Best,
Paul

Hendrik R.
Bad Sassendorf,

Jul 27, 2022
26 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

I have now tried different things. The ComReceive with the aioDefault=0 as well as with the parameter which is to be seen on the picture. But also with all the others that I can select there. I also took the receive out of the loop to see if I receive anything at all. That is not the case. I always get the same result. The string that should be transmitted does not arrive and I do not receive anything, you can see that in the monitor of ATEasy. What you can see in picture 3 is the program "RealTerm" with which I can receive the data over the FTDI from the ESP over a serial monitor and different settings but also send the command like "eeprom". What you can see in picture 3 is the output of the ESP when I send the command "eeprom". And I would like to see this in ATEasy. But since I don't receive anything according to the monitor, it doesn't work yet.

As mentioned before, when I send the command "eeprom" via ATEasy, I get a timeout. Picture 5 shows the communication via ATEasy and the FTDI/ESP. For this I used a program that listens on the port as a silent observer. I have also tried to send the commands without the silent observer, in the assumption, which could disturb the communication, here also, unfortunately without success.

@Paul Thanks for the tip, unfortunately did not work for me :/

Hendrik


File Attachment:
picture5.png

Hendrik R.
Bad Sassendorf,

Jul 27, 2022
26 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

oh, i'm sorry! I just reloaded the page and then the text was sent again. I will try your changes

Victor F.
Ergal,

Jul 27, 2022
2 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

Hi Hendrik,
What is ESP32 model you are using ? is this a NodeMCU or similar kit?
Some of the kits use the Serial control lines (RTS,CTS) to reset the ESP32 chip and place the chip in programming mode  , make sure all control lines are disable ?
I have ESP32 NodeMCU ,if you like send me your example i will try from my side ..

Thanks
Victor F

Hendrik R.
Bad Sassendorf,

Jul 27, 2022
26 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

@Paul, Tried all of your changes, thanks for that but it does not work for me.

@Victor I am using ESP32-WROOM-32UE it is the Single SMD Chip on a selfmade PCB.
No RTS/CTS or DTR/DSR is used with the RealTerm program. The hardware flow control setting is "None" and with the setup it works with the tool.

Meanwhile I believe that it is not compatible with the integrated COMM module of ATEasy. Have you had any experience with other modules or libraries that can be used for serial communication?

Paul T.
Maennedorf, Zurich

Jul 27, 2022
64 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

Hi Hendrik,

Are you sure you use exactly the same settings with the RealTerm?
Can you show us a working snapshot with the RealTerm, and also the COM settings that you used?
I really doubt something is wrong wirh ATEasy… Rather some settings are not the same, it should not be that complicated.
I saw in one of your previous pictures that you were using hardware handshake, and later None…

Best,
Paul

Paul T.
Maennedorf, Zurich

Jul 27, 2022
64 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

And also put return variables from all your Com commands in ATEasy and make sure they return the successful value.
In your first picture, I saw that Receive was working more or less for the „Hello“ message. How come it worked back then? Were you having the HardwareHandshake or?

Best,
Paul

Victor F.
Ergal,

Jul 27, 2022
2 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

Hi Hendrik,
I checked with  Node32s board  and the example provided with ATEasy "ComChat.prj" and it works correctly ..
just make sure you you setup the Baud rate at fixe value in your Arduino code , if not after reset the ESP32 can take any speed by default.

I hope this can help.

Kind Regards

Hendrik R.
Bad Sassendorf,

Jul 28, 2022
26 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

Hi Paul, Victor

@Paul Please see picture 6. there I played the code to the ESP to make it send the string "Hallo" permanently. I also checked the return values of the COM functions (good tip by the way). I noticed that for ComReceive everything is OK for the first command and for the following ones the value is -1. If I take the \r\n out of ComReceive, the return value is 0, so it is ok.
The problem which still exists with the reception is, at which time the string is read. As you can see in the monitor, I don't get a coherent string yet.

@Victor I have also tried your suggestion and set the values with the panel under ComChat.prj. I get the "Hallo" too, but as in the monitor before, chopped (See picture 8).

@Paul Furthermore I have still the setting of the RealTerm in picture 7 taken.

So in general I can say that I can receive messages, although not yet correctly formatted. But for some reason sending via ATEasy does not work yet. Neither over the ComSend nor over the ComChat panel. If I listen with again on the port a silent observer, I get a timeout when sending also via the ComChat Panel.


File Attachment:
picture6.png

Hendrik R.
Bad Sassendorf,

Jul 28, 2022
26 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

picture 7


File Attachment:
picture7.png

Hendrik R.
Bad Sassendorf,

Jul 28, 2022
26 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

picture 8


File Attachment:
picture8.png

DrATEasy (Ron Y.)
Mission Viejo, CA

Jul 28, 2022
358 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

The aioDisableComReceiveEarlyReturn should only used if there is no terminator, you should remove it.

Can you change the receive to use only the \n instead of \r\n (just to see).

I tried it with virtual ports with ComChat x2 and it works as designed:, see  picture9.


File Attachment:
picture9.jpg

Hendrik R.
Bad Sassendorf,

Jul 28, 2022
26 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

Hi Ronnie

For me there has been no change without the \r

Is it possible to switch the CTS/RTS pins on or off via ATEasy? (See picture 7)
I have to turn off the RTS for the communication to work via the FTDI. Is it possible to do this also via ATEasy or via the COMM module?

Solution Available
Hendrik R.
Bad Sassendorf,

Jul 29, 2022
26 Posts

1  |  0  

Re: Read serial data from esp32 through FTDI programmer

IT WORKS! Damn..

If you guys are looking at picture 7. You see, that RTS is Constant LOW. If its Enabled, the Sending Command does not work.

Solution: The FTDI have 6 PINS (Using FT232RL Chip from Waveform btw) And we have: VCC, GND, TXD, RXD, RTS, CTS but for the communication from UART you only need VCC GND TXD and RXD. So, since the PIN of RTS must always be LOW, I just pinched it off. Thats it.

Thanks for all your Help @Ronnie,Paul and Victor

Hendrik


File Attachment:
done.png

Paul T.
Maennedorf, Zurich

Jul 29, 2022
64 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

Hi Hendrik,

Well, I’m glad it works, but for me it’s not clear what you did…
I mean, you had the same hardware wiring with the RealTerm and with ATEasy, right? Or once you had the RTS line connected, and second not?!
Could you please explain? I am interested to understand.
Thank you.

Best
Paul

Hendrik R.
Bad Sassendorf,

Jul 31, 2022
26 Posts

0  |  0  

Re: Read serial data from esp32 through FTDI programmer

Hi Paul,
Yes i had the same Hardware setup for RealTerm and ATEasy.
But in RealTerm it was possible to set the RTS and DTR pin to HIGH or LOW on the software side. The communication in Realterm only worked when RTS was on LOW and DTR was on HIGH. Because I didn't find this setting in ATEasy, I cut the RTS and CTS pin on the FTDI, so that I have only the pins: GND, VCC, TXD and RXD on the FTDI, because more is not necessary for the transmission via UART.

Probably a confirmation on a pin was missing, which was necessary to send (if one uses the pins). This would also explain the timeout when sending commands from ATEasy. Because RTS stands for "Ready to send".

Hendrik



Please Note
You need to have a M@GIC account to participate in the Forums.
Not yet registered on our website? Click here to register today!

All content, information and opinions presented on the Marvin Test Solutions User Forums are those of the authors of the posts and messages and not Marvin Test Solutions'. All attachments and files are downloaded at your own risk. [Read More]