Example Code for Firebeetle 2 ESP32-E-Detecting Gesture learning ID

Last revision 2026/03/05

FireBeetle 2 ESP32-E enables gesture detection with the AI Vision Posture Sensor. Setup includes hardware, Arduino IDE, and library guide. Follow the I2C wiring and use provided sample code for detecting learned gestures and controlling the onboard LED.

Hardware Preparation

Software Preparation

Wiring Diagram

I2C Wiring Diagram

SEN0670-I2C wiring diagram

Pin Connection Description:

  • Sensor: + Pin --- (Connects to) --- Main Controller: 3V3
  • Sensor: - Pin --- (Connects to) --- Main Controller: GND
  • Sensor: SCL Pin --- (Connects to) --- Main Controller: 22/SCL
  • Sensor: SDA Pin --- (Connects to) --- Main Controller: 21/SDA

Sample Code

Function: Continuously detects gestures; lights up the onboard LED when a preset learned gesture (ID ≠ 0) is recognized, otherwise turns it off.

#include <DFRobot_HumanPose.h>
#include <Wire.h>

// -------------------------- Core Configuration --------------------------
#define HUMANPOSE_COMM_I2C    // I2C communication only
const uint8_t I2C_ADDR = 0x3A; // Sensor default I2C address
DFRobot_HumanPose_I2C humanPose(&Wire, I2C_ADDR);
const int LED_PIN = LED_BUILTIN; // ESP32-E onboard LED pin (GPIO2 for FireBeetle 2)

void setup()
{
  // Initialize serial for debug
  Serial.begin(115200);

  // Initialize onboard LED (output mode)
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, LOW); // Turn off LED initially

  // Sensor initialization (retry on failure)
  while (!humanPose.begin()) {
    Serial.println("Sensor init fail!");
    delay(1000);
  }
  Serial.println("Sensor init success!");

  // Set detection model to hand gesture
  humanPose.setModelType(DFRobot_HumanPose::eHand);
}

void loop()
{
  bool gestureDetected = false; // Flag for learned gesture

  // Read valid gesture results
  if (humanPose.getResult() == DFRobot_HumanPose::eOK) {
    while (humanPose.availableResult()) {
      HandResult *result = static_cast<HandResult *>(humanPose.popResult());
      // Check for learned gesture (ID != 0 = valid learned gesture)
      if (result->id != 0) {
        Serial.print("Learned Gesture ID: "); Serial.println(result->id);
        Serial.print("Gesture Name: "); Serial.println(result->name);
        gestureDetected = true;
      }
    }
  }

  // Control onboard LED
  digitalWrite(LED_PIN, gestureDetected ? HIGH : LOW);

  // Basic delay to reduce detection frequency
  delay(50);
}

Result

When the sensor recognizes the learned gesture, the LED light on the main control board will light up, and the serial port will synchronously print the gesture ID and name.

Was this article helpful?

TOP