FreeRTOS on ARDUINO nano driving Multiple Christmas garlands LED controller
Animate multiple 24 VDC LED garlands with flashing and variable brightness (13 different parameters) with one Arduino Nano multi-tasking with FreeRTOS.
After my previous project with one Arduino controlling one LED garland, here, this project use multi-tasking with FreeRTOS on one Arduino (nano) to drive multiple garlands with asynchronous tasks using 13 different set of parameters. See Diagram file.
*** A version of this project for the ESP32 with FreeRTOS is here.
At the beginning I want to animate some LED strings garlands. So I began with one Arduino nano without multitasking, but duplicating all the stuff. After this first step, and discovering Elektor news about FreeRTOS on ESP32 I tried the experiment (see above link).
This test with this microcontroller was conclusive.
And I returned on Arduino nano with my ESP32 experience to program it with multitasking. After several tests and corrections., I ended up running 3 tasks with optimizations code (see diagram file).
So here, I use tasks of FreeRTOS to drive PWM ouputs. The code is written with IDE Arduino platform.
Each task select randomly 1 parameter set among the 13 and drive its garland with PWM output, and a MosFET module driving the LED garland. I use also a part of an Elektor newspaper article to improve driving MosFET gate with 3 transistors & resistors (see picture interface module).
Each garland is 24V= LEDs system.
At this stage, ARDUINO support three tasks with its limited ressources. So it drives 3 LED garlands.
The PWM Arduino nano outputs are D5, D6, D9 respectively on pins 8, 9, 12.
The basis is a 240V~ transformer to 24V ~ and a rectifier for =24V, multiple coloured LED strings 24V= garlands.
The components are as follow:
- 1 Arduino nano,
- 1 Arduino support for tests,
- 1 power supply module for the Arduino from 24V= (Internet far eastern shop),
- 3 MosFET modules for garland control (Internet far eastern shop),
- 3 interface drivers for the MosFET module driven by the Arduino PWM outputs,
- 1 printed circuit board with holes for mounting,
- several connectors for garlands & input power on the box,
- 1 plastic box to encapsulate the project,
- 3 x 24V= LED garlands,
- 1 transformer & rectifier 240V~/24V=.
For information, I found 24V LED garlands at Lumitronix web site, with transformer and rectifier.
I choose to program 13 different control light parameters in two sets which may be extended:
- one set to control ON/OFF light with different ON and OFF time;
- one set to control variable PWM light with different up and down time.
Each parameters set is selected randomly with an added library TrueRandom, because Random Arduino code is not clearly random as I tested.
And for PWM control, I choose 32 steps for ON and OFF variations in sine wave because eye light perception is not linear.
Each of the 3 tasks is independent and asynchronous, so light animation is superb.
Each task (FreeRTOS name) drive an ARDUINO PWM output.
The code listing is in zip file.
The task is defined one time and gets in the given parameter the PWM output number.
The setup creates the three tasks with each output in given parameter, and start the scheduler after.
Effectively, IDE Arduino don't start the scheduler, you have to start it in your code. But after that the code cannot reach the loop code.
So the Loop is not used..
See the result:
https://youtu.be/WGU4wzvqRX0
Have you any comment or remark ?
*** A version of this project for the ESP32 with FreeRTOS is here.
At the beginning I want to animate some LED strings garlands. So I began with one Arduino nano without multitasking, but duplicating all the stuff. After this first step, and discovering Elektor news about FreeRTOS on ESP32 I tried the experiment (see above link).
This test with this microcontroller was conclusive.
And I returned on Arduino nano with my ESP32 experience to program it with multitasking. After several tests and corrections., I ended up running 3 tasks with optimizations code (see diagram file).
So here, I use tasks of FreeRTOS to drive PWM ouputs. The code is written with IDE Arduino platform.
Each task select randomly 1 parameter set among the 13 and drive its garland with PWM output, and a MosFET module driving the LED garland. I use also a part of an Elektor newspaper article to improve driving MosFET gate with 3 transistors & resistors (see picture interface module).
Each garland is 24V= LEDs system.
At this stage, ARDUINO support three tasks with its limited ressources. So it drives 3 LED garlands.
The PWM Arduino nano outputs are D5, D6, D9 respectively on pins 8, 9, 12.
The basis is a 240V~ transformer to 24V ~ and a rectifier for =24V, multiple coloured LED strings 24V= garlands.
The components are as follow:
- 1 Arduino nano,
- 1 Arduino support for tests,
- 1 power supply module for the Arduino from 24V= (Internet far eastern shop),
- 3 MosFET modules for garland control (Internet far eastern shop),
- 3 interface drivers for the MosFET module driven by the Arduino PWM outputs,
- 1 printed circuit board with holes for mounting,
- several connectors for garlands & input power on the box,
- 1 plastic box to encapsulate the project,
- 3 x 24V= LED garlands,
- 1 transformer & rectifier 240V~/24V=.
For information, I found 24V LED garlands at Lumitronix web site, with transformer and rectifier.
I choose to program 13 different control light parameters in two sets which may be extended:
- one set to control ON/OFF light with different ON and OFF time;
- one set to control variable PWM light with different up and down time.
Each parameters set is selected randomly with an added library TrueRandom, because Random Arduino code is not clearly random as I tested.
And for PWM control, I choose 32 steps for ON and OFF variations in sine wave because eye light perception is not linear.
Each of the 3 tasks is independent and asynchronous, so light animation is superb.
Each task (FreeRTOS name) drive an ARDUINO PWM output.
The code listing is in zip file.
The task is defined one time and gets in the given parameter the PWM output number.
The setup creates the three tasks with each output in given parameter, and start the scheduler after.
Effectively, IDE Arduino don't start the scheduler, you have to start it in your code. But after that the code cannot reach the loop code.
So the Loop is not used..
See the result:
https://youtu.be/WGU4wzvqRX0
Have you any comment or remark ?
Discussion (0 commentaire(s))