# Problem with USB VCP

**URL:** <https://forums.openmv.io/t/problem-with-usb-vcp/6276>\
**Category:** OpenMV Boards\
**Created:** [August 31, 2021, 9:43pm UTC](https://forums.openmv.io/t/problem-with-usb-vcp/6276 "2021-08-31T21:43:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tsangkai](https://avatars.discourse-cdn.com/v4/letter/t/0ea827/32.png) [@tsangkai](https://forums.openmv.io/u/tsangkai)\
**Post date:** [August 31, 2021, 9:43pm UTC](https://forums.openmv.io/t/problem-with-usb-vcp/6276/1 "2021-08-31T21:43:32Z")

</div>

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 `usb_vcp.py` working.

Since the example `usb_vcp.py` did not work, I tried the simpler example code from [this post](https://forums.openmv.io/t/having-trouble-with-usb-vcp/1138/18) to test the communication. I repost the code below:

The `main.py` on OpenMV camera:

```auto
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:

```auto
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))[0]
sp.close()
print(size)

```

It works fine. I get `1234` as expected.

Once I changed the code to

```auto
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.

---

<div class="post-metadata">

**Author:** ![iabdalkader](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/iabdalkader/32/1169_2.png) [@iabdalkader](https://forums.openmv.io/u/iabdalkader)\
**Post date:** [August 31, 2021, 9:49pm UTC](https://forums.openmv.io/t/problem-with-usb-vcp/6276/2 "2021-08-31T21:49:15Z")

</div>

> [@tsangkai](#):
>
> `sensor.set_pixformat(sensor.RGB565) `

Probably main.py throws an exception here because the GS doesn’t support this format.

---

<div class="post-metadata">

**Author:** ![tsangkai](https://avatars.discourse-cdn.com/v4/letter/t/0ea827/32.png) [@tsangkai](https://forums.openmv.io/u/tsangkai)\
**Post date:** [August 31, 2021, 11:50pm UTC](https://forums.openmv.io/t/problem-with-usb-vcp/6276/3 "2021-08-31T23:50:05Z")

</div>

Thanks for the timely reply! That solves my problem! Thank you so much!
