Skip to content

Object tracking with NXT Cam V4 for LEGO Mindstorms #792

Description

@gara-3004

Hello,

I am trying to program an object tracking robot with lego mindstorms using the python language. However I am not able to communicate with the NXT cam.

#!/usr/bin/env pybricks-micropythonfrompybricks.hubsimportEV3Brickfrompybricks.ev3devicesimport (Motor, TouchSensor, ColorSensor,
InfraredSensor, UltrasonicSensor, GyroSensor)
frompybricks.parametersimportPort, Stop, Direction, Button, Colorfrompybricks.toolsimportwait, StopWatch, DataLogfrompybricks.roboticsimportDriveBasefrompybricks.media.ev3devimportSoundFile, ImageFile# This program requires LEGO EV3 MicroPython v2.0 or higher.# Click "Open user guide" on the EV3 extension tab for more information.# Create your objects here.ev3=EV3Brick()
# Write your program here.ev3.speaker.beep()
importev3dev2fromev3dev2importsensorfromev3dev2.sensorimportlegofromev3dev2.sensor.legoimportI2C# Set up the I2C port on the EV3 for communication with the NXTCam-v4i2c_port=ev3dev2.get_current_i2c_bus()
i2c_address=0x01# NXTCam-v4 I2C addressi2c_sensor=lego.I2C(i2c_port, i2c_address)
# Turn on the camerai2c_sensor.mode=lego.I2C.MODE_RAW# Set I2C mode to RAWi2c_sensor.write(0x01, 0x00) # Write 0x00 to register 0x01 to turn on the camera# Read data from the camerawhileTrue:
i2c_sensor.write(0x00, 0x00) # Write 0x00 to register 0x00 to trigger a new framedata=i2c_sensor.read(8, lego.I2C.REPEAT) # Read 8 bytes of data from the camera# Process the data as needed

I tried this code but it keeps bringing up the error : no module named 'ev3dev2'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions