|
通过定义GROVE引脚可以方便的将图像通过串口发送至M5Stack,按照JPEG的格式组装字节数组直接发送即可
[mw_shl_code=python,true]import network, socket, time, sensor, image,lcd
from Maix import GPIO
from fpioa_manager import fm, board_info
from machine import UART
#M5StickV Camera Start
clock = time.clock()
lcd.init()
lcd.rotation(2)
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
#sensor.set_vflip(1)
sensor.run(1)
sensor.skip_frames(time = 2000)
#M5StickV GPIO_UART
fm.register(34, fm.fpioa.UART2_TX, force=True)
fm.register(35, fm.fpioa.UART2_RX, force=True)
uart_Port = UART(UART.UART2, 115200,8,0,0, timeout=1000, read_buf_len= 4096)
while True:
clock.tick()
img = sensor.snapshot()
lcd.display(img)
img_buf = img.compress(quality=70)
img_size1 = (img.size()& 0xFF0000)>>16
img_size2 = (img.size()& 0x00FF00)>>8
img_size3 = (img.size()& 0x0000FF)>>0
data_packet = bytearray([0xFF,0xD8,0xEA,0x01,img_size1,img_size2,img_size3,0x00,0x00,0x00])
uart_Port.write(data_packet)
uart_Port.write(img_buf)
time.sleep(1.0) #这里的时间不可省略,省略M5Stack画面不流畅
print("finish")[/mw_shl_code]
M5Stack使用PORTA接口接收,按照规则解析,每次10个字节
[mw_shl_code=arduino,true]#include <M5Stack.h>
HardwareSerial serial_ext(2);
typedef struct {
uint32_t length;
uint8_t *buf;
} jpeg_data_t;
jpeg_data_t jpeg_data;
static const int RX_BUF_SIZE = 20000;
static const uint8_t packet_begin[3] = { 0xFF, 0xD8, 0xEA };
void setup()
{
M5.begin();
jpeg_data.buf = (uint8_t *) malloc(sizeof(uint8_t) * RX_BUF_SIZE);
jpeg_data.length = 0;
if (jpeg_data.buf == NULL) {
Serial.println("malloc jpeg buffer 1 error");
}
serial_ext.begin(115200, SERIAL_8N1, 22, 21);
}
void loop()
{
M5.update();
if (serial_ext.available()) {
uint8_t rx_buffer[10];
int rx_size = serial_ext.readBytes(rx_buffer, 10);
if (rx_size == 10) { //packet receive of packet_begin
if ((rx_buffer[0] == packet_begin[0]) && (rx_buffer[1] == packet_begin[1]) && (rx_buffer[2] == packet_begin[2])) {
//image size receive of packet_begin
jpeg_data.length = (uint32_t)(rx_buffer[4] << 16) | (rx_buffer[5] << 8) | rx_buffer[6];
int rx_size = serial_ext.readBytes(jpeg_data.buf, jpeg_data.length);
//image processing,
M5.Lcd.drawJpg(jpeg_data.buf, rx_size);
//image processing end
}
}
}
}[/mw_shl_code]
|
|