Tommaso Martorellasilvia11931
Published © GPL3+

Multithreading on Microcontrollers with Zerynth

In this tutorial, we'll see multithreading on microcontrollers in Python on Zerynth.

BeginnerFull instructions provided1 hour1,677
Multithreading on Microcontrollers with Zerynth

Things used in this project

Hardware components

SparkFun ESP32 Thing
SparkFun ESP32 Thing
×1

Software apps and online services

Zerynth Studio
Zerynth Studio

Story

Read more

Schematics

sparkfun

Sparkfun ESP32 Thing

Code

main.py

Python
################################################################################
# Multi-Thread Basics
#
# Created by Zerynth Team 2015 CC
# Authors: G. Baldi, D. Mazzei
################################################################################

import streams

# create a serial port with default parameters
streams.serial()

# Define a function to be used in the various threads.
# Parameters are passed to the function when the thread is created and then used in the thread loop.
# To be continuously executed by a thread a function requires an infinite loop,
# otherwise when the function terminates the thread is closed
     
def threadfn(number,delay):    
    
    while True:                    
        print("I am the thread",number)
        print("I run every:",delay,"msec")
        print()                # just add an empty line for console output readability 
        sleep(delay)

# create the various threads using the same function but passing different parameters        
thread(threadfn,1,500)
thread(threadfn,2,1000)
thread(threadfn,3,1300)
thread(threadfn,4,800)

Credits

Tommaso Martorella

Tommaso Martorella

8 projects • 4 followers
silvia11931

silvia11931

10 projects • 9 followers

Comments