Search code examples
pythonmicrocontrollerpython-multithreadingesp32micropython

Problem when running Threads in MicroPython with ESP32


I have the following code. I want to run it on an ESP32. The MicroPython is already installed. The problem is that nothing happens. I get no errors but the testThread() method is not called at any time. I really don't know where the problem lies.

Thank you in advance for your answers.

Code:

import _thread
import time

def testThread():

  while True:
    print("Hello from thread")
    time.sleep(2)

_thread.start_new_thread(testThread, ())

Solution

  • Same problem with esp32 thread execution - no output from thread function invoking a print statement. Not only that when the thread exited it crashed the esp32.

    However, I fortunately had another esp32 and the threaded function worked as expected, output was printed to the repl.

    The problem seems to be the latest version of micropython which can be checked by executing uos.uname().

    The working version 1.12.0 while version 1.14.0 fails.

    The uname output:

    WORKING: (sysname='esp32', nodename='esp32', release='1.12.0', 
    version='v1.12-286-gc5cc64175 on 202
    0-03-25', machine='ESP32 module with ESP32')
    
    FAILED: (sysname='esp32', nodename='esp32', release='1.14.0', version='v1.14 
    on 2021-02-02', machi
    ne='ESP32 module with ESP32')