Using (#include <Arduino_FreeRTOS.h>) BREAKS the String Library/Function.

Right so… I was trying to learn how to use the String function, because I want to use it for receiving a full sentence or command from serial port communication.

So I searched, and quickly found this example:

void setup() {
  Serial.begin(9600);
  Serial.println("Enter your name.");
}

char rx_byte = 0;
String rx_str = "";

void loop() {
  if (Serial.available() > 0) 
  {    // is a character available?
    rx_byte = Serial.read();       // get the character
    
    if (rx_byte != '\n') 
    {
      // a character of the string was received
      rx_str += rx_byte;
    }
    else 
    {
      // end of string
      Serial.print("Welcome ");
      Serial.println(rx_str);
      rx_str = "";                // clear the string for reuse
      Serial.println("");
      Serial.println("Enter your name.");
    }
  } // end: if (Serial.available() > 0)
}

See Code Output Video <<<

I had uploaded it on my Arduino Uno, and it works correctly as per the video.

This is all fine and dandy…
However as for my current graduation project, I need to use the “#include <Arduino_FreeRTOS.h>” library in order to use its functions for other matters.
I need to use the Real Time Operating System functions.

So, I had tried implement what was explained in the code and video to my code, and ran into a few illogical problems.
Later on I traced down the source of the problem, until I realized that SIMPLY INCLUDING the “<Arduino_FreeRTOS.h>” library, BREAKS the String library… YES, BREAKS IT!

Here’s why I think It breaks the String library…
If I try initialize a string value INSIDE of void loop or using a task (A function from the FreeRTOS library) No matter what I do, the value that I put in the string is not being read, or is not being put into the string’s value.

Moreover, When trying to apply what the video is trying to do, I either get ONE letter, or NOTHING at all.

I have also attempted to use delays after and before assigning a value to a string, in the sense that “Maaaybe I need to wait for a while for the value to be able to get a chance to be assigned to the targeted string”, even as ridiculous as that sounds, it didn’t work.

When I have attempted to manipulate and change and initialize a String value within the void setup, it works fine… However, this would be a ONE time use, but I want to be able to manipulate any string I want during the execution of my program… So still, it’s a big problem.

The reason I also want to use strings, even if I were to use a char array as an alternative, is that I would still want to compare a prior constant value to the received message, because depending on it a command or a function will fire in the Arduino.
If I were to use the char array, I’d have to have to get into the mindset of having to access every single character in the array, and comparing it with every single character of a constant char array value, to check If they match or not…
Which is just annoying to think about, knowing there SHOULD be the easier solution, which is following the video, and using Strings.

I’ll have to be forced to use the char array until I get a reply, I kinda need this to be answered within a day or so…
So ya, This could probably save someone from a headache in the future.

PS: Using “char” works fine, that’s why I have mentioned that I’ll use “char array”.
PS2: Here’s my attempt at manipulating a String both inside void setup (which works) and void loop (which doesn’t work)

#include <Arduino_FreeRTOS.h>

String lol = "AAA";
void setup() {
  Serial.begin(9600);
  Serial.println("Enter your name.");
  Serial.println(lol);
  String lel = " LOOOOOOL ";
  Serial.println(lel);
  lel = "LAAAAL";
  Serial.println(lel);
    lol += "A";
  Serial.println(lol);
}

char rx_byte = 0;
String rx_str = "";

void loop() {
  lol += "A";
  Serial.println(lol);
  if (Serial.available() > 0) 
  {    // is a character available?
    rx_byte = Serial.read();       // get the character
    
    if (rx_byte != '\n') 
    {
      // a character of the string was received
      rx_str += rx_byte;
    }
    else 
    {
      // end of string
      Serial.print("Welcome ");
      Serial.println(rx_str);
      rx_str = "";                // clear the string for reuse
      Serial.println("");
      Serial.println("Enter your name.");
    }
  } // end: if (Serial.available() > 0)
}

I was trying to learn how to use the String function, because I want to use it for receiving a full sentence or command from serial port communication.

Stop right there. Do not pass GO ! Do not use the String class when you could just as well use zero terminated arrays of chars (aka C style strings)

See Serial input basics - updated

Exactly which features of the RTOS do you need to use ?
Which Arduino board are you using ?

UKHeliBob:
Stop right there. Do not pass GO ! Do not use the String class when you could just as well use zero terminated arrays of chars (aka C style strings)

See Serial input basics - updated

Exactly which features of the RTOS do you need to use ?
Which Arduino board are you using ?

I'm using Arduino Uno
And I'll be using Semaphores, Multiple task with different priorities to be created, to make a system that will allow me to run them whenever they should.
I'll also be using the Queue function.

My project needs me to integrate my Arduino code with Labview programming...
Meaning, there will be code in Labview, that will send serial communication data (Arduino Rx) to my Arduino.
And for Arduino to send serial communication data (Arduino Tx) to Labview.

2010wolf:
I'll have to be forced to use the char array until I get a reply, I kinda need this to be answered within a day or so...
So ya, This could probably save someone from a headache in the future.

Anyhow, as I have previously mentioned, I have already made it possible for my Arduino to read a full line using char arrays.
So I guess my need for using Strings in Arduino is dependent on learning why are you freaking out about me wanting to use Strings.... are they bad :o?

I'll happily use char arrays instead, if it's somehow possible that Strings may ruin my project, or prove to be a major headache.

I'll check out the link you sent.
Until then, thanks for the help! :slight_smile:

I'm using Arduino Uno
And I'll be using Semaphores, Multiple task with different priorities to be created, to make a system that will allow me to run them whenever they should.
I'll also be using the Queue function.

That sounds like an awful lot to expect of a Uno. Are you sure that you cannot do what you want without using RTOS ?

As to Strings. Yes, they are generally regarded as a bad thing in the small memory footprint of an Arduino such as the Uno, particularly when the RTOS will be taking up much of it

UKHeliBob:
That sounds like an awful lot to expect of a Uno. Are you sure that you cannot do what you want without using RTOS ?

As to Strings. Yes, they are generally regarded as a bad thing in the small memory footprint of an Arduino such as the Uno, particularly when the RTOS will be taking up much of it

Well, Do you perhaps think i’d be better to use Arduino Omega?
Also, Yeah I’v realized that my Arduino crashes sometimes when there’s “Too much input” received through the Rx pin, or so it seems to be that way… Thing is, that’s what I’ll be able to have during these times where I am.

Also Also, Me and My graduation project team was told to get the Arduino Uno, and that I’d be fine if we use it.
If I had known any better, we would have saved ourselfs the headache and bought the Omega or something a tad more decent than Uno.

Ah alright, that makes sense.
I’ll continue to use array chars then!
Also I have checked just the general idea of the link that you sent, and I can tell it will guide me quite well into using char arrays more easily… so thanks a lot again for your help! <3

Do you perhaps think i'd be better to use Arduino Omega?

I presume that you mean an Arduino Mega. It certainly has more memory but I am still not convinced that you need to use RTOS

More details of what you are trying to do please

UKHeliBob:
I presume that you mean an Arduino Mega. It certainly has more memory but I am still not convinced that you need to use RTOS

More details of what you are trying to do please

Yes, I meant Mega :b

Well for the details… long story short I’d say we were told to use these tools for our graduation project, so really we don’t know any better of what to use or what the heck we’re doing.
We just know that we need to use Arduino, including the FreeRTOS Library, with Labview, using RS232 as the middle man between Arduino and Labview as the Serial Communicator, It is a Requirement.
(Why we need RS232? Because we also want to see the state of the satellite using the Arduino’s Serial Monitor, and we can’t do that if both Arduino IDE and Labview want to view the same PORT at the same time, only ONE can access at a time.)

As for the long story…
We’re trying to make/program the “On-Board Computer” of a Cube-Satellite into the Arduino.
Meanwhile, Labview will be representing the Ground Station.

However, there is a strict requirement that we MUST use FreeRTOS while we program inside the Arduino, the reason being is that the Cube-Satellite needs to operate at a Real-Time speed, or as close to it as possible.
Therefore, we are told to use the FreeRTOS Library, to achieve this.
(Oh and If it happens that it’s still slow on the Arduino, It won’t matter as long as the concept is there, meaning if there is a better Arduino it’ll run faster, that won’t matter for us in order to graduate, what matters is that we DO IT, and HOW WE DID IT.)

For our team to be able to graduate from this project, we need to AT THE VERY LEAST, be able to simulate a the Cube-Satellite being first powered on, all systems are checked and fixed if there are any problems, then proceed to send a “Beacon” to the Ground Station.

The “Beacon” will be containing Information about the Cube-Satellite’s hardware similar to:
Number Of batteries installed, Each battery charge percentage, subsystems conditions, and GPS location of the Cube-Satellite.
Basically, Sending Telemetry.

And finally, being able to send data to the Ground Station, perhaps an image of like 10x10 dimensions or something.
And receiving “Imaging Mission Plan” command from the Ground Station.


Isn’t this too much?

All of this seems too much, however everything that may seem complicated will simply be replaced by a temporary Imaginary value.

What does this mean? For example…
As for the batteries charge percentage, we won’t be really using any batteries, it’ll simply be an integer variable that is programmed to not go over 100% or under 0%, Perhaps every time a function of the Cube-Satellite is triggered a small or big (Pre-Defined) percentage of the battery will be subtracted.

Same goes for the subsystems conditions, they can simply be a Boolean variable that is checked if it’s true or false. (True = Healthy, False = Corrupted/Non-functional)

As for the GPS, it will be simply be another Imaginary two integer numbers, altitude and latitude.
Both values will periodically be updated every few seconds/ minutes or so.
The Updating process will fire a void function that will take both ints and increment or decrements them based on their (Pre-Defined) vector of movement in space.
However, It seems to be a requirement that for the GPS data to be sent, it has its own format of how it’ll be sent, and we haven’t really dug into learning about that part yet.

If there’s anything else in our system, we’ll make sure to place temporary/Imaginary values in their place.
When we want to know what are the accurate real life values that are seen in Cube-Satellites, we’ll simply ask the professors that gave us this graduation project to work on, from their experience.


How we’ll use FreeRTOS?

We haven’t started with programming the Cube-Satellite On-Board computer yet…
However we assume we’ll have perhaps 3 tasks in total, maybe 5 max or so.

We’ll have a task for Receiving data.
Another task for Processing data.
And lastly, a task for Sending data.

OR

A task that will follow the normal cases or decision cases execution, that will switch the Cube-Satellite to one of the 6 modes we’re working with. (Initialization, Detumbling, Safe, Standby, Imaging, Communication)
Some modes may be able to receive data from the Ground Station, or attempt to send data.

Another task for data processing, and Imaginary values update.
and one last task for the Safe Mode.

That’s the general Idea we have, we didn’t work on anything yet, However we’ll be starting in the coming days.


Since you asked for more details, I had to explain everything :b
so… yea… sorry if this was too much.
Also, sorry for the late responses, I’v been having a rough day, can’t sleep at all.

PS: All the decisions and processes that our team does are guided by our superiors (Professors).

"(Why we need RS232? Because we also want to see the state of the satellite using the Arduino's Serial Monitor, and we can't do that if both Arduino IDE and Labview want to view the same PORT at the same time, only ONE can access at a time.)"

Mega has 4 hardware serial ports: Serial (connects to PC via USB), and Serial1, Serial2, Serial3, all with 0 to 5V signals.
Any of those would be appropriate to connect to an RS232 module to talk to RS232 devices.

CrossRoads:
"(Why we need RS232? Because we also want to see the state of the satellite using the Arduino's Serial Monitor, and we can't do that if both Arduino IDE and Labview want to view the same PORT at the same time, only ONE can access at a time.)"

Mega has 4 hardware serial ports: Serial (connects to PC via USB), and Serial1, Serial2, Serial3, all with 0 to 5V signals.
Any of those would be appropriate to connect to an RS232 module to talk to RS232 devices.

I wish we had known this earlier.... I really do...
This would have saved us money, time, and a big stinging headache.

I have to say this was not mentioned to us by our supervisors, nor the fact that we needed the RS232.
If we had bought the Mega from before, we wouldn't have needed to get TWO Arduino Uno, and the RS232, and their cables to be connected to the computer...
(I realize that now you'll think why we bought the RS232, even though we have a second Arduino... well... I happen to have left it in my apartment near Uni, I'm currently in another city with my parents, I had planned to take it, but then the pandemic spread to here, and I can't travel to my apartment that has this second Arduino... so I guess we're pretty damn unlucky too.)

Part of the time wasted was because of the information that were provided to us pretty late, a total of 2.5 weeks of delay.

I just hope that in the end they don't put us in a faulty position, as if we're the ones that are lazy or making excuses...
Thanks for your help btw! :slight_smile: