Serial connection between MPUs

Discussion in 'UDOO KEY' started by JMuller, Mar 5, 2023.

  1. JMuller

    JMuller UDOOer

    Joined:
    Feb 15, 2023
    Messages:
    5
    Likes Received:
    1
    I wanted to use standard serial communication to send a message from the ESP32
    to the 2040 to control the on-board LED.
    Several problems with UART ports and setup were resolved. I found that I cound not
    test the signals between the two devices since they are not exposed in hardware (
    IO 0 & 1 on the 2040 are not connected to the output pins like on the standard 2040 and
    on the ESP32 IO 19 & 22 connections are not provided).

    I also found the Udoo Key's MCU connections page incorrectly states "Keep in mind that RP GPIO0 is
    connected to ESP IO19 and, vice versa, GPIO1 is connected with IO22"
    .

    In reality the ESP32 IO 19 connects with the 2040 IO 1 and ESP 22 to IO 0. Standard TX to RX and
    RX to TX connections are used not as stated in the documentation.

    Here are the two programs that I wrote:
    ESP32 code:
    '''
    test UART connection between P2040 and
    and ESP32 for Udoo Key

    Send UART based command to RP2040 to flash its
    LED

    '''

    from machine import Pin, UART
    import time

    to2040 = 19
    from2040 = 22


    LEDy = Pin(33, Pin.OUT)
    LEDb = Pin(32, Pin.OUT)

    # NOTE you must use UART port 1, port 0 is REPL & 2 is external connector
    uart1 = UART(1, baudrate=9600, tx=to2040, rx=from2040)

    while 1:

    LEDy.value(1)
    uart1.write("1\n")
    time.sleep(.25)
    LEDy.value(0)
    uart1.write("0\n")
    time.sleep(.25)

    RP2040 code:
    '''
    test UART connection between P2040 and
    and ESP32 for Udoo Key

    Revieve command over UART to flash the RP2040
    internal LED

    '''

    from machine import Pin, UART
    import time

    LEDg = Pin(25, Pin.OUT)

    toESP32 = 0
    fromESP32 = 1

    # NOTE must use UART port 0, only that port connects with IO 0 & 1
    # also note the difference between the need to pass a Pin object vs
    # just the IO number
    uart0 = UART(0, baudrate=9600, tx=Pin(toESP32), rx=Pin(fromESP32))


    while 1:
    inp = uart0.readline()
    if inp != None:

    if inp == b'0':
    LEDg.value(0)
    elif inp == b'1':
    LEDg.value(1)
    else:
    print(inp)


    Instructions:
    Load Micropython on both devices. You may use Thony to load python on the rp2040 but for the ESP32
    download esp32-idf3-20210202-v1.14.bin from https://micropython.org/download/esp32/
    Use the estool.py to erase the 32's memory :
    esptool.py --chip esp32 --port COM9 erase_flash

    then flash Micropython to the ESP32:
    esptool.py --chip esp32 --port COM9 --baud 460800 write_flash -z 0x1000 esp32-idf3-20210202-v1.14.bin

    Verify you get the REPL on both MPUs (you may have to remove power before switching between MPUs.)

    Now load the first program on the ESP32 using Thony naming it main.py on that device.

    On the rp2040 use Thony to load the second program, then press the reset on the ESP32 to run the main.py code. The two LEDs should flash in Sync.
     
  2. Ramesh

    Ramesh New Member

    Joined:
    Wednesday
    Messages:
    1
    Likes Received:
    0

Share This Page