Forum >Huskylens with ESP32

Huskylens with ESP32

userHead claan719 2025-01-29 18:23:42 159 Views0 Replies

I have recently purchased a huskylens and I try to get it up and running.

Its firmware is updated to version "0.5.1aNorm"

I

 am using an ESP32 with micropython code for integration using I2C.

The huskylens is set to I2C mode and the device is detected on the I2C bus.

 

However, when I try to do something as simple as possible, such as switching to face detection mode, it just won't work.

I have also tried switching to UART, but that still don't work. I don't get any data from the huskylens device. I have tried loopback in UART mode and that works, so the problem is not on the ESP32 side.  

Can you please give me some good advice how to proceed here ? I provide you with a simple scaled down micropython program (attached) and its corresponding output, which is all 0x00:

 

 

 

MPY: soft reboot
I2C devices found : [50]
Initialize HuskyLens.
Sending: bytearray([0x00])
Received Data (Hex): b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
Set to face recognition mode.
Sending: bytearray([0x02, 0x02])
Received Data (Hex): b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
Check Current Mode: bytearray([0x03])
Received Data (Hex): b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'

 

 

 

Code:

from machine import Pin, SoftI2C
import time

 

class HuskyLens:
   def __init__(self, scl_pin, sda_pin, i2c_addr=0x32):
       self.scl_pin = scl_pin
       self.sda_pin = sda_pin
       self.i2c_addr = i2c_addr
       self.i2c = SoftI2C(scl=Pin(self.scl_pin), sda=Pin(self.sda_pin), freq=100000)
       # Scan for connected I2C devices
       devices = self.i2c.scan()
       print("I2C devices found :", devices)    

 

   def send_command(self, command):
       """Send command to HuskyLens."""
       self.i2c.writeto(self.i2c_addr, command)
       time.sleep(0.1)

 

   def receive_data(self):
       """Receive data from HuskyLens."""
       return self.i2c.readfrom(self.i2c_addr, 32)

 

   def initialize(self):
       print("Initialize HuskyLens.")
       print("Sending: bytearray([0x00])")
       self.send_command(bytearray([0x00]))  # Initialization command
       data = self.receive_data()
       print(f"Received Data (Hex): {data}")
       return data

 

   def set_face_recognition_mode(self):
       print("Set to face recognition mode.")
       print("Sending: bytearray([0x02, 0x02])")
       self.send_command(bytearray([0x02, 0x02]))  # Set to face recognition mode
       data = self.receive_data()
       print(f"Received Data (Hex): {data}")
       return data

 

   def check_current_mode(self):
       """Check current mode."""
       print("Check Current Mode: bytearray([0x03])")  # Command to check current mode
       self.send_command(bytearray([0x03]))
       data = self.receive_data()
       print(f"Received Data (Hex): {data}")
       return data

 

# Initialize the HuskyLens
huskylens = HuskyLens(scl_pin=14, sda_pin=13)

 

# Initialize the device
huskylens.initialize()
time.sleep(1)

 

# Try setting to Face Recognition mode
huskylens.set_face_recognition_mode()
time.sleep(1)

 

# Check the current mode after attempting to set Face Recognition
huskylens.check_current_mode()