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.