Attitude Estimation· Live
Home / Chapter 1 / 1.4

ESP32 (Arduino IDE): send text over Serial

Lesson 1.4 · ESP32 · free

Video coming soon

Now the same result on the Arduino Nano ESP32, programmed in the Arduino IDE: a short sketch says hello once and sends a counter every second over Serial. On Windows, the first upload may fail with a DFU error; we fix it once with the post_install.bat driver script and watch the counter in the same serial plotter.

In this lesson · 4 steps
  1. New sketch, board and port
  2. Hello and a counter
  3. Save and upload
  4. Open the serial plotter

1New sketch, board and port

  1. Arduino IDE → File → New Sketch
  2. Board list → Select Other Board and Port → search Nano ESP32 → pick Arduino Nano ESP32 and the board's port → OK
  3. The IDE asks to install the Arduino ESP32 Boards package → Yes (or Tools → Board → Boards Manager → Nano ESP32 → Install)
  4. When the install is done, the board name shows at the top
Why?
The board tells the IDE how to build the code. The port is how the computer talks to the board: it appears when you plug it in (COM9 here, yours may differ). The package holds the files for this board; we install it only once.

2Hello and a counter

ch1_serial.ino · replace everything

Serial.begin opens the serial port at 115200 baud; the plotter must use the same number. setup runs once: we wait one second for the USB serial, then say hello. loop runs forever: print sends the name and a colon, println sends the number and ends the line.

int counter = 0;

void setup()
{
  Serial.begin(115200);
  delay(1000);   /* the Nano ESP32 uses USB serial: give it time to connect */
  Serial.println("Hello from ESP32!");
}

void loop()
{
  Serial.print("counter:");
  Serial.println(counter);
  counter++;
  delay(1000);
}
Why?
Then we add one and wait a second.

3Save and upload

  1. Save the sketch as ch1_serial, then press Upload (arrow button)
  2. Upload fails with No DFU capable USB device available (Windows)? That's the missing driver
  3. Install it once: close the IDE, open %LOCALAPPDATA%\Arduino15\packages\arduino\hardware\esp32\<version>, right-click post_install.bat → Run as administrator, then plug the board in again
  4. Upload again: it reaches 100% and says Done
  5. Still failing? Double-tap the reset button on the Nano ESP32 (the LED pulses), choose the new port and upload again
Why?
DFU is the USB mode the Nano ESP32 uses to receive new code. Windows has no driver for it by default. The board package has a small script that installs it; we run it only once.

4Open the serial plotter

  1. steppeschool.com → Tools → Serial Plotter (or serial.steppeschool.com)
  2. Baud 115200 → Connect → pick the Nano ESP32 port → Connect
  3. Lines like counter:41 in the console, and a line going up on the plot
Why?
This is our web plotter, not the one inside the Arduino IDE. Only one program can use the port, so close the Arduino Serial Monitor first. The counter doesn't start at zero, because the board was already running: we missed the hello line.
Check & troubleshoot

What you should see

  • Lines like counter:41, one per second
  • The plot shows one line, counter, going up

If it doesn't work

  • Upload fails with "No DFU capable USB device available": Windows has no driver for DFU, the USB upload mode. Paste %LOCALAPPDATA%\Arduino15\packages\arduino\hardware\esp32 into the Explorer address bar, open the version folder inside (the only or the latest one), run post_install.bat as administrator, then plug the board in again
  • Still failing: double-tap the reset button (upload mode), pick the new port and upload again
  • Plotter cannot open the port: close the Arduino Serial Monitor first
  • Counter starts at 40, no hello line: the board was already running before you connected; hello is printed only once

Good to know

  • The plotter reads a name, a colon, then a value. Each name becomes one curve. Several values fit in one line with commas: we do that in the next lesson
  • Our loop waits one second, but printing also takes time, so each loop is a little longer. Lesson 1.5 fixes the rate

Next: Lesson 1.5: a fixed-rate loop on the ESP32, without a timer interrupt.