Camera doesn't react through serial port

Discussion related to "under the hood" OpenMV topics.
Houkouha
Posts: 9
Joined: Sun Mar 31, 2019 6:18 pm

Camera doesn't react through serial port

Postby Houkouha » Wed Apr 08, 2020 6:20 am

Hi. I've been working with the camera from linux and python3. Yesterday I couldn't make the camera return a picture through it's port to my computer. The error:

Code: Select all

File "main_bolts.py", line 42, in camera_capture
    frame = sp.read(size)
File "/home/filip/.local/lib/python3.6/site-packages/serial/serialposix.py", line 483, in read
    ready, _, _ = select.select([self.fd, self.pipe_abort_read_r], [], [], timeout.time_left())
Communication is done with:

Code: Select all

sp.write(b"snap")
sp.flush()
size = struct.unpack("<L", sp.read(4))[0]
frame = sp.read(size)
The camera script:

Code: Select all

import sensor, image, time, ustruct, pyb
from pyb import USB_VCP
usb = USB_VCP()
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
while(True):
    cmd = usb.recv(4, timeout=5000)
    img = sensor.snapshot().compress()
    if (cmd == b'snap'):
        usb.send(ustruct.pack("<L", img.size()))
        usb.send(img)
Connection established as:

Code: Select all

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.setDTR(True) # dsrdtr is ignored on Windows.
The script was left hanging on read from camera as it didn't return anything. I tried flashing the camera, but still couldn't make it work until it randomly started working again after ~10 tries. Today I boot up my computer and the camera won't work again. The tty port is right, checked trough both OPENMVIDE and terminal. Am I doing something wrong?

UPDATE: since then the camera is working again. I literally didn't do anything just ran the script every 30 mins to check.
User avatar
kwagyeman
Posts: 4271
Joined: Sun May 24, 2015 2:10 pm

Re: Camera doesn't react through serial port

Postby kwagyeman » Wed Apr 08, 2020 1:23 pm

Okay.

Um, we have a new RPC library for control over a UART coming soon. Dealing with these issues will be a thing of the past very soon. Expect a new IDE release with the new functionality within the month.
Nyamekye,

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 26 guests