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.
Thank you. This info helped me a lot. When I raised a support ticket, they were not aware of it. I will inform them to correct it or find a way to update the same in the github repository. https://github.com/UDOOboard/Key-Docs/blob/master/docs/02_Hardware_References/04_MCUs_connections.md
hello JMuller and all, I'm quite new to te rpi2040 world so I have used your rpi code to test the connection between esp32 and rpi, thank you very much. I would like to add a second serial transmission on USB side to show on PC screen that the LED was turned ON or OFF. I'm trying with print function but I can only write one Byte per transmission. I was not able to find a tutorial or a manual to understand this kind of serial transmission. could you please hepl me? Thank you. I'm using VSCode with espressif extention to build esp32 project in c/ c++ and Thonny to interface with rpi.
I was not able to get this code working on the RP2040 side as published without adding a delay, approximately 3- Msec, in the while 1 loop. I added a sync output on the esp32 and RP2 side to measure the time difference between the LEDs on eaxh side. It vairied quite a bit from 8 msec to 25 msec. I finally added "timout=500" to the uart instantiation. and solved all the problems. Code: syncPin = Pin(3, Pin.OUT) # 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),timeout=500) while True: inp = uart0.readline() #print(inp) if inp is not None: if inp == b'1\n': #LEDg.value(0) syncPin.value(1) LEDg.on() #print(" ONE1") elif inp == b'0\n': syncPin.value(0) LEDg.off() #print(" zero0") else: pass #time.sleep(0.03)