How to send data to the serial console

PawelJalocha
Posts: 13
Joined: Tue Apr 24, 2018 9:14 pm

How to send data to the serial console

Postby PawelJalocha » Tue Apr 24, 2018 9:22 pm

What is the best/easiest/quickest method of sending data to the serial console ?
I mean the most direct method, with least overhead and no data manipulation.
I use putchar() for now but I find it does NL to CR+NL conversion and I would like to avoid such conversion if possible.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: How to send data to the serial console

Postby kolban » Thu Apr 26, 2018 5:14 am

Would printf() not be sufficient? If you need to absolutely minimize latency and simply send a byte ... then the serial API would be the lowest level ...

search for:

uart_write_bytes()

as the ESP-IDF function to use.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

PawelJalocha
Posts: 13
Joined: Tue Apr 24, 2018 9:14 pm

Re: How to send data to the serial console

Postby PawelJalocha » Thu Apr 26, 2018 5:41 pm

Thank you, my main objective right now is to avoid the NL to CR+NL translation and keep the call as elementary as possible. Involving printf() for every character printed would clearly be too much overhead.

Thus I can assume the UART for the console is open and so I can just write to it. Can I read it too ?
What kind of buffering shall I expect in such case ?

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: How to send data to the serial console

Postby kolban » Fri Apr 27, 2018 2:46 pm

Howdy,
Have a good read at this documentation page:

http://esp-idf.readthedocs.io/en/latest ... /uart.html

I think its quite well written and comprehensive. There is a lot there so take your time and read it a few times. If you have questions, post back.

If we were chatting, I'd probably clarify the notion of the "serial console". The ESP32 uses a serial port (also called UART) to read and write data into it. This is what is used by esptool when you flash the device. When you run an ESP32, the application contained within it "just runs" ... however, convention is that during development, we log messages to the UART which can then be read by an external terminal application (or make monitor in ESP-IDF). I'd suggest to stop thinking of the ESP32 as having a "console" but instead think of the ESP32 as having a UART serial port which can "act" as a console.

Yes you can both read and write to the serial port.

See also:

http://esp-idf.readthedocs.io/en/latest ... m/log.html
http://esp-idf.readthedocs.io/en/latest ... nsole.html
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

PawelJalocha
Posts: 13
Joined: Tue Apr 24, 2018 9:14 pm

Re: How to send data to the serial console

Postby PawelJalocha » Sat Apr 28, 2018 12:43 am

Thank you again,

In my application, all works fine, when I use putchar() and the base call to send characters to the console.
But when I try to use UART library and I call uart_write_bytes(UART_NUM_0, ) then I receive stream of errors like:

uart: uart_write_bytes(1073): uart driver error

thus what am I doing wrong ?

Pawel.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: How to send data to the serial console

Postby kolban » Sat Apr 28, 2018 6:58 pm

Did you first call uart_driver_install() to install the driver?

See:

http://esp-idf.readthedocs.io/en/latest ... stallation
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

PawelJalocha
Posts: 13
Joined: Tue Apr 24, 2018 9:14 pm

Re: How to send data to the serial console

Postby PawelJalocha » Sat Apr 28, 2018 10:49 pm

No, but I am writing to the console UART, which is already setup and open, correct ?

I am communicating with the GPS UART and it all works fine, I set it up, etc.
But the console UART is already setup by the system I understand.

Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot] and 89 guests