the programme blocked when i started using dht22 sensor task

mouadmomo wrote on Wednesday, October 23, 2019:

hello
am developping the system using freeRTOS on arduino i have 4 tasks
the logo displayer task , the menu displayer task , the idle task and the sensing task
when i use the three first tasks everything works good when i use the forth taks which use the dht library the system block on the sensing part and stay do it infinitly
the my source code

void setup() {
  // Set up functio parameters 
   initialize();

   // cteating tasks for the operating system
    xTaskCreate(dispLogo,"disp_logo", 200, NULL, 3, &TaskHandle_logo);
    xTaskCreate(dispMenu,"disp_menu", 100, NULL, 2, &TaskHandle_menu);
    xTaskCreate(taskIdle,"taskIdle", 100, NULL, 0, NULL);
    xTaskCreate(sensingTask , "sensing", 50, NULL, 1, &TaskHandle_sensing);
   dht.begin();

}


void taskIdle(void* pvParameters) {
  while(1)
  { 
  Serial.println(F("idle state"));
  delay(50);
 //vTaskDelay(50/portTICK_PERIOD_MS);
  }
}

 void dispLogo(void* pvParameters)
{
  while(1)
  {
   // vTaskSuspend( TaskHandle_sensing );
    mfunc.paint_logo(myGLCD) ;
    Serial.println("the logo is displayed ");
    //vTaskSuspend( TaskHandle_menu );
    vTaskResume( TaskHandle_menu );
     Serial.println("the logo is deleted ");
    vTaskDelete(NULL);    
  }
}


 void dispMenu(void* pvParameters)
{

  while(1)
  { 
    vTaskDelay(3000/portTICK_PERIOD_MS); 
              display_menu();
        }

         Serial.println("the end of the menu function ");

    // evry second the process must start again to verify the dynamique display charachters 
     vTaskDelay(1000/portTICK_PERIOD_MS); 
     
  }
}


void sensingTask (void* pvParameters)
{

 // vTaskDelay(4000/portTICK_PERIOD_MS); 
 // int sensingBuffer ; 
 // temHumiQueue  = xQueueCreate (2,sizeof(sensingBuffer)) ;
  while(1)
  {
   Serial.println("sensing temperature and humedity  ");
   
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  int humidity = dht.readHumidity();

  // seinding data into the queue buffer 
  //xQueueSend( temHumiQueue , (void*) sensingBuffer,(TickType_t)0);
 // Read temperature as Celsius (the default)
 /* int temperature = dht.readTemperature();
   if (isnan(humidity) || isnan(temperature) ) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }*/
  int temperature = dht.readTemperature();
  
  // xQueueSend( temHumiQueue , (int*) temperature,(TickType_t)0);
  Serial.print("Humidity: ");Serial.print(humidity);Serial.print(" %\t");
  Serial.print("Temperature: ");Serial.print(temperature);Serial.print(" *C ");

  //vTaskResume( TaskHandle_menu );

   vTaskDelay(1000/portTICK_PERIOD_MS);
  }
}

void loop(){}

rtel wrote on Wednesday, October 23, 2019:

I am not familiar with Arduino or dht22, but some general comments:

  • Serial.println() is called from several tasks, is it thread safe?

  • The fourth task is calling vTaskDelay(), which will make it block, so
    I’m guessing when you say it runs the sensor task infinitely it is
    getting stuck in one of the other function calls so never reaching
    vTaskDelay() - is that the case? If so, which function is it getting
    stuck in? If you break on the debugger, what is the code doing?

  • Are any of the function calls doing anything that will conflict with
    the kernel’s use of the CPU? For example, disabling interrupts,
    changing the timer that FreeRTOS is using?

mouadmomo wrote on Thursday, October 24, 2019:

thanks for your answer

  • i use the serial.println function just for debuging
  • i commented the vTaskDelay() function i didn’t use it i used it in the end of the function just the get the temperature and humidity value each second
  • i didn’t use the timer neither interrupt i think the dht library use the timer when the calculation of temperature
    every think work well till i add
    int temperature = dht.readTemperature();
    or humidity = dht.readHumidity();
    when i add one of these two instruction the serial monitor block and nothing will work in the system

Did you fix this problem?
I have the same with dht11.