-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Object tracking with NXT Cam V4 for LEGO Mindstorms #792
Comments
Pybricks is not the same as ev3dev-lang-python. You can't use both at the same time. To use ev3dev-lang-python, change the shebang to |
from ev3dev2.sensor import INPUT_1, INPUT_2, INPUT_3, INPUT_4
from ev3dev2.sensor.lego import TouchSensor, ColorSensor, InfraredSensor, UltrasonicSensor, GyroSensor
from ev3dev2.motor import OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D, LargeMotor, MediumMotor
from ev3dev2.sound import Sound
from ev3dev2.display import Display
from time import sleep do you mean like this? |
Yes, that looks right. |
I gave it another try with your correction, now it shows ImportError: cannot import name 'I2C'. |
Where did you get the code? There is no |
My main problem is that I am struggling to set up a communication with NXT cam since there is only poor information on the internet. #!/usr/bin/env python3
from ev3dev2.sensor import INPUT_1, INPUT_2, INPUT_3, INPUT_4
from ev3dev2.motor import LargeMotor, OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D
from ev3dev2.port import LegoPort
from time import sleep
i= 1
from smbus import SMBus
bus = SMBus(4) # NXTCam-v5 plugged into input port 2, /dev/i2c-in2 -> i2c-4
address = 0x01
bus.write_byte_data(address, 0x41, 0x42) # set object tracking mode
num = bus.read_byte_data(address, 0x42) # get number of tracked objects
data = bus.read_i2c_block_data(address, 0x43 + i * 5, 5)
print("color: ", data[0])
print("x coordinate upper left corner: ", data[1])
print("y coordinate upper left corner: ", data[2])
print("x coordinate lower right corner: ", data[3])
print("x coordinate lower right corner: ", data[4]) But it shows up the following error:
|
To be able to use SMBus with an I2C sensor, you must set the mode of the port to "i2c-other" first. |
I am just trying to realize a simple program where for example a motor is being moved, when the teached object is detected by the camera. Just to check if the camera is even working. I didn't find any information do you maybe experimented with the camera? |
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.
I tried this code but it keeps bringing up the error : no module named 'ev3dev2'
The text was updated successfully, but these errors were encountered: