OLED display hectic behavior - interference with other parts of the code?

Disclaimer: I’m a total novice to Arduino so please forgive me if the question may seem trivial, I’m trying my best to learn :slight_smile:

I’m working on a small project where I have a fingerprint sensor, a servo and an OLED display. The goal is to be able to register a fingerprint and then use the fingerprint to move the servo, whilst the OLED display gives instruction / messages to the user.

I noticed a few days ago an issue whereby my OLED wouldn’t simply stop working if I had some Serial.println in my code. Without understanding the root cause, by trial and error I got to the conclusion that the issue was with that specific function, so I proceeded to remove it and everything went ok.

Then I noticed that the display stopped working also by adding extremely simple pieces of code that should not be related in ANY way to how the OLED works (at least to the best of my very limited knowledge).

The attached code (sorry, was to long to put it inline here) works as expected, each and every call to the oledPrint function yields the expected result on the OLED itself.

However, if I uncomment the code in the baseRegistration and/or masterRegistration functions (see code snippet below), the display starts to act up: some text is displayed, some other isn’t, some other again is displayed partially. I just can’t find a sensible explanation anywhere, and being used to work on much higher abstraction levels this is to me completely absurd :smiley:

boolean baseRegistration(){
  boolean check = false;
  int tempBaseCount = baseCount + 1;
//PART THAT CAUSES ISSUES - STARRT
  if(tempBaseCount > BASE_MAX){
    oledPrint("Too many users already registered");
    return true;
  }
//PART THAT CAUSES ISSUES - END
  oledPrint("Starting registration");
  while(check == false){

    oledPrint("Please put your finger on the reader");
    
  
    id = tempBaseCount;
    if (id == 0) {// ID #0 not allowed, try again!
       return;
    }

    if(getFingerprintEnroll(tempBaseCount, false)){  
      check = true;
    }
  }
  return check;
}

Even more oddly, if I remove the part above from those two functions and I had one more simple call to the fingerprint sensor in the loop function, the OLED just stops working altogether (and again, absolutely crazy for me :P).
See below the loop function with the addition of the line that breaks the OLED altogether:

void loop() {

  bool skip = false;
  oledPrint("Welcome to your fingerprint locker");
  //base registration case
  if(digitalRead(buttonRegisterPin) == ISPRESSED && skip == false){

    
    while(!baseRegistration());
    skip = true;
  }

  //master registration case
  if(digitalRead(buttonRegisterMasterPin) == ISPRESSED && skip == false){

    
    while(!masterRegistration());
    skip = true;
  }

  //base clear case
  if(digitalRead(buttonClearPin) == ISPRESSED && skip == false){
    clearRegistrations(false);
    //do stuff for base clear
    skip = true;
  }

  //master clear case
  if(digitalRead(buttonClearMasterPin) == ISPRESSED && skip == false){
   
    //do stuff for master clear
    skip = true;
  }

  int fingerprintID = getFingerprintIDez(); //THIS IS THE LINE
  delay(50);

}

I just don’t know how to proceed, if any of you would be so kind to help a novice out I’d be extremely grateful!
Thanks in advance to anyone who could point me in the right direction!!

For the sake of completeness, I’m using the adafruit libraries for the fingerprint sensor as well as the oled.

MASTER_REG_V2.ino (9.89 KB)

I start by getting rid of all the ‘String’ references. You are passing C strings (arrays of chars) to your oledprint() function, but you declare it as taking a ‘String’ object.

You should also enable all the warnings in the IDE and fix them throughout your code.

Thank you blh64, good point! I corrected it, however - as I expected - it didn't change the way the display behaves :frowning:

I can’t see your code, but if it contains a lot of literal strings like oledPrint("Too many users already registered") you should rethink, and get those strings into PROGMEM.

TheMemberFormerlyKnownAsAWOL:
I can't see your code, but if it contains a lot of literal strings like oledPrint("Too many users already registered") you should rethink, and get those strings into PROGMEM.

Thanks, I'll do it tonight as soon as I'm home.
Will that help with the issue at hand or is it more of a generic best practice?

One possibility is running out of RAM, which causes random and confusing symptoms - hence the precaution of moving read only data to flash / progmem.

MarkT:
One possibility is running out of RAM, which causes random and confusing symptoms - hence the precaution of moving read only data to flash / progmem.

Makes sense, something I didn't think about at all (I mean, usually RAM ain't an issue for me :D).
I'll try this out tonight and let you guys know if it worked!

Thanks a million!!

Using PROGMEM solved my issue, thanks a lot to everyone!

I'm still surprised as to how a few strings (char arrays, but ok) broke everything, while adding one more library (which I assume it contains more characters than the messages I'm using) didn't.
But that's for another day :smiley: