Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

You can build a browser-based p5.js sketch that reads from or sends commands to an ESP32 over Bluetooth Low Energy (BLE) with p5.ble.js. The sketch runs as the BLE central and the ESP32 as the peripheral: the ESP32 advertises a GATT service with characteristics, and the sketch asks the user to select the device before accessing those characteristics. Both sides must use matching service and characteristic UUIDs and agree on how values are encoded.

What you need before connecting p5.js to an ESP32

  • An ESP32 development board whose variant supports the BLE features you plan to use. The board runs firmware that advertises a BLE service and exposes characteristics.
  • A computer and browser with Web Bluetooth support. Support is not universal; check the current compatibility information before relying on this approach.
  • A secure web context for the sketch, plus a Connect button that the user clicks to begin device selection. Web Bluetooth requires secure contexts and explicit permission, and requesting a device must follow a user action.
  • The p5.js and p5.ble.js libraries loaded by your page.

The browser-side library is a bridge between a p5 sketch and a BLE peripheral; it does not create the ESP32 service for you. For firmware, use Espressif’s ESP-IDF BLE documentation as the official starting point for discovery, connections, data exchange, security, and profiles. Select the exact board variant, firmware framework, BLE stack configuration, UUIDs, characteristic permissions, and payload format for your build.

Choose how the sketch and ESP32 will exchange data

A BLE service groups related characteristics. A characteristic is the value the sketch reads, writes, or subscribes to for updates. Decide the interaction before implementing either side:

Interaction Use it for What must match
Read A sketch retrieves a current value from the ESP32, such as a sensor reading. The characteristic UUID, permissions, and interpretation of the returned value.
Write A p5 interface sends a command or value to the ESP32. The characteristic UUID, write permissions, and serialized payload. The documented p5.ble.js .write(characteristic, data) method takes a string; serialize structured values deliberately rather than passing a JavaScript object.
Notifications The ESP32 sends characteristic updates that the sketch listens for. The characteristic UUID, notification configuration, and agreed payload format.

Match the service UUID in the sketch to the service the ESP32 advertises, and match each characteristic UUID used by the sketch to the corresponding ESP32 characteristic. Also agree on the data type and byte order: the library supports integer, string, floating-point, and custom parsing modes, but the protocol is yours to define on both sides. For example, if firmware sends a textual number, parse it as text or convert it consistently; if it sends bytes, define their order and meaning explicitly.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Connect a p5 sketch to the BLE device

The documented p5.ble.js getting-started flow loads p5.js and p5.ble.js, sets the service UUID, creates a p5ble instance in setup(), and calls the connection method from a Connect button. Once connected, its callback receives available characteristics and the example reads one. The following is a workflow outline, not a complete drop-in sketch: adapt method arguments and callbacks to the installed p5.ble.js version, and implement the matching ESP32 firmware separately.

  1. Load the libraries. Include p5.js and p5.ble.js in the HTML page that hosts the sketch.
  2. Set the service identifier. In the sketch, define serviceUuid to exactly match the service UUID exposed by the ESP32.
  3. Create the BLE client. Instantiate a p5ble object in the sketch’s setup().
  4. Start selection from a user gesture. Attach the connection function to a visible Connect button. The browser’s device request requires user activation and permission, so do not launch it automatically while the page loads.
  5. Use the connection callback. When the user selects a peripheral and the connection succeeds, obtain the characteristic needed for your interaction and begin reading, writing, or listening for updates.
  6. Use the result in the sketch. Update the p5 sketch with the received value, such as drawing a sensor reading to the canvas.

The guide’s read example starts another read after each result and draws the received value. That demonstrates the client sequence, not a verified ESP32 implementation. In a real sketch, choose a read cadence suited to the interaction, or use notifications when the peripheral should push updates; the available sources do not establish comparative performance or power figures.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Read, write, and listen with p5.ble.js

The p5.ble.js API reference documents connection to a service, characteristic reads and writes, notifications, disconnect handling, and connection-state checks. A new p5ble instance connects to one device. Use the API operations that fit the protocol you implemented:

  • Read: Request the characteristic value and handle the result using the type or custom parser appropriate to your agreed payload.
  • Write: Send a string through .write(characteristic, data). If your command has multiple fields, define a serialization format, such as a delimited string or JSON text, and make the ESP32 decode the same format.
  • Notifications: Start notifications on the characteristic when the peripheral should report changes without repeated client reads; stop them when no longer needed.
  • Disconnect and recover: Register a disconnect callback and check connection state before attempting operations. Give the user a way to reconnect after leaving range or losing the link.

Browser limits and common connection failures

MDN describes Web Bluetooth as having limited availability, requires a secure context, and notes that a new device request needs explicit permission and transient user activation. Consult the MDN Web Bluetooth API reference for current details; it was last modified on 2025-05-27. Do not assume every browser, operating system, or device combination supports this workflow.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
  • The Connect action does nothing or the API is unavailable: Check the browser’s current Web Bluetooth support and whether the page is served in a secure context.
  • No device appears: Confirm that the ESP32 is powered, advertising, and exposing the expected service. Check that the sketch requests the same service UUID.
  • The device connects, but reads or writes fail: Verify the characteristic UUID, permissions, operation type, and payload encoding on both sides.
  • Values appear corrupted or nonsensical: Reconcile the sender’s encoding, the selected parser, and byte order. A characteristic UUID match alone does not define what its bytes mean.
  • The link drops: Handle the disconnect event and let the user initiate a new selection and connection.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Where to start on ESP32 firmware

ESP32 firmware must implement the BLE peripheral side: advertise the service, expose characteristics with suitable permissions, and provide the values or command handling the sketch expects. The official Espressif ESP-IDF BLE guide covers the relevant BLE concepts and points to documentation for discovery, connection, data exchange, security, and profiles. It is an ESP-IDF reference; if you choose another firmware framework, use that framework’s documentation for its implementation details.

There is no single firmware example here that can be claimed to work across ESP32 variants or frameworks. Before building, specify your exact board, framework, BLE implementation, characteristic permissions, and payload protocol, then keep those choices synchronized with the p5 sketch. The p5.js Libraries Directory lists p5.ble and credits Yining Shi, Jingwen Zhu, and Tom Igoe.

Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.