I want to communicate with OpenMV camera via USB. I was using OpenMV H7, and everything worked fine. I replaced the camera with the global shutter module, and updated the firmware. Everything works fine on the IDE, but I can not get
Since the example
usb_vcp.py did not work, I tried the simpler example code from this post to test the communication. I repost the code below:
main.py on OpenMV camera:
import ustruct from pyb import USB_VCP usb = USB_VCP() while(True): try: cmd = usb.recv(4, timeout=5000) if (cmd == b'snap'): usb.send(ustruct.pack("<L", 1234)) except: pass
The corresponding python code on the PC:
import sys, serial, struct port = '/dev/ttyACM0' sp = serial.Serial(port, baudrate=115200, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, xonxoff=False, rtscts=False, stopbits=serial.STOPBITS_ONE, timeout=None, dsrdtr=True) sp.write(b"snap") size = struct.unpack('<L', sp.read(4)) sp.close() print(size)
It works fine. I get
1234 as expected.
Once I changed the code to
import ustruct from pyb import USB_VCP import sensor usb = USB_VCP() sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.skip_frames(time=2000) while(True): try: cmd = usb.recv(4, timeout=5000) if (cmd == b'snap'): usb.send(ustruct.pack("<L", 1234)) except: pass
I can only get
1885433459, where I should get
1234 as the previous code.
I am not sure how I should debug this. It would be great if there is some guidance. I appreciate the help in advance.