Auxiliary Function-Use Program to Trigger Learning Function

Last revision 2026/01/20

This article details how to programmatically trigger the learning functions of HUSKYLENS using microcontrollers like Arduino and micro:bit, showcasing sample programs and automation techniques for efficient object recognition.

In addition to manually pressing the "learn button" to learn the target object, it can also be triggered programmatically. This function enables micro: Bit, Arduino, and other mainboards to automatically control the learning of HUSKYLENS.

All 7 algorithms of HUSKYLENS support this function.

Demonstration

Press button A on the mainboard of micro:bit or pull down the Arduino Pin A0 to let HUSKYLENS learn the object once. The object’s ID is 1.

  • Mind+ Sample Program:

Program_Trigger_Learning_Mindplus

  • MakeCode Sample Program:

Program_Trigger_Learning_MakeCode

  • Arduino Sample Program:
#include "HUSKYLENS.h"

HUSKYLENS huskylens;

void setup() 
{
    Serial.begin(115200);
    pinMode(A0,INPUT_PULLUP);
    Wire.begin();
    while (!huskylens.begin(Wire))
    {
        Serial.println(F("Begin failed!"));
        delay(100);
    }
}

void loop() 
{
  if(digitalRead(A0) == 0)
  {
     while (!huskylens.writeLearn(1))  // bool writeLearn(int ID)
    {
      Serial.println(F("learn object ID1 failed!")); 
      delay(100);
    }
    Serial.println(F("learn object ID1 success")); 
  }
}

Result

In object classification mode, aim HUSKYLENS at the following three images in turn. Press button A of micro:bit or pull down the Arduino Pin A0, then HUSKYLENS will learn these three images as objects:ID1 in turn. When HUSKYLENS recognizes any of these three images again, it displays object:ID1 on the screen, indicating that the three workers are wearing safety hats.

1 2 3
10 11 12

Here you can customize the name of ID1, such as safe:ID1; You can also customize the text on the screen, overlaying relevant information to indicate that the status is with safety hat. With the information, the recognition results are easy to understand.

Was this article helpful?

ON THIS PAGE

TOP