Strings and FreeRTOS or Array of String or Char

Good day!

I am playing around with FreeRTOS on a (an) Uno and it works pretty well but there are some unique issues. The one big issue I am having is in using a string or a char array in an RTOS task.

In each task, which I have two of them, I have some blinking leds/relays to show me that the FreeRTOS tasks are working.

I have declared in my code:

#include <Arduino_FreeRTOS.h>
#include <LiquidCrystal_I2C.h>
#include <Ethernet.h>
#include <EthernetICMP.h>

// Setup IP addresses to ping
 IPAddress machineIP[] = {IPAddress(192,168,100,1), IPAddress(192,168,100,30), IPAddress(192,168,100,25), IPAddress(192,168,100,165)};
// Setup Machine Names
  char *MachineNames[] = {"Tucson Router", "Nebula VPN", "Tucson PiHole", "Tucson FreePBX"};

// define the two tasks
void PingMyServers( void *pvParameters );
void WebServerStartUp( void *pvParameters );

In my setup() I have;

void setup()
// Now set up two tasks to run independently.
  xTaskCreate(
    PingMyServers
    ,  "Blink3Relays"   // A name just for humans
    ,  128  // This stack size can be checked & adjusted by reading the Stack Highwater
    ,  NULL
    ,  2  // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
    ,  NULL );

  xTaskCreate(
    WebServerStartUp
    ,  "Blink1Relay"
    ,  128  // Stack size
    ,  NULL
    ,  1  // Priority
    ,  NULL );

My WebServerStartUp task works fine as there is not much to go wrong. However, my PingMyServers task will run as long as I do not try to use or print a member of my MachineNames[ ]. So...

void PingMyServers(void *pvParameters)  // This is a task. PingMyServers
{
  (void) pvParameters;

  for (;;)
  {
  // Blink smoe relays for fun and ensure the task is functioning
  digitalWrite(relay[1], HIGH);
  vTaskDelay( 250 / portTICK_PERIOD_MS );
  digitalWrite(relay[2], HIGH);
  vTaskDelay( 250 / portTICK_PERIOD_MS );
  digitalWrite(relay[3], HIGH);
  vTaskDelay( 250 / portTICK_PERIOD_MS );
  digitalWrite(relay[3], LOW);
  vTaskDelay( 250 / portTICK_PERIOD_MS );
  digitalWrite(relay[2], LOW);
  vTaskDelay( 250 / portTICK_PERIOD_MS );
  digitalWrite(relay[1], LOW);  
  vTaskDelay( 250 / portTICK_PERIOD_MS ); 

//*************** TRY THE PING STUFF **************************************

  lcd.setCursor(0,0);
  lcd.print("Pinging:");
  numFailures = 0;
  numSuccesses = 0;
   // Start the Pinging the machine  
  for (int z = 0; z <= 3; z++) 
  {
   ClearLine(1);
   ClearLine(2);
   ClearLine(3);
   lcd.setCursor(0,1);

   //  lcd.print(MachineNames[z]); // << THIS DOES NOT WORK. Ever!
 
   lcd.print("My Machine name");   // << THIS WORKS

   lcd.setCursor(0, 2);
   lcd.print(machineIP[z]);        // THIS WORKS EVERY TIME!!

   vTaskDelay( 1000 / portTICK_PERIOD_MS );
  
  }   //End of the Ping Stuff Loop

  }
}

Simply, lcd.print(MachineNames[z]); does not work and as a matter of fact it hoses up both tasks so nothing is running. Both tasks do not run.

AND... if I try to declare an actual string array,

String MachineNames[] = {"Tucson Router", "Nebula VPN", "Tucson PiHole", "Tucson FreePBX"};

And leave the tasks alone so that they worked as before neither task run.

In a nutshell, how do I get a string or char array to display when in a 'for' in my FreeRTOS task? Somehow I wouldn't think this would be rocket science but I am stumped.

Any help will be most appreciated.

John

You may be running out of memory. When you comment out that line of code the optimizer probably does not include the array.

What does the IDE say about the amount of storage space used after you build? The UNO only has 2048 bytes of RAM.

@ToddL1962

Thanks for the quick reply! The poor Uno could defineatley use some more memory!! In any event, here's what each shows after an Upload/Compile

Works. (With code REMed out):
Sketch uses 24528 bytes (76%) of program storage space. Maximum is 32256 bytes.
Global variables use 1071 bytes (52%) of dynamic memory, leaving 977 bytes for local variables. Maximum is 2048 bytes.

Does NOT Work. (With code intact):
Sketch uses 24590 bytes (76%) of program storage space. Maximum is 32256 bytes.
Global variables use 1117 bytes (54%) of dynamic memory, leaving 931 bytes for local variables. Maximum is 2048 bytes.

Memory shrinks quickly with the FreeRTOS library, but still there. I can remove and did remove other superfluous code prior to my post for testing and still no joy!

John

Your tasks are consuming memory too that isn't accounted for in what the compile time numbers reflect.

Does RTOS have an equivalent of the freememory function to tell you how much you have left at runtime?

You really can't see how much dynamic allocation is being done. It might be interesting to remove the WebServerStartup task and see if it works.

@ToddL1962

Nothing like asking others for ideas! Never thought about removing the other task and see if things work.

And they did!

@wildbill
I do not know yet if FreeRTOS has a FreeMem function or similar but I will research that.

I have a Mega around here as well and I will give that a shot as it has more memory... if my memory is correct. I will report back!

Thank-you!!

Hello

Show complete code or a small compilable example demonstrating the problem

Still a poor fit. Why are you trying to force FreeRTOS on a poor little AVR? Pick up an ESP32. They come with FreeRTOS pre-loaded and you'll be swimming in resources -- relatively speaking. Cheaper too.

@gfvalvo

Just don't have one lying around right now! Have a couple pi pico's, a couple each of Uno's, Megas and Nano's... a couple pi's 3 and 4, pi zero 2 W, pi zero W, but no ESP32!

I guess I had better get to ordering one!! Or two!

Thanks!!

John

@ToddL1962

Yes sir! Memory! Worked just fine on the Mega.

Need to buy an ESP32!

Thanks!

John