We've done quite a bit of experimentation with adding preemptive multitasking support to non-hard real time software running on MCUs at my current company. After a lot of head banging and dead ends, I've come to the conclusion personally that the embedded community could really use an implementation of the POSIX threading APIs or some meaningful subset thereof for various platforms. They're already standardized, well…
Threads are already supported by esp-idf on esp32 source: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/...
Introducing multitasking to Arduino
61–70 of 88 posts
Re: Introducing multitasking to Arduino
#62Nice, but pointless addition to an old processor. ESP32's are cheap and readily accessible and they come with FreeRTOS running already. If I absolutely need to multitask on a Mega328 Arduino, I use the protothreads library. But really, for anything heavy, I'll turn to an ESP32 or an STM32. Use the right tool for the job!
Yeah, the art students with miniscule coding experience who just want to get stuff done are probably going to be thrilled to work with FreeRTOS. The truth is, that Arduino always has put in a lot of work to do things that could already be done only to make them more accessible, easier to use and thus more widely available. If you think this is pointless you should consider this might say more about how far you have c…
That is a minuscule part of the Arduino audience. For the rest of us, FreeRTOS works fine.
Re: Introducing multitasking to Arduino
#63A couple years ago, I managed a summer/afterschool program that introduced thousands of kids (age 8-18) to the Arduino. When we would set up a software abstraction to simplify multitasking (something that came up often with more advanced students), we set up something like this: int time = 0; int max_period = 10000; void loop() { if (time % 100 == 0) { everyTenthSecond(); } if (time % 1000 == 0) { everySecond(); } //…
Re: Introducing multitasking to Arduino
#64A couple years ago, I managed a summer/afterschool program that introduced thousands of kids (age 8-18) to the Arduino. When we would set up a software abstraction to simplify multitasking (something that came up often with more advanced students), we set up something like this: int time = 0; int max_period = 10000; void loop() { if (time % 100 == 0) { everyTenthSecond(); } if (time % 1000 == 0) { everySecond(); } //…
I’ve made some fun projects with Espruino - where you can literally use setTimeout/setInterval and it will even sleep the uC until it hits the the timeout :)
Re: Introducing multitasking to Arduino
#65Earlier quoted context omitted.
> move up to a larger system I'll take this one step further and suggest that beginners not start with the AVR, but instead with a Blue/Black pill (STM32) or ESP32. Leave the AVR for the more advanced people who are trying to squeeze every penny out of a project (even there, in many cases STM32 will cost less!!!). I visit the arduino.cc forums at least once every day and the things that beginners want to do these day…
I agree- I think just about everybody should start with an ESP32 instead of an Arduino. I still use the Arduino API when programming the ESP32 (due to the large amount of compatible drivers) but I've also installed FreeRTOS and ported zork. I am embarassed to say I also got C++ STL working on an AVR with 8k of ram- enough to allocate a std::vector of length 2.
Re: Introducing multitasking to Arduino
#66A couple years ago, I managed a summer/afterschool program that introduced thousands of kids (age 8-18) to the Arduino. When we would set up a software abstraction to simplify multitasking (something that came up often with more advanced students), we set up something like this: int time = 0; int max_period = 10000; void loop() { if (time % 100 == 0) { everyTenthSecond(); } if (time % 1000 == 0) { everySecond(); } //…
Re: Introducing multitasking to Arduino
#67We've done quite a bit of experimentation with adding preemptive multitasking support to non-hard real time software running on MCUs at my current company. After a lot of head banging and dead ends, I've come to the conclusion personally that the embedded community could really use an implementation of the POSIX threading APIs or some meaningful subset thereof for various platforms. They're already standardized, well…
BSP support is a little lacking in some cases. The raspberry pi is currently crashing on a call to fflush(). No idea why.
I really wish more people knew about it. As a matter of fact, I'll post about it here.
Re: Introducing multitasking to Arduino
#68Earlier quoted context omitted.
I'm a casual embedded-electronics user at best, most of my projects haven't advanced much past turn a simple servo, light some LEDs, maybe read a sensor and POST to an endpoint. For these tasks, Arduino has been pretty good for me and removed a lot of the complexity. The `setup()` and `loop()` model makes a lot of intuitive sense. That being said, I've spent no small amount of time on `String` vs `char*` (as an inexp…
I think AVR is a good architecture to learn on, because the devices are far simpler than ARM or other more modern chips. The main concept to master as an embedded developer is operating a device by its registers. The common arduino device, ATMEGA328, has a total of 84 registers across all peripherals. A simple program to blink the LED is less than 10 lines total. The datasheet is tiny compared to most ARM devices, bu…
Re: Introducing multitasking to Arduino
#69I wonder if async Rust would be a good fit for this use case? It doesn't solve the accidental blocking problem (although async-std did experiment with blocking detection at one point), but you can get transparent support for multiple cores and a lot of thread safety.
Re: Introducing multitasking to Arduino
#70async/await does not result in bloated code that is hard to maintain and debug. It's a strange thing to say - async/await is now built in to most major programming languages - strange that Arduino would dismiss it so easily. They are correct in that async/await does not solve multicore utilisation, but it's the most important and easiest way to implement parallelism on a single core.
> The traditional way to do this is to write non-blocking code so that the loop() function can run as fast as possible, updating state variables and calling the millis() function to ensure proper timing
Indeed, that style of programming is nothing at all like async/await in, say, Javascript.