BLYNK (serial USB) +FreeRTOS issue

hi. i have some problem with this code. i was combine FreeRTOS with blynk seial USB example but its does not work. it is the blynk support with FreeRTOS? how to fixed this code ? thanks

    #include <Arduino_FreeRTOS.h>
    #include <dht.h>
    #include <SoftwareSerial.h>
    SoftwareSerial DebugSerial(2, 3);
    #define BLYNK_PRINT DebugSerial
    #include <BlynkSimpleStream.h>
    char auth[] = "token";

   void HUMIDITY( void *pvParameters );
   void BLYNK( void *pvParameters );

  void setup()
  {
    Serial.begin(9600);
    while (!Serial) {
    ;
    }

  xTaskCreate(
    BLYNK
    ,  (const portCHAR *)"BLYNK"   
    ,  128 
    ,  NULL
    ,  1  
    ,  NULL );

 xTaskCreate(
  HUMIDITY
  ,  (const portCHAR *)"HUMIDITY"   
  ,  128 
  ,  NULL
  ,  2  
  ,  NULL );

  }

 void loop()
 {
 }
void BLYNK(void *pvParameters)
{
  (void) pvParameters;
  DebugSerial.begin(9600);
  Serial.begin(9600);
  Blynk.begin(auth, Serial);
  for(;;)
  {
    Blynk.run();
  }
}

 void HUMIDITY(void *pvParameters)
 {
    (void) pvParameters;
     Serial.begin(9600);
     pinMode(8, OUTPUT);
     dht DHT; 
     for(;;)
    {
     int maxtemp = 32;
     int readData = DHT.read22(A2); 
     float t = DHT.temperature; 
     float h = DHT.humidity;

    Serial.print("Temperature = ");
    Serial.print(t);
    Serial.print(" *C ");
    Serial.print("    Humidity = ");
    Serial.print(h);
    Serial.println(" % ");

    if(t > maxtemp){
    digitalWrite(8, HIGH);}
    else{
    digitalWrite(8, LOW);
    }
  delay(500); 
  }
}

We didn’t test it, but I’ll take a look.
First of all, you’re using Serial.print - but serial should be used only by blynk… use debugserial

1 Like

Did it help? Or should I take a look?
What is your hardware?

did not work… im using arduino mega.

I believe that your problem is with stack overflow in one of the tasks, or maybe your whole stack overflows. You should use debugger and check if any of the tasks is crashing