ESP32-P4 HuskyLens Display — Dfrobot Firebeetle2 Esp32P4 simulation

ESP32-P4 project with HuskyLens, Grove Vision AI and LCD display

An interactive Dfrobot Firebeetle2 Esp32P4 circuit simulation you can run free in your browser on Velxio, by davjoel996.

Components

Sketch code

// DFRobot FireBeetle 2 ESP32-P4 - blink the on-board "L" LED (GPIO/pin 3).
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "DFRobot_HuskylensV2.h"

// Set up the I2C LCD (Typically address 0x27)
LiquidCrystal_I2C lcd(0x27, 20, 4);

// Create the HuskyLens object using the exact class name required by V2
HuskylensV2 huskylens;

void updateDisplay(String line1, String line2) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(line1);
    lcd.setCursor(0, 1);
    lcd.print(line2);
}

void setup() {
    Serial.begin(115200);
    delay(500); 

    Serial.println("--- Starting HuskyLens Simulator Sequence ---");

    // 1. Initialize LCD
    lcd.init(); 
    Wire.end(); 
    delay(100);

    // 2. Lock back onto Pins 7 and 8 cleanly
    Wire.begin(7, 8);
    lcd.backlight();
    updateDisplay("System Booting", "Bus Stabilized");
    delay(1000);

    // 3. Native initialization call for HuskyLens V2
    // We break it out of the while loop so a minor library handshake issue doesn't stall the code execution
    huskylens.begin(Wire); 
    Serial.println("HuskyLens Init signal sent over I2C.");

    // 4. Force state transition to matching menu
    huskylens.switchAlgorithm(ALGORITHM_FACE_RECOGNITION);
    updateDisplay("System Ready", "Scanning...");
}



void loop() {
    // Tell the camera to look for objects using its current algorithm
    huskylens.getResult(ALGORITHM_OBJECT_RECOGNITION);
    
    // Check if the camera detects anything
    if (huskylens.available(ALGORITHM_OBJECT_RECOGNITION)) {
        
        // Extract the name string dynamically using the V2 library macro
        // This targets the object closest to the center of the camera view
        String dynamicName = String(RET_ITEM_STR(huskylens.getCachedCenterResult(ALGORITHM_OBJECT_RECOGNITION), Result, name));
        
        // Fallback in case a custom object is learned but has no text label assigned
        if (dynamicName.length() == 0 || dynamicName == "null") {
            int objectID = RET_ITEM_NUM(huskylens.getCachedCenterResult(ALGORITHM_OBJECT_RECOGNITION), Result, ID);
            dynamicName = "Object ID: " + String(objectID);
        }

        Serial.print("Target Spotted! Name: ");
        Serial.println(dynamicName);
        
        updateDisplay("Object Found!", dynamicName);
    } 
    else {
        updateDisplay("Scanning...", "No target");
    }
    
    delay(250); // Frame refresh rate
}

More projects by davjoel996