Examples for the ESP32

Open, press F9, go through line by line with F8 – in assembly and in aBelle.

The examples in assembly are in the folder examples\esp32 of the ZIP, those in aBelle in examples\abelle\esp32. Each runs with F9 in the RAM of the board under the debugger; Debug > Write to Flash and Run (Shift+F9) writes it into the flash, then it starts by itself after every reset. The registers an example uses are in its comments, with the source.

What an example writes shows under the debugger in the tab Serial next to the output window, else in a terminal on the COM port at 115200 baud. The outputs on this page show what it looks like; the names of the networks and the addresses are changed.

In assembly

Xtensa code with .target esp32, in the folder examples\esp32. The sources are also on GitHub.

Blink

blink_ram.asm, blink_flash.asm

The LED at GPIO 2 on and off, half a second each, counted with the cycle counter ccount. Shows the IO MUX, the GPIO registers with their set and clear addresses and l32r for 32-bit constants. The flash version switches the watchdogs off at the start.

Hello, world!

hello_uart_ram.asm, hello_uart_flash.asm

"Hello, world!" once a second over UART0, the COM port of the board. The text is in .data in the DRAM, where the core can read bytes. The flash version greets at every start of the board.

The clock

clock_ram.asm

The core from the crystal (40 MHz) and from the PLL at 80, 160 and 240 MHz, and how fast a loop goes at each clock. Shows how ESP-IDF switches on the PLL, in a few registers.

The console

console.asm

A small operating system in assembly: a file system in the flash, commands for any terminal (ls, cat, put, rm, df, run, boot) and the packets the window Board Files of Asmonite speaks with.

Start: Debug > ESP32 Board Files > Write Console to Flash, then Format.

In aBelle: the board itself

Programs with target "esp32", in the folder examples\abelle\esp32. They need only the board and the USB cable. They write text and numbers with inc\uart.abel.

Blink

blink.abel

The LED at GPIO 2 on and off. The registers as an array at their address, a function of the ROM with at, and watchdogs_off(), so that the program also runs from the flash.

Hello, world!

hello_uart.abel

"Hello, world!" and a counter, about once a second over UART0. Shows the FIFO of the UART and how to wait until it has room.

Chip info

chipinfo.abel

The MAC address, the package and the revision from the eFuses, with the size of the flash from its JEDEC id. The eFuses do not hold it.

The clock

clock.abel

Switches the core to 40, 20 and 10 MHz every six seconds and measures how fast a loop goes. The LED blinks at the same speed at every clock, because the timer follows.

Clock with a timer

timer.abel

Timer 0 of timer group 0 counts microseconds. The LED blinks, and every second the program writes how long it runs.

Dice

dice.abel

The random number generator of the ESP32: first 600 throws and how often each number came, then one throw a second.

Reaction game

reaction.abel

After 2 to 5 seconds the LED goes on; press the BOOT button as fast as you can. The program writes your time and your best one. Shows a pin as an input with a pull-up.

Sieve of Eratosthenes

sieve.abel

A benchmark: the primes below 20000, ten times, and the time it took. The array of the sieve has 20000 bytes in the DRAM.

Temperature

temperature.abel

The temperature sensor inside the chip, its raw value every second. Put a finger on the module, and the value goes up. The sensor is not calibrated; it tells changes better than degrees.

Before the WiFi examples

  1. Once per board: Debug > ESP32 Board Files, Write Console to Flash and Format if that is not done yet, then Install WiFi (about 25 seconds).
  2. The network: in inc\network.abel enter the name and the password of your network (2.4 GHz, open or WPA2).
  3. Start: open the example and press F9, or upload it to the board with Upload This Program and start it there with Run, run name in the console or as the autostart.

Every WiFi example connects first, gets an address by DHCP and writes it. The program runs on the first core, the WiFi on the second: at a breakpoint the connection stays up.

connecting to my-network
connected
ip: 192.168.1.73  mask: 255.255.255.0  router: 192.168.1.1  dns: 192.168.1.1  lease: 864000 s

WiFi: exploring the network

Scan

scan.abel

The WiFi networks nearby: signal, channel, protection, BSSID and name. Needs only Install WiFi, no password.

  -45 dBm  ch  1  WPA2       02:11:22:33:44:01  my-network
  -74 dBm  ch  1  WPA/WPA2   02:11:22:33:44:02  neighbour
  -84 dBm  ch  6  WPA2/WPA3  02:11:22:33:44:03  cafe

DHCP

dhcp.abel

The first frames of aBelle over the WiFi: a DHCP DISCOVER, built by hand, and the OFFER of the router with the address it would give.

discover sent: 0
offer: 192.168.1.73 from 192.168.1.1

DNS

dns.abel

Names into addresses, at the DNS server of the router, with the time of each answer; a name with a CNAME and one that does not exist. Then all once more, from the cache of the server.

example.com = 172.66.147.243  (42 ms)
no-such-name.invalid: no address

Ping

ping.abel

Four ICMP echo requests to the router and to a server in the internet, as the ping of a PC, with ttl and time. Every example answers pings to the board by itself.

reply from 192.168.1.1: seq 1, ttl 64, 3 ms
4 sent, 4 received, 0 % lost, min/avg/max 2/3/5 ms

The time by NTP

ntp.abel

Asks the time server of the PTB in Braunschweig by NTP (UDP, port 123) and shows the date and the time.

dns: ptbtime1.ptb.de = 192.53.103.108
time: 2026-11-10 06:50:48 UTC, 2026-11-10 07:50:48 CET

Who is in the network?

arpscan.abel

Asks every address of the network by ARP and lists each device that answers with its MAC; also devices that ignore pings. Marks MACs a device made up itself.

Wake-on-LAN

wol.abel

Sends the "magic packet" to a PC, which then starts from sleep. You enter the MAC of the PC in wol_target().

WiFi: services on the board

With net_set_name and mdns_start the board has a name in the network: http://esp32.local/ instead of the address. TCP does one connection at a time, as a client or a server.

UDP echo

udpecho.abel, udpecho.py

Sends every UDP packet to port 7777 back to its sender. On the PC: python udpecho.py with the address of the board.

listening on 192.168.1.73:7777  (mask 255.255.255.0)
echo 1: 6 bytes from 192.168.1.20:61940 echo 1

Fetching a web page

httpget.abel

Finds example.com by DNS, opens a TCP connection to port 80, sends a GET and shows the status line, the title and the length of the page.

tcp: connected in 26 ms
status: HTTP/1.1 200 OK
title: Example Domain
bytes: 928

Web server

webserver.abel

Answers each request on port 80 with a small page: the number of the request, the seconds since the start, the first line of the request. In the browser: http://esp32.local/.

Telnet shell

telnetd.abel

A small shell on port 23: telnet esp32.local (Windows: the feature "Telnet Client", or PuTTY). The files of the board (ls, cat, hex, df), memory (mem), the network (ip, ping, dns), the LED and a reset. With boot telnetd in the console it starts after every reset.

The building blocks behind them, DHCP, DNS, ARP, ICMP, UDP, TCP and mDNS, are in aBelle in inc\net.abel and inc\tcp.abel. In the debugger you can go through each step while the connection goes on on the second core.

Next

The ESP32

Connecting, debugging, flash, console, WiFi, memory and limits.

The ESP32 page →

aBelle

The language of most examples here, with the look of Python.

The aBelle page →

More examples

For Windows and DOS, with the code the assembler makes of them.

To the examples →