Use FreeRTOS?



  • Re: The "new" Arduino Pro IDE

    Currently I am running into a limitation of MySensors. Sleeping can be done on only two interrupts. I am using an Arduino ATMega 328.
    The bare Arduino platform doesn’t provide a solution.
    A real time OS could provide a neat solution and imho that would be the right place to implement such things as interrupts.
    The first OS I found was FreeRTOS, there is a library available in the Arduino IDE.
    It would be nice if MySensors had a mode to run on FreeRTOS.
    Is there anybody who already built this?
    I don’t have enough knowledge and time to develop this on my own. maybe someone can help me.



  • @cvdenzen said in Use FreeRTOS?:

    Re: The "new" Arduino Pro IDE

    Sleeping can be done on only two interrupts. I am using an Arduino ATMega 328.

    You don't define what your goal is but sleeping can be done on either of the interrupts or timer or both. If you simply need more interrupts then look at the diode matrix solution. With minicore you can then have 9 'interrupts' on digital pins and more using the analog pins if you so choose.



  • Even with the regular bootloader you can use the pin change interrupts to wake up the avr. Some special tricks are needed when waking up though but these are easy to implement.



  • The mysensor-library s building some kind of own operating system 😉 It hijacks a lot of things If you want to use them, you need to know how. For example save&read from EEPROM.
    Of course it is possible to handle everything.

    FreeRTOS would set the system on a standard base.
    Mysensor could "use" the functionality of FreeRTOS including different platforms and focus on the software for radio communication, security, etc..

    But FreeRTOS is also not very easy to understand and there are some tricky things to consider. In the end is it also complicated to understand everything as soon you need to go in detail. i am pretty sure that you would have had this or other questions if mysensors would set up on FreeRTOS.

    In the end a normal mysensor node just wants to send some collected data over the air and is not doing a lot of other things in parallel.
    So I dont know if it would make it more easy or more complicated.

    Maybe it is worse a thought if somebody starts to think about mysensor 3.0?



  • @skywatch I would like to see the "diode matrix solution", but I cannot find it. Is it in Arduino or in MySensors?



  • @jenspr said in Use FreeRTOS?:

    The mysensor-library s building some kind of own operating system 😉 It hijacks a lot of things If you want to use them, you need to know how. For example save&read from EEPROM.
    Of course it is possible to handle everything.

    FreeRTOS would set the system on a standard base.
    Mysensor could "use" the functionality of FreeRTOS including different platforms and focus on the software for radio communication, security, etc..

    But FreeRTOS is also not very easy to understand and there are some tricky things to consider. In the end is it also complicated to understand everything as soon you need to go in detail. i am pretty sure that you would have had this or other questions if mysensors would set up on FreeRTOS.

    In the end a normal mysensor node just wants to send some collected data over the air and is not doing a lot of other things in parallel.
    So I dont know if it would make it more easy or more complicated.

    Maybe it is worse a thought if somebody starts to think about mysensor 3.0?

    Yes, I totally agree with you. The "problem" is, that I am a big fan of real time solutions, it was the subject of my final project at school. Things won't be easier, mistakes are easily made in concurrent programming.
    I see these advantages of using a real time OS:

    • better hardware support (more interrupts)
    • nice features to support elegant real-time concurrent programming (queues, semaphores etc.)
      The disadvantages I see:
    • extra software, more complexity (download, documentation to read)
    • concurrent programming is error-prone

    I am going to spend a few hours trying FreeRTOS with MySensors for my application, it looks like there are not many people who have tried it.

    Carl



  • @cvdenzen Essentially you normally take a 'trigger' signal to an int and that's it. Fine.

    But what you can do is take a lot of signals and send each one to a different input AND use a doide from that input to the int pin. Then any signal can trigger an int and the first thing you do in your int routine is check the inputs to see which one triggered it.

    I think a RTOS would drain batteries farily quickly, wouldn't it?



  • @skywatch There should be no reason why a RTOS would drain batteries quickly, one could even expect the opposite. In a RTOS there is no need to loop, it can simply wait for any interrupt to arrive. That is theory. But I suspect FreeRTOS not doing a low-power sleep, and instead simply looping the cpu. There might be possibilities to do a low-power sleep (in the loop() method).
    Connecting diodes to other pins is not very simple in my situation. I have this easypirmultisensorbox (https://github.com/EasySensors/easyPIRmultisensorsBox2) and soldering will not be easy:-).
    The PIR sensor in this thing is connected to pin 7. In the MySensors sleep method only pins 2 and 3 can be used for interrupts.
    This Arduino forum post https://forum.arduino.cc/index.php?topic=704977.0 didn't give me much hope. It is bare Arduino that already is problematic with FreeRTOS, and I guess that MySensors will make things even more complicated.
    So maybe I will take a look at dirtier solutions, like writing my own sleep method. If I don't find a solution within a few months, I might even resort to one of the worst, dirtiest and appalling software mechanism ever: polling.


  • Hardware Contributor

    MySensors runs on ESP32 which is based on a modified FreeRTOS. So technically you can have MySensors and FreeRTOS at the same time right now, just not on an atmega.

    Introduction to RTOS Part 1 - What is a Real-Time Operating System (RTOS)? | Digi-Key Electronics – 11:34
    — DigiKey



  • I am using the Pinchange interrupts to wake up from sleeping.
    Maybe this helps?
    See code snippets below.

    #include <PinChangeInt.h>  //include PinChange lib from MySensors utilities
    

    in setup()

      attachPinChangeInterrupt(BotLeft_PIN, BotLeft_ISR, CHANGE);
    

    and in the ISR

    void BotLeft_ISR() {
    _wokeUpByInterrupt = 0xFE; // work-around to force MS lib to handle this interrupt
     // more code here
    }


  • Yeah, the pin change interrupt really gets you the benefit of the diode plan that was talked about, but without using the extra pin. You still have to check which pin has changed, if you have multiple pins enabled for the interrupt, but that's still the same level of work as checking all the pins under the diode plan.

    Saves all that extra hardware/soldering as well. You just need to hook up to the input as you normally would. Though with the board you're using, maybe things are already connected, and you just need to enable things and then check the input?

    It sounds like you're making this more complicated than it has to be. What you're asking for is already supported and is pretty easy to do. It's just part of the microcontroller and is straightforwardly part of Arduino, and therefore mysensors.



  • Yes, the pin change intgerrupt gives me what I want. The sleep call also wakes up on this interrupt, I thought it would only wake up in INT0 or INT1.

    So for now my experiments with FreeRTOS end.

    @electrik thanks for the hint!


Log in to reply
 

Suggested Topics

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts