Is there anyway to send manually typing messages to arduino through serial port in platformio?

Hi, @pfeerick
Is there any detailed method to use CoolTerm for talking to arduino when running platformio code?
I searched these days, but failed.
Best regards.

Not that I know of. There isn’t anything special about it anyway. Load up CoolTerm, hit the Options toolbar button, pick your serial port, baud rate. If you need it to act like the Arduion IDE, and send after pressing enter rather than as you type, goto the ‘Terminal’ page of the options, and set it to ‘Line mode’, and change the Enter key emulation if needed (CR+LF, LF, etc). Then connect or disconnect as needed (i.e. connect after uploading, disconnect before doing a new upload).

It is probably possible to integrate it into PlatformIO somewhat via extra-scripting, but that would probably be a bit clunky. Assuming it is possible.

Thank you for giving me the detailed illustration, @pfeerick
By the way, I find that there is “send_on_enter” in Serial Monitor of platformio ide:


Does it is what we want?

2 Likes

Nice spot.

Documentation says

Send a text to device on ENTER

So it’s worth a try. See what happens when you add monitor_filters = send_on_enter to your platformio.ini, and restart the serial monitor. :wink:

1 Like

Hi, @pfeerick
It works very well.
By the way, I find that if the arduino code contains ‘\n’ as the terminate character, for example:


then the “stringComplete = true;” in “else if” can’t be reached.
For finding the reason, I set “monitor_filters = debug, send_on_enter”, then I find:
4
It seem that the platformio receives ‘\r\n’ (not ‘\n’) when I hit the “Enter” key in my keyboard.
But in my textbook, it says that ‘\n’ is Enter key, I’m very puzzled.
Best regards.

Yes, \n is the traditional newline/line feed character. However, Windows considers it to be a carriage return (\r) + line feed (\n) for the end of line. Hence CR+LF, instead of just LF. on Windows, and just LF on Linux/unix/MacOS. Also, C/C++/Perl expects LF, but Python/Java expects CR+LF. Not confusing at all. :face_vomiting:

Since it’s the default for python (which PlatformIO is written in), I expect it will be the same everywhere, but can be changed in the source code. But this is the reason you have to option to change it in the Arduino IDE serial monitor.

Hi, @pfeerick
I find that there is an option in platformio device monitor:
1
It maybe the method I searched, but how to set “–eol = LF” in platformio.ini or somewhere else?
Best regards.

I used this to get it to work in a terminal session outside of VSCodium:

pio device monitor --eol=CRLF --echo --filter send_on_enter

I needed the --echo as I suspect that with the filter to send_on_enter, it no longer echoes. Anyway, I now know that that works on the command line, adding the folloiwng to my platformio.ini file also now works:

monitor_flags = 
    --echo 
    --eol 
    CRLF

As per the docs at Redirecting..., the flags and their options must each be supplied on a new line. What it doesn’t say, and it will not work, unless you start each line with a tab. (Or spaces?) I get the impression that this needs to be in Python format - where indents are required.

The above works in VSCodium (1.34.0) on Linux Mint 19.3 64 bit.

HTH

Cheers,
Norm.

1 Like

Yup, python format. And it can be spaces or tab - just needs to be indented.

1 Like

Hi, @normandunbar , thanks a lot.
The “monitor_flags” format also works in vscode+platformio (on win10 64 bit), according to my arduino code above, I add the following to my platformio.ini file:

monitor_flags =
    --filter
    debug
    --filter
    send_on_enter
    --echo
    --eol
    LF

By the way, I set --eol to be LF, so the “Enter” key equals ‘\n’:
6
but in my arduino code above, the

else if ( inChar == ‘\n’ )

in “void serialEvent()” can not be reached. I don’t know why. Can you help me?
Best regards.

I would add a Serial.println(inChar, HEX); debug line just after you read a character into inChar to see if the \n is actually being passed over to your code. I have a feeling, but don’t quote me, that the send-on-enter filter might be filtering off the \n and it’s not reaching your code.

You would see a or 0a if there is a \n coming through.

HTH

Cheers,
Norm.

1 Like

Thank you very much, @normandunbar
You are right, the ‘\n’ was filtered off, so ‘\n’ can not be received by arduino.
7
Best regards.

1 Like

Excellent! Never underestimate the power of a quick Serial.println when trying to debug. It’s what I’ve been doing most of my working life!

Cheers,
Norm.

3 Likes

The general docs “platformio.ini” (Project Configuration File) — PlatformIO latest documentation state

Multiple value options can be specified in two ways:

  • Split values with “, ” (comma + space)
  • Multi-line format, where each new line starts with at least two spaces
1 Like

Hi @maxgerhardt,

thanks for the link. When I mentioned that there was no mention of having to start each line with spaces or tabs, I was referring to the link I posted (above) to the monitor_flags docs. Happy that the need for spaces etc is documented elsewhere.

I hadn’t used monitor_flags up until then, and didn’t initially spot the example’s leading spaces/tabs until I tried it without and it failed to work.

Cheers,
Norm.

2 Likes

Thanks for the information sharing.

Add the following command lines to platformio.ini :

...
monitor_filters = send_on_enter
monitor_flags = 
     --echo

Restart VSCode and try something like this…

Cheers,
Roe

Hi, thank you for all the info above. However, I couldn’t manage to type anything into the terminal. Is there any setting I missed? I already added send_on_enter in the filter.

If you enable the “echo” flag, you would be able to see what you typed. Otherwise, just hit enter and what you typed would be sent to the device, it just won’t show up in the terminal

Use this Serial monitor extension thats the best way to use serial monitor in vs code :relaxed: