ESP32 Hello World – Serial Print For Debugging – Arduino

Previous Tutorial Previous Tutorial Tutorial 2 Next Tutorial Next Tutorial
  ESP32 Hello World! Serial Port Print – Arduino  
  ESP32 Course Home Page ????  

 

In this tutorial, you’ll learn how to use the ESP32 serial print function in Arduino IDE to print our first Hello world example. Then, we’ll discuss how to print numeric variables for debugging Arduino code. And finally, use the ESP32 to send some numeric data over the serial port and plot the data points in Arduino IDE serial plotter. So, let’s get started!

ESP32 Hello World Example - Serial Port Print - ESP32 Serial Plotter Tutorial

[toc]


Requirements For This Tutorial

Prior Knowledge

  • Nothing

Software Tools

Hardware Components

You can either get the complete course kit for this series of tutorials using the link down below. Or just refer to the table for the exact components to be used in practical LABs for only this specific tutorial.


ESP32 UART Serial Port

 

As we’ve stated earlier in the introductory tutorial, the ESP32 has 3 UART peripherals. One of which is hard-wired to the USB-TTL converter on the ESP32 dev board itself. This is what we’re going to use in this tutorial to send data from the ESP32 to our PC over the UART serial port.

This is a very easy and quick way to debug your Arduino Applications by printing out the current variables’ values to the terminal screen and keep track of what’s going on. And maybe check some flags, logic decisions, etc.

Another use that we’ll also try in this tutorial is the serial plotting feature in the Arduino IDE. We can actually send numeric variables from the ESP32 to the PC and get the value plotted in a graphical interface inside Arduino IDE itself.

ESP32 Serial Port Initialization

First of all, you need to initialize the UART serial port before you’re able to use it for sending/receiving any data. The Arduino built-in library for the serial port doesn’t require you to enter any configuration parameter for the UART peripheral other than the Baud Rate. Which is the rate at which we’ll be sending/receiving serial data.

To initialize (start) the serial port, you need to call the Serial.begin() function and pass the desired baud rate value to it. As shown in the example down below.

This step is typically done in the setup() function before starting the main loop() function. Now, we can send/receive serial data over the UART port using the Arduino API functions shown in the next sections down below.

ESP32 Serial Print Functions

To send data over the serial port, you need to call the Serial.print() function. Which will send the string equivalent of your message byte-by-byte until it’s done. While the Serial.prinln() function will do the exact same thing but it sends a line termination escape sequence “\r\n” at the end of the message.

The code above will print “Hello!” in one line and terminate the line to start a new line for the next message.

ESP32 Serial Read Functions

Before reading serial data, it’s important to check if there is data that has been received already in the buffer or not. And then, we can proceed to read its contents. To check if data has been already received or not, you can use the Serial.available() function.

The example down below shows you how to check the incoming data and echo the received data back to the serial port. So you can see what the ESP32 has already received.

 

If you want to learn more about UART Serial Communication Protocol. And how serial communication works at the low level. You can check that tutorial guide for UART communication. It’s pretty long, but very informative indeed!

 


Components For This Tutorial’s LABs

 

QTY. Component Name Buy Links
1 ESP32 Devkit v1 DOIT Board

 

or Any Other ESP32 Dev Board

Amazon.com  –  eBay.com  –  Banggood.com
2 BreadBoard Amazon.com –  eBay.com –  Banggood.com
1 Micro USB Cable Amazon.com  –  eBay.com –  Banggood.com

*Affiliate Disclosure: When you click on links in this section and make a purchase, this can result in this site earning a commission. Affiliate programs and affiliations include, but are not limited to, the eBay Partner Network (EPN) and Amazon.com, Banggood.com. This may be one of the ways to support this free platform while getting your regular electronic parts orders as usual at no extra cost to you.


ESP32 Hello World Example – LAB

 

LAB Number 2
LAB Name Hello World Serial Print
  • Initialize the UART serial port @ the desired Baud Rate
  • Send a “Hello World!” message once a second

