greiman / FreeRTOS-Arduino

FreeRTOS 8.2.3 Arduino Libraries
300 stars 122 forks source link

Serial.readString() returns empty String #10

Closed eziya closed 7 years ago

eziya commented 7 years ago

Hi,

I used Serial.readString() method to receive string message from string monitor. but it returns empty string.

#include "Arduino.h"
#include "FreeRTOS_AVR.h"

void setup()
{
    Serial.begin(9600);
    xTaskCreate(vTaskSerial,  NULL, configMINIMAL_STACK_SIZE, NULL, 2, NULL);
    vTaskStartScheduler();

    while(1);
}

void vTaskSerial(void *pvParameters) {

    while(1) {
        if(Serial.available() > 0) {
            Serial.println("Serial is available");
            String msg = Serial.readString();
            Serial.println(msg);
            Serial.println("Message printing ends");
        }

        vTaskDelay(100 / portTICK_PERIOD_MS);
    }
}

void loop() {

}
>>Send to COM3: "hello"<<
Serial is available

Message printing ends 
greiman commented 7 years ago

Strings use dynamic memory so probably won't work in a thread.

I think there are other ports of FreeRTOS to Arduino so you might try them.