Getting Started
An Arduino library to drive Hapbeat haptic devices over Wi-Fi UDP from an ESP32 / M5Stack / ESP8266 / Arduino-compatible Wi-Fi board. Press a button → the Hapbeat buzzes, in the fewest steps.
What you need
Section titled “What you need”- An ESP32-series / M5Stack / ESP8266 board with Wi-Fi (anything with
WiFiUDP) - A Hapbeat device (firmware flashed) on the same Wi-Fi / LAN
- Arduino IDE or PlatformIO
The library itself has zero dependencies. Only the examples use M5Unified.
Install
Section titled “Install”- Arduino IDE: Library Manager → search “Hapbeat” → Install. (Or Sketch → Include Library → Add .ZIP Library from a repo ZIP.)
- PlatformIO: add to
lib_depslib_deps = hapbeat/arduino@^0.1.0
First buzz (no kit needed)
Section titled “First buzz (no kit needed)”The quickest check is the synthesized sine. It needs no kit on the Hapbeat — if a powered Hapbeat is on the same LAN, it just buzzes.
#include <WiFi.h> // ESP8266: <ESP8266WiFi.h>#include <Hapbeat.h>
Hapbeat hb;
void setup() { WiFi.begin("YOUR_SSID", "YOUR_PASS"); while (WiFi.status() != WL_CONNECTED) delay(200); WiFi.setSleep(false); // keep the radio awake while streaming hb.begin(7700, "MyDevice"); // app name shows on the Hapbeat OLED}
void loop() { // on some input: hb.playSine(160.0f, 0.7f, 400); // 160 Hz, intensity 0.7, 400 ms (no kit)}When the app name you passed to hb.begin() appears on the Hapbeat OLED,
you are connected.
Fire a kit event (command mode)
Section titled “Fire a kit event (command mode)”Command mode keeps the waveform in the kit on the Hapbeat and sends only a light trigger from the MCU. Deploy a kit to the device first with Hapbeat Studio.
hb.play("sample-kit.sine_100hz", 0.6f); // the id must exist in the deployed kitEvent ids are <kit-name>.<file-name>. If play(...) does nothing, check the
kit is deployed (use the kit-free playSine to isolate the problem).
What to read next
Section titled “What to read next”- command vs sine — command vs sine
- Synthesized sine streaming — continuous, expressive sine
- Discovery & targeting — device discovery & targeting
- API reference — the API surface