ESP32 Programming issue

Thread Starter

Thilanka Kodikara

Joined Sep 30, 2017
5
Hi
im trying to use Task creating in ESP32 to handle OLED display , so i put a one simple counter in one task and add oled display the text in other task. but the oled display not displaying the correct text just there some scroll text that cant identify even. the OLED display is I2C 128x64 display , what will be the reason of this.

Thanks
 

Irving

Joined Jan 30, 2016
3,884
Have you been able to write to the display directly, so confirming the display works?

Post your code (use 'insert code' on menu) and PDF wiring diagram here.
 

Thread Starter

Thilanka Kodikara

Joined Sep 30, 2017
5
Have you been able to write to the display directly, so confirming the display works?

Post your code (use 'insert code' on menu) and PDF wiring diagram here.
Hi
thanks for reply
yes i checked the display separately with basic loop , it worked perfectly ,
here is the test code

Mod: please use Code tags, listed in the 'Insert' menu.

C-like:
#include <Wire.h>

#include <Adafruit_GFX.h>

#include <Adafruit_SSD1306.h>


#define SCREEN_WIDTH 128  // OLED display width, in pixels

#define SCREEN_HEIGHT 64  // OLED display height, in pixels


TaskHandle_t Task1;

TaskHandle_t Task2;

// LED pins

const int led1 = 2;

const int led2 = 4;

#define OLED_RESET -1        // Reset pin # (or -1 if sharing Arduino reset pin)

#define SCREEN_ADDRESS 0x3C  ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define RESET_P 26


void setup() {

  Serial.begin(115200);

  //pinMode(led1, OUTPUT);

  // pinMode(led2, OUTPUT);

  if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {

    Serial.println(F("SSD1306 allocation failed"));

    for (;;)

      ;  // Don't proceed, loop forever

  }

  // Show initial display buffer contents on the screen --

  // the library initializes this with an Adafruit splash screen.

  display.display();

  delay(2000);  // Pause for 2 seconds

  // Clear the buffer

  display.clearDisplay();

// display.drawPixel(10, 10, SSD1306_WHITE);

  display.display();

  //create a task that will be executed in the Task1code() function, with priority 1 and executed on core 0

  xTaskCreatePinnedToCore(

    Task1code, /* Task function. */

    "Task1",   /* name of task. */

    10000,     /* Stack size of task */

    NULL,      /* parameter of the task */

    1,         /* priority of the task */

    &Task1,    /* Task handle to keep track of created task */

    0);        /* pin task to core 0 */

  delay(500);

  //create a task that will be executed in the Task2code() function, with priority 1 and executed on core 1

  xTaskCreatePinnedToCore(

    Task2code, /* Task function. */

    "Task2",   /* name of task. */

    10000,     /* Stack size of task */

    NULL,      /* parameter of the task */

    2,         /* priority of the task */

    &Task2,    /* Task handle to keep track of created task */

    1);        /* pin task to core 1 */

  delay(1000);

}

int i;

int j;

//Task1code: blinks an LED every 1000 ms

void Task1code(void* pvParameters) {

  Serial.print("Task1 running on core ");

  Serial.println(xPortGetCoreID());

  for (;;) {

    i++;

    display.clearDisplay();

    display.setTextSize(2);               // Normal 1:1 pixel scale

    display.setTextColor(SSD1306_WHITE);  // Draw white text

    display.setCursor(0, 0);

    display.print(i);

    //display.setCursor(50, 20);

    //display.print(j);

    display.display();

    vTaskDelay(1000/portTICK_PERIOD_MS);

    //delay(500);

    // digitalWrite(led1, HIGH);

    // delay(1000);

    // digitalWrite(led1, LOW);

    // delay(1000);

    //   Serial.println("Task1 running on core ");

  }

}

//Task2code: blinks an LED every 700 ms

void Task2code(void* pvParameters) {

  Serial.print("Task2 running on core ");

  Serial.println(xPortGetCoreID());

  for (;;) {

    j++;

    //display.clearDisplay();

    //display.setTextSize(2);               // Normal 1:1 pixel scale

    //display.setTextColor(SSD1306_WHITE);  // Draw white text

    //display.setCursor(50, 30);

    //display.print(j);

    //display.display();

    //delay(1000);

    // digitalWrite(led2, HIGH);

    // delay(700);

    // digitalWrite(led2, LOW);

    // delay(700);

    //  Serial.println("Task2 running on core ");

  }

}

void loop() {

// i++;

//  display.clearDisplay();

//     display.setTextSize(2);               // Normal 1:1 pixel scale

//     display.setTextColor(SSD1306_WHITE);  // Draw white text

//     display.setCursor(0, 0);

//     display.print(i);

//     //display.setCursor(50, 20);

//     //display.print(j);

//     display.display();

//     delay(500);


}
 
Last edited by a moderator:

Irving

Joined Jan 30, 2016
3,884
I wonder if the OLED library is thread-safe.

Experiment 1: What happens if you put the OLED update code in the loop, and increment i & j in the tasks..

Experiment 2: What happens if you put the OLED setup &. update code in one task and increment i & j in the loop and the other task.
 
Top