Your first firmware
Blink an LED in an SOS pattern: install the SDK, create the project, build, flash and watch the serial console.
This page follows the blink-sos example (04-gpio-led/blink-sos in the examples). It needs a board from the
supported list, an LED with a resistor of about 330 ohm between GPIO2 and GND,
and phpbm with the conductor installed (phpbm docs).
SDK 2.0 is available only as previews (2.0.0-alpha.N); phpbm reads them by default. See the
overview.
Install the SDK
phpbm downloads the newest esp32 release, checks its sha256 and unpacks it into ~/.phpbm/sdks/esp32/<version>.
Choose the board
Connect the board and run phpbm discover. For each serial port it prints the chip and the boards of the SDK
built on that chip.
The chip does not tell the board apart: pick the id whose name and flash size match the board in your hand.
The example uses waveshare-esp32-s3-zero-n8r8. If your board is not listed, use the matching generic board
(see Supported boards).
Create the project
phpbm initwritescomposer.json,project-src/index.phpand.gitignore.composer requireruns the conductor, which installs the packages and writes.phpbm/manifest.json.phpbm toolchain:installinstalls ESP-IDF v6.1 once per machine (about 6 GB).phpbm flashbuilds, checks the chip on the port and flashes. The first build compiles PHP and takes a while.phpbm monitoropens the serial console; leave it with Ctrl + ].
composer.json
extra.baremetal is the SDK's input: sdk (name and constraint), board (a file in boards/), runtime and
storage. The full format is in the
phpbm project guide.
project-src/index.php
With the init-loop runtime the script runs once, then setup() once and loop($tick) forever
(init-loop). gpio_mode() and gpio_write() come from ext-gpio, delay() from
ext-sys.
What the console shows
The example does not record its console output. The firmware prints two lines at start, then your script's output. The first has the form below, with the project name and version, the PHP version, the board name, the ESP-IDF version and the memory limit:
The LED then repeats three short, three long, three short flashes. Edit project-src/index.php and run
phpbm flash again: phpbm rebuilds what changed.
Hold BOOT while you press RESET (or plug the cable in while holding BOOT), release, and flash again: the chip then waits in download mode. More in Troubleshooting.