Skip to content
php-baremetal REGISTRY
Publish a package

php-baremetal/boards-arduino

bm-boards MIT

Board files of the Arduino boards for php-baremetal: chip, memory, console, pin names and the on-board peripherals with their pins.

needs no platform HAL

boards-arduino · ESP32-S3

Arduino Nano ESP32

The Arduino Nano ESP32 (ABX00083): NORA-W106 module, 16 MB flash, 8 MB octal PSRAM, Wi-Fi, an I2C bus on A4/A5 and the Arduino pin names as PHP constants.

Board id arduino-nano-esp32, file boards/esp32/arduino-nano-esp32.json. Arduino documents the board (SKU ABX00083) at docs.arduino.cc.

Property Value
Chip ESP32-S3 (esp32s3), module u-blox NORA-W106-10B
PSRAM octal, 8 MB
Flash 16 MB (GD25B128E, quad)
Console usb-jtag (native USB, USB-C connector)

Pins

The pins key of the board file names the GPIOs as the board and the Arduino core name them. The values are GPIO numbers of the ESP32-S3, taken from variants/arduino_nano_nora/pins_arduino.h of the Arduino ESP32 core (the GPIO numbering, not the Arduino pin numbering 0–24 the core can also use).

Name GPIO Also
D0 44 RX
D1 43 TX
D2 5
D3 6
D4 7
D5 8
D6 9
D7 10
D8 17
D9 18
D10 21 SS
D11 38 MOSI
D12 47 MISO
D13 48 SCK, LED_BUILTIN
A0 1
A1 2
A2 3
A3 4
A4 11 SDA
A5 12 SCL
A6 13
A7 14
LED_RED 46 LEDR
LED_GREEN 0 LEDG
LED_BLUE 45 LEDB

Every name in the "Also" column is a constant of its own with the same GPIO: Pin::SDA === Pin::A4.

Use the pins from PHP

The firmware registers Baremetal\Board\Pin, a final class with one integer constant per name of the table. Any function that takes a GPIO number takes them, such as gpio_mode(), gpio_write() and gpio_read() of ext-gpio.

php main.php, blink the LED on D13
<?php
use Baremetal\Board\Pin;

function setup(): void
{
    gpio_mode(Pin::LED_BUILTIN, GPIO_OUTPUT);
}

function loop(int $tick): void
{
    gpio_write(Pin::LED_BUILTIN, $tick % 2);
    delay(500); // ext-sys
}

With the SDK option board-constants set to global (in extra.baremetal.options), the names are also global constants and the script can drop the class:

php main.php, with board-constants: global
<?php
function setup(): void
{
    gpio_mode(D13, GPIO_OUTPUT);
    gpio_mode(A0, GPIO_INPUT);
}

function loop(int $tick): void
{
    gpio_write(D13, gpio_read(A0));
}

The three colours of the RGB LED are separate pins and are active-low, as the Arduino Nano ESP32 cheat sheet states: write 0 to turn a colour on and 1 to turn it off.

php main.php, the RGB LED in red
<?php
use Baremetal\Board\Pin;

function setup(): void
{
    foreach ([Pin::LED_RED, Pin::LED_GREEN, Pin::LED_BLUE] as $pin) {
        gpio_mode($pin, GPIO_OUTPUT);
        gpio_write($pin, 1); // off
    }
    gpio_write(Pin::LED_RED, 0); // on
}

function loop(int $tick): void
{
}

Blocks

Block Type Keys Handled by Notes
network wifi none the SDK + ext-wifi The script connects with ext-wifi.
i2c i2c sda A4 (GPIO 11), scl A5 (GPIO 12) ext-i2c Bus::onboard(); the Nano's I2C pins.

The i2c block names its pins: the SDK replaces "A4" and "A5" with their GPIO numbers from pins when it loads the board. The keys are described in Board files; a project changes them with board overrides, where pin names work as well ("sda": "D2").

Use it in a project

bash in the project folder
composer require php-baremetal/boards-arduino
composer require php-baremetal/ext-gpio php-baremetal/ext-wifi php-baremetal/ext-i2c   # what you use
json composer.json, extra.baremetal
{
  "sdk": "esp32@^2.0",
  "board": "arduino-nano-esp32",
  "runtime": "init-loop",
  "storage": "embedded"
}

Install only the drivers of the blocks the program uses: a block without its driver is left alone. The pin names need no package.

Notes

  • D13, SCK and LED_BUILTIN are the same GPIO 48: the LED lights when the pin is high, and it follows the clock of an SPI bus on D13.
  • The console is the chip's native USB port (USB-Serial-JTAG), not a UART on D0/D1 (RX/TX).
  • Some boards of the first limited production batch have an RGB LED with the green and blue pins swapped, as Arduino notes in the cheat sheet; on those boards LED_GREEN lights blue and LED_BLUE green.
  • The board file follows the Arduino core's names for the pins; Arduino® is a trademark of Arduino S.r.l.

Related