I am trying to set up an Arduino Nano ESP32 so that I can code in MicroPython. I successfully installed Arduino Lab for MicroPython and flashed the firmware onto the device, but when I try to run the sample code from the MicroPython Installation Guide, it fails, citing a syntax error. Curiously, it works fine when I run it through the REPL.
After spending a while trying to debug, I found something interesting. The following code yields the error "Traceback (most recent call last): File "<stdin>", line 11 SyntaxError: invalid syntax"
import time
while True:
print("1")
time.sleep(1)
print("2")
time.sleep(1)
print("3")
time.sleep(1)
print("4")
time.sleep(1)
However, if I get rid of the last two lines, it works fine. And once again, the full code works fine if I copy-paste into the REPL. What could be going wrong?
Edit: After spending some more time debugging, it looks like the failure is based on the number of characters in the script. Anything more than 128 characters causes it to fail.
-
do some basic debugging ... for example, what happens when you get rid of print("1") and print("2") ?jsotola– jsotola2025年08月12日 22:34:09 +00:00Commented Aug 12 at 22:34
-
if you have an answer, write it please as answer, not as an update to the postJuraj– Juraj ♦2025年08月22日 13:13:11 +00:00Commented Aug 22 at 13:13
2 Answers 2
Upload the file manually with mpremote or ampy Install mpremote:
pip install mpremote
Upload your script:
mpremote connect /dev/ttyUSB0 fs put yourscript.py
mpremote connect /dev/ttyUSB0 run yourscript.py
This bypasses the Arduino Lab size limit.
It turns out that there was an incompatibility between MacOS and version 1.26.0 of the Arduino Nano ESP32 firmware. I reverted to v1.25.0, and now everything works.