There are two mode in micropython: REPL vs paste mode. I guess the uart of my ESP32 board has no flow control, so you can’t send all bytes at once, because it is too fast, so I sleep 100 ms for every 100 bytes.
REPL mode
You can’t just send your python code, you need to remind two things: the indent and the return of indent. See the below diagram, in line 26 should be one indent but you can’t have it, because the line 25 is indent-ed so all next lines are supposed no need to indent again. So you can see from line 26 to 32, there is no indent. Secondly, in line 34, you need \r to return from indent to no-indent
![](https://peter.quantr.hk/wp-content/uploads/2025/01/Screenshot-2025-01-28-at-8.52.27 PM.png)
Paste mode
In paste mode, you DON’T have to change anything to your code like the last section. But you need to send 0x5 to enter paste mode and send 0x4 to leave paste mode, after that, the program will run right after it. See line 61 and 72
![](https://peter.quantr.hk/wp-content/uploads/2025/01/image-1.png)