ESP32 Hello World Code Example

The delay() function is used in this example just to achieve the timing requirement for this LAB. In order to have a message sent once a second. Note that it’s not an efficient way to get this job done, you’ll be introduced to better techniques later on in this course (series of tutorials).

Choose the board, COM port, hold down the BOOT button, click upload and keep your finger on the BOOT button pressed. When the Arduino IDE starts sending the code, you can release the button and wait for the flashing process to be completed. Now, the ESP32 is flashed with the new firmware.

Open the Arduino serial monitor from the icon on the top right or from the tools menu and select Tools > Serial Monitor

Screenshot For The Result

ESP32 Hello World Example Arduino IDE - Serial Port Print Tutorial

 


ESP32 Print String And Variable – LAB

 

LAB Number 3
LAB Name ESP32 Serial Print String & Numeric Variable
  • Initialize the UART serial port @ the desired Baud Rate
  • Create a counter variable
  • Send a message showing the counter variable’s value (once a second)

ESP32 Printing a String + Numeric Variable

The numeric variable (Counter) will be evaluated and converted to a string and get printed after the “Counter Value = ” string. The counter is incremented by 1, then the ESP32 executes a delay for 1 second, and repeat!

Choose the board, COM port, hold down the BOOT button, click upload and keep your finger on the BOOT button pressed. When the Arduino IDE starts sending the code, you can release the button and wait for the flashing process to be completed. Now, the ESP32 is flashed with the new firmware.

Screenshot For The Result

ESP32 Hello World Example Arduino IDE - Serial Print String And Variable

 


ESP32 Serial Plotter Example – LAB

 

LAB Number 4
LAB Name ESP32 Serial Plotter
  • Initialize the UART serial port @ the desired Baud Rate
  • Create a lookup table (Array)
  • Send a message containing the current value in the lookup table

ESP32 Serial Plotter in Arduino

The code example down below defines a sine waveform lookup table consisting of 32 values (Array of integers). Then, we’ll send those data points one-by-one over the UART serial print and use the Arduino Serial Plotter to plot the incoming data points. Which should be a, roughly looking, sinusoidal waveform.

Choose the board, COM port, hold down the BOOT button, click upload and keep your finger on the BOOT button pressed. When the Arduino IDE starts sending the code, you can release the button and wait for the flashing process to be completed. Now, the ESP32 is flashed with the new firmware.

Demo Video For The Result

 


Did you find this helpful? If yes, please consider supporting this work and sharing these tutorials!

 

Stay tuned for the upcoming tutorials and don’t forget to SHARE these tutorials. And consider SUPPORTING this work to keep publishing free content just like this!

 

 

  ESP32 Course Home Page ????   
Previous Tutorial Previous Tutorial Tutorial 2 Next Tutorial Next Tutorial
???? Also Read
ESP32 WiFi Tutorial & Library Examples

This is the ultimate guide for ESP32 WiFi, if you’re just starting with ESP32 WiFi, you should definitely check it out. It’ll provide you with a clear roadmap for what to learn and in which order to fully understand everything about ESP32 WiFi.

Share This Page With Your Network!
Join Our +25,000 Newsletter Subscribers!

Stay Updated With All New Content Releases. You Also Get Occasional FREE Coupon Codes For Courses & Other Stuff!

Photo of author
Author
Khaled Magdy
Embedded systems engineer with several years of experience in embedded software and hardware design. I work as an embedded SW engineer in the Automotive & e-Mobility industry. However, I still do Hardware design and SW development for DSP, Control Systems, Robotics, AI/ML, and other fields I'm passionate about.
I love reading, writing, creating projects, and teaching. A reader by day and a writer by night, it's my lifestyle. I believe that the combination of brilliant minds, bold ideas, and a complete disregard for what is possible, can and will change the world! I will be there when it happens, will you?

Leave a Comment