Weird behaviour of Due - help needed

I am an experienced Arduino programmer, have successfully realised some large projects on Mega boards. Since 3 years I am playing with Due boards because I need more horsepower and memory for my Midi controller projects. However, I can't make the Due work and I am close to giving up. Here is the issue:

I have set up a Due with a 2x20 Oled Character Display W202-XLG just for making my first steps with Due. Running a super simple example sketch that looks like this:

#include <LiquidCrystal.h> //Searches library in standard library folder

// LiquidCrystal(rs, rw, enable, d4, d5, d6, d7)
LiquidCrystal lcd(26, 27, 28, 22, 23, 24, 25);

const int numRows = 2;
const int numCols = 20;

void setup() {
lcd.begin(numCols, numRows);
delay(200);
lcd.clear();
pinMode(53,INPUT_PULLUP);
}

void loop() {

for (int thisLetter = 'a'; thisLetter <= 'z'; thisLetter++) {
lcd.clear();

// loop over the rows:
for (int  thisRow = 0; thisRow < numRows; thisRow++) {

  // loop over the columns:
  for (int thisCol = 0; thisCol < numCols; thisCol++) {

    // set the cursor position:
    lcd.setCursor(thisCol, thisRow);
    lcd.write(thisLetter);
   
  if (digitalRead(53) == 0){
    delay(100);}
  else {
    delay(20);}
  }
}

}
}

The code writes letters into the display, starting with 'a' from left to right in row 1 and then row 2, then clearing the display and continuing with 'b' etc. . A push button connected to pin 53 changes the speed by introducing a longer delay after each lcd.write cmd.

Here is the problem:

  • After loading the sketch it will most often work. Sometimes it doesn't start at row 1 but rather at row 2 and then filling row 1.

  • After pressing 'reset' (either on the board or by gnding the reset conn.) the code runs but the display shows wrong characters, begins at the wrong column/row or both. LCD.clear doesn't seem to work, some characters stay visible.

  • Pressing 'reset' again will clear the display but in most cases then just change the pattern of the weird characters and or the start location.
  • However, sometimes when pressing 'reset', it actually returns to correct behaviour. It seems unpredictable.
  • When powering the due by dis- and reconnecting the USB cable (programming port) it will most always run correctly, sometimes it starts at the wrong row as right after upload of the sketch.

So it appears as if certain variables are not initialised correctly after a reset and sometime also after startup. Also the LCD.clear cmd sometimes doesn't work because once it is in its 'weird state' certain characters remain on the display and are not cleared while the code seems to run 'somehow'.
However, once it is running, it runs reliable, even for days.

LiquidCrystal version is 1.0.7.

Any ideas, hints? I have searched forums and web like crazy but I cant get around this. Where about roughly is the root cause for this behaviour?

I have also:

  • tried another Due board - same behaviour
  • fixed the '10k resistor missing over mosfet' issue - this has improved the recognition of the board from the IDE but not changed its behaviour in any regard
  • improved the hardware cabling for excluding any issues from that end etc. No changes at all.

Maybe this topic might help you out(from reply #35). It seems that the initialization process differs from an LCD to an OLED :

Bang! Solved! As suggested in the other thread the strange behaviour comes from wrong initialisation of the OLed. After LCD.begin (....) I have inserted

lcd.command(0x08); // Display OFF
lcd.command(0x06); // entry mode set increment cursor by 1 not shifting display
lcd.command(0x17); //Character mode and internel power on
lcd.command(0x01); //clear display
lcd.command(0x02); //return home
lcd.command(0x0c); //display on

and now it works!

I have also inserted some serial monitoring of all the variables in the code and this verifies, that the code actuially runs correct. All variables show expected values.

Many thanks! You have not only saved my day, I can now start a new Midi controller project based on Due. :clap: :+1: :+1:

Glad to see that it solve the problem for another one than me :wink:
I still don't know why the library doesn't do the right job, maybe some timming issues, but I didn't check anyway.
Have a nice day