uart request / response snapshot

Discussion related to "under the hood" OpenMV topics.
openmvdev
Posts: 4
Joined: Tue Jun 04, 2019 7:05 pm

uart request / response snapshot

Postby openmvdev » Tue Jun 04, 2019 7:28 pm

I am using an adafruit M4 express Cortex M4 core running at 120 MHz, 512 KB flash, 192 KB RAM

For now I want to use the m7 as a camera that can take a picture on demand from an arduino serial port.

Is it possible and do you know of any sample code for both arduino & openmv to

1. Request (from the arduino) the openmv to take a picture (This is cleaner in my case than using an external pin trigger)
2. Receive from the openmv a picture (binary data is fine, once the arduino receives it will be posted to a server)

Thanks!
User avatar
iabdalkader
Posts: 1143
Joined: Sun May 24, 2015 3:53 pm

Re: uart request / response snapshot

Postby iabdalkader » Tue Jun 04, 2019 7:49 pm

Yes you'll find so many examples for this if you search the forums:

search.php?keywords=arduino+uart+serial

search.php?keywords=arduino%2Buart&term ... mit=Search

They don't do exactly what you want to do, but you can put something together form the examples and then let me know if you need more help.
User avatar
kwagyeman
Posts: 3829
Joined: Sun May 24, 2015 2:10 pm

Re: uart request / response snapshot

Postby kwagyeman » Tue Jun 04, 2019 7:53 pm

Hi, I can't really give you all the code you need but I can point you to the right direction.

Code: Select all

import pyb, sensor, image
sensor.reset()
sensor.set_frame_size(sensor.QVGA)
sensor.set_pixformat(sensor.RGB565)
uart = pyb.UART(3, 115200, timeout_char=1000)
while true:
    if uart.any():
        if uart.read(1) == 'p':
            img = sensor.snapshot().compress(quality=80)
            uart.write(img.size())
            uart.write(img)
When the camera receives 'p' on the uart it will send the jpeg stream.

As for the Arduino size of things, the first 4 bytes are the image size followed by the jpeg data which you want to write to disk. The data is kinda going to come back to back... so, you need to be able to handle the burst speed.
Nyamekye,
openmvdev
Posts: 4
Joined: Tue Jun 04, 2019 7:05 pm

Re: uart request / response snapshot

Postby openmvdev » Tue Jun 04, 2019 11:28 pm

This is great. Thank you both for the fast replies!

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 5 guests