Skip to content

Instantly share code, notes, and snippets.

@anoken
Last active February 11, 2022 13:51
Show Gist options
  • Select an option

  • Save anoken/8b0ce255e9aef9d1a7f4d46272cedcaa to your computer and use it in GitHub Desktop.

Select an option

Save anoken/8b0ce255e9aef9d1a7f4d46272cedcaa to your computer and use it in GitHub Desktop.

Revisions

  1. anoken revised this gist Jan 18, 2020. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions m5stickc_arduino.ino
    Original file line number Diff line number Diff line change
    @@ -34,6 +34,9 @@ void loop() {
    int rx_size = serial_ext.readBytes(jpeg_data.buf, jpeg_data.length);
    Serial.println(rx_size);

    //M5StickC is not this function (arduino m5stickc lib ver0.1.1)
    //you need add this
    //https://github.com/anoken/M5StickC/commit/34965325891bdcab97f2bb056d4838cdf75e1b8d
    M5.lcd.drawJpg(jpeg_data.buf, jpeg_data.length, 0, 20);
    }
    else {
  2. anoken revised this gist Jan 18, 2020. No changes.
  3. anoken revised this gist Jan 18, 2020. 2 changed files with 17 additions and 38 deletions.
    28 changes: 10 additions & 18 deletions M5Stack.ino → m5stickc_arduino.ino
    Original file line number Diff line number Diff line change
    @@ -1,50 +1,42 @@
    // Copyright (c) 2019 aNoken
    #include <M5StickC.h>

    #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 = 30000;
    static const int RX_BUF_SIZE = 3000;
    static const uint8_t packet_img[4] = { 0xFF, 0xF1, 0xF2, 0xA1};

    void setup() {
    M5.begin();
    M5.Lcd.setRotation(1);

    M5.Lcd.setRotation(2);
    M5.Axp.ScreenBreath(10);
    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, 17, 16);
    Serial.println("Initialize");
    serial_ext.begin(115200, SERIAL_8N1, 32, 33);
    }

    uint16_t rx_buffer2[10240];

    void loop() {
    M5.update();
    if ( M5.BtnA.wasPressed() ) {
    }
    if ( M5.BtnB.wasPressed() ) {
    }
    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_img[0]) && (rx_buffer[1] == packet_img[1]) && (rx_buffer[2] == packet_img[2]) && (rx_buffer[3] == packet_img[3])) {
    if (rx_size == 10) {
    if ((rx_buffer[0] == packet_img[0]) && (rx_buffer[1] == packet_img[1]) &&
    (rx_buffer[2] == packet_img[2]) && (rx_buffer[3] == packet_img[3])) {
    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);
    Serial.println(rx_size);
    M5.lcd.drawJpg(jpeg_data.buf, jpeg_data.length);

    M5.lcd.drawJpg(jpeg_data.buf, jpeg_data.length, 0, 20);
    }
    else {
    uint8_t rx_buffer[10];
    int rx_size = serial_ext.readBytes(rx_buffer, 1);
    }
    }
    27 changes: 7 additions & 20 deletions MaixPy_UnitV.py → maixpy_UnitV.py
    Original file line number Diff line number Diff line change
    @@ -56,37 +56,24 @@ def unitv_check():
    but_a = GPIO(GPIO.GPIO1, GPIO.IN, GPIO.PULL_UP)
    but_b = GPIO(GPIO.GPIO2, GPIO.IN, GPIO.PULL_UP)


    #UART Connection
    fm.register(35, fm.fpioa.UART2_TX, force=True)
    fm.register(34, fm.fpioa.UART2_RX, force=True)
    uart_Port = UART(UART.UART2, 115200,8,0,0, timeout=1000, read_buf_len= 4096)
    fm.register(35, fm.fpioa.UART1_TX, force=True)
    fm.register(34, fm.fpioa.UART1_RX, force=True)
    uart_Port = UART(UART.UART1, 115200,8,0,0, timeout=1000, read_buf_len= 4096)

    while(True):
    img1 = sensor.snapshot()
    img_buf=img1.copy()
    img_buf=img1.resize(160,160)
    img_buf.compress(quality=50)
    img_buf=img1.resize(80,80)
    img_buf.compress(quality=60)
    img_size1 = (img_buf.size()& 0xFF0000)>>16
    img_size2 = (img_buf.size()& 0x00FF00)>>8
    img_size3 = (img_buf.size()& 0x0000FF)>>0

    data_packet = bytearray([0xFF,0xF1,0xF2,0xA1,img_size1,img_size2,img_size3,0x00,0x00,0x00])

    uart_Port.write(data_packet)
    uart_Port.write(img_buf)
    print("",img_buf.size(),",",data_packet)

    if but_a.value() == 0 and but_a_pressed == 0:
    but_a_pressed=1
    print("but_a_pressed")

    if but_a.value() == 1 and but_a_pressed == 1:
    but_a_pressed=0
    #print("",img_buf.size(),",",data_packet)

    if but_b.value() == 0 and but_b_pressed == 0:
    but_b_pressed=1
    print("but_b_pressed",dist_thresh)

    if but_b.value() == 1 and but_b_pressed == 1:
    but_b_pressed=0

  4. anoken revised this gist Jan 18, 2020. 2 changed files with 54 additions and 0 deletions.
    54 changes: 54 additions & 0 deletions M5Stack.ino
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    // Copyright (c) 2019 aNoken

    #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 = 30000;
    static const uint8_t packet_img[4] = { 0xFF, 0xF1, 0xF2, 0xA1};

    void setup() {
    M5.begin();
    M5.Lcd.setRotation(1);

    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, 17, 16);
    Serial.println("Initialize");
    }

    uint16_t rx_buffer2[10240];

    void loop() {
    M5.update();
    if ( M5.BtnA.wasPressed() ) {
    }
    if ( M5.BtnB.wasPressed() ) {
    }
    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_img[0]) && (rx_buffer[1] == packet_img[1]) && (rx_buffer[2] == packet_img[2]) && (rx_buffer[3] == packet_img[3])) {
    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);
    Serial.println(rx_size);
    M5.lcd.drawJpg(jpeg_data.buf, jpeg_data.length);
    }
    else {
    uint8_t rx_buffer[10];
    int rx_size = serial_ext.readBytes(rx_buffer, 1);
    }
    }
    }
    vTaskDelay(10 / portTICK_RATE_MS);
    }

    File renamed without changes.
  5. anoken created this gist Jan 18, 2020.
    92 changes: 92 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,92 @@
    ## Copyright (c) 2019 aNoken

    import image, lcd, sensor,gc
    from fpioa_manager import fm,board_info
    import KPU as kpu
    from Maix import GPIO
    from pmu import axp192
    from machine import UART,I2C
    import ulab as np
    from modules import ws2812


    #M5StickV LCD Initialize
    def m5stickv_init(uniV_use):
    if uniV_use==0:
    lcd.init()
    lcd.rotation(2)
    sensor.reset()
    sensor.set_pixformat(sensor.RGB565)
    sensor.set_framesize(sensor.QVGA)
    sensor.set_windowing((224, 224))
    sensor.run(1)
    if uniV_use==0:
    pmu = axp192()
    pmu.setScreenBrightness(9)

    def unitv_check():
    uniV_use=0
    i2c = I2C(I2C.I2C0, freq=100000, scl=28, sda=29)
    devices = i2c.scan()
    if len(devices)==0:
    uniV_use=1
    return uniV_use


    print("Initialize")
    uniV_use=unitv_check()
    m5stickv_init(uniV_use)

    if uniV_use==1:
    class_ws2812 = ws2812(8,1)
    class_ws2812.set_led(0,(0,0,0))
    class_ws2812.display()

    print("M5 Button def")
    but_a_pressed = 0
    but_b_pressed = 0

    if uniV_use==0:
    fm.register(36, fm.fpioa.GPIO1)
    fm.register(37, fm.fpioa.GPIO2)
    else :
    fm.register(18, fm.fpioa.GPIO1)
    fm.register(19, fm.fpioa.GPIO2)

    but_a = GPIO(GPIO.GPIO1, GPIO.IN, GPIO.PULL_UP)
    but_b = GPIO(GPIO.GPIO2, GPIO.IN, GPIO.PULL_UP)


    #UART Connection
    fm.register(35, fm.fpioa.UART2_TX, force=True)
    fm.register(34, fm.fpioa.UART2_RX, force=True)
    uart_Port = UART(UART.UART2, 115200,8,0,0, timeout=1000, read_buf_len= 4096)

    while(True):
    img1 = sensor.snapshot()
    img_buf=img1.copy()
    img_buf=img1.resize(160,160)
    img_buf.compress(quality=50)
    img_size1 = (img_buf.size()& 0xFF0000)>>16
    img_size2 = (img_buf.size()& 0x00FF00)>>8
    img_size3 = (img_buf.size()& 0x0000FF)>>0

    data_packet = bytearray([0xFF,0xF1,0xF2,0xA1,img_size1,img_size2,img_size3,0x00,0x00,0x00])
    uart_Port.write(data_packet)
    uart_Port.write(img_buf)
    print("",img_buf.size(),",",data_packet)

    if but_a.value() == 0 and but_a_pressed == 0:
    but_a_pressed=1
    print("but_a_pressed")

    if but_a.value() == 1 and but_a_pressed == 1:
    but_a_pressed=0

    if but_b.value() == 0 and but_b_pressed == 0:
    but_b_pressed=1
    print("but_b_pressed",dist_thresh)

    if but_b.value() == 1 and but_b_pressed == 1:
    but_b_pressed=0