Simple Test program using Husky V2
williampretty 2026-04-16 06:47:53 19 Views0 Replies I found the following simple program. All it is supposed to do is send the target coordinates to the serial monitor.
The protocol is set to I2C and the blue LED is on indication I2C.
To the best of my knowledge I am using the latest version of the HuskyLens V2 library.
The software compiles without any errors.
When I download and run the software it prints “Hello World” on the serial monitor and nothing else.
------------ code -------------
#include "DFRobot_HuskylensV2.h"
#include "Wire.h"
// Create object
HuskylensV2 huskylens;
void setup() {
Serial.begin(9600);
Wire.begin();
Serial.print("Hello World ");
// Wait for connection
while (!huskylens.begin(Wire)) {
Serial.println("Waiting ... ");
Serial.println("Huskylens not found! Check wiring.");
delay(100);
}
Serial.print("Switching to tracking mode");
// Switch to Object Tracking mode
huskylens.switchAlgorithm(ALGORITHM_OBJECT_TRACKING);
}
void loop() {
// Request results from the sensor
huskylens.getResult(ALGORITHM_OBJECT_TRACKING);
// Check if a target is currently detected
if (huskylens.available(ALGORITHM_OBJECT_TRACKING)) {
// Get the object closest to the center crosshair
auto target = huskylens.getCachedCenterResult(ALGORITHM_OBJECT_TRACKING);
Serial.print("Target ID: ");
Serial.println(RET_ITEM_NUM(target, Result, ID));
Serial.print("Position (X, Y): ");
Serial.print(RET_ITEM_NUM(target, Result, xCenter));
Serial.print(", ");
Serial.println(RET_ITEM_NUM(target, Result, yCenter));
Serial.print("Size (W x H): ");
Serial.print(RET_ITEM_NUM(target, Result, width));
Serial.print("x");
Serial.println(RET_ITEM_NUM(target, Result, height));
}
delay(500);
}

