The purpose of this library is to allow connecting LEGO robots to the Huskylens. It uses MicroPython and should work on LEGO MINDSTORMS EV3, LEGO SPIKE Prime, and LEGO MINDSTORMS 51515 Robot Inventor.
- Create a new Python project
- Paste the script from Library/SPIKEInstaller.py
- Run it once and discard the project
- Create another new project
- Paste the code from Library/SPIKEBoilerplate.py
- Start coding
Alternatively, you can copy and paste the contents of Library/pyhuskylens.py above your script.
To connect the Huskylens to your hub use a breakout board or solder the included huskeylens header/wires to a spare Wedo2plug pin 5 and 6 (ID1/ID2 lines) via UART to HusleyLens pin 2 and 1 (Rx/Tx) Full How-To Blog Here
Further details on pinout and ID1/ID2 here. Details on the pinout of the HuskeyLens here (Pin1=Tx=Green Pin2=Rx=Blue)
Powering the Huskylens is done with a USB battery pack or LPF by wireing in a 3V3 buck converter. If you set the port to 100% PWM, M+ will be about 8V and M- will be 0V (GND). Warning that using LPF-Motor(M1/M2 lines) the Huskeylens firmware 0.5+ and SPIKE/Robot Inventor The Huskylens will randomly crash during use, unless you power it over USB (example, USB battery pack or a LPF/buck converter). Either supply extra power or downgrade to firmware0.4.7
from hub import button
from projects.mpy_robot_tools.pyhuskylens import HuskyLens, ALGORITHM_FACE_RECOGNITION
#hl = HuskyLens('A', pwm=100 ,debug=False)
hl = HuskyLens('A',debug=False)
print(hl.get_version()) # This returns '.': OK and no payload on firmware < 0.5.1 > may not work
# Show some text on screen
hl.clear_text()
hl.show_text("hello from SPIKE", position=(120,120))
print("Starting face recognition")
hl.set_alg(ALGORITHM_FACE_RECOGNITION)
while not button.right.is_pressed():
# Get x/y loc of a face
blocks = hl.get_blocks()
if len(blocks) > 0:
face_x = blocks[0].x
face_y = blocks[0].y
error_x = (face_x-155)
error_y = (face_y-120)
print('face found:', face_x,face_y)
- Make EV3 example
- Implement loading and saving learned models
- Implement saving screenshots and pictures