Arduino and sparkfun LCD 2X16 random giberrish

I have built a stepper motor control using arduino etherten, gecko g251 stepper driver, an lcd screen to indicate movement of the stepper, a 12v power supply for the arduino and a 5v power supply for the lcd.
I am using a separate power supply because the stepper was messing up the lcd when it was plugged in the arduino 5v.
Now I am having random giberrish on the lcd screen, it worked for 2 months before messing up the lcd, i think i am on the right track but would like opinion. On power down, the 12v power supply to the arduino shuts down faster than the 5v to the lcd, so the lcd stays on and i believe it picks up random data from the powered down arduino...
Could this mess up the configuration of the lcd on the next startup?

This system needs to be 100% reliable, so i want to make it right. Any other thoughts about this type of problem is welcome.
I'll attach the code tomorrow morning.
Thanks for your help.

Are all the grounds tied together, even to the arduino?

Yes all ground are to the enclosure (metal)

The LCD can run off the arduino, it doesn't really need its own supply. By any chance could you post a picture of your setup? You may just have a loose wire, or possibly some noise.

Could you also post your full code?

gibberish as in.... weird symbols, but still characters... or like random pixelations? if one power supply is on longer than the other at shut down, and they are connected by a common ground, maybe something is sucking power through the ground between the two supplies? perhaps diodes and/or like a small value capacitor could help.

i think the 16x2 displays have two internal registers/buffers. one for the data, and one for instructions. maybe some code to clear these registers could fix your issue

for the power to the LCD module, do you have a current limiting resistor or is it plugged straight in? directly connected is fine for brief debugging purposes perhaps, but having it directly connected for any length of time could make some of the chips burn up. does it produce any heat while plugged in?

forgot to say that i have gotten symbol/gibberish characters when i had the data lines connected backwards (had soldered wires to 4 pin headers and i put it in backwards, or put it on the first 4 data pins rather than the last 4)

You will have a better chance of getting reliable help from knowledgeable sources if you provide more information. This information would include circuit diagrams, photographs of your interconnections, copies of the program code that you are using, and photographs of the display resulting from that program code.

Don

When you post the code, also provide some clarification on your symptoms.

Could this mess up the configuration of the lcd on the next startup?

Are you saying that the LCD/stepper combo works properly except that after power down you get gibberish? And, if that's true, does the gibberish gradually become lucid until another power down? If both of these are true, you might concentrate on how you declare the lcd in SETUP and how you initialize it.

Maybe I did not explain the problem as precisely as I should have. I had the boot splash, and then when the code was beginning, it was only rubbish. What I did so far, I included a 5 seconds delay at the beginning of the code in order not to send command to the LCD before it is ready, which i believe could have caused the problem, before it was 500 millis and I reset the LCD to 9600 baud. Maybe the aging of the LCD power supply increased the its boot time?Now it is working fine, even though i have gibberish on shut down, because the power supply of the LCD is still supplying it for 3 seconds or so after the arduino has shut down, when i power it again, the boot splash is there, as well as the proper display.What I don’t want is to happen again, after 2 months or so…I know the LCD can be run through arduino 5v, but when I tried it before, i had rubbish on the LCD when i was activating the servo. I guess noise or something. That is why i am using a separate power supply. I forgot to mention i am using a 24v power supply for the stepper motor which is a nema 24 382 oz inch. By "could this mess up the configuration of the lcd on the next startup?" i mean, could there be a chance that on shutdown, the gibberish characters be the one to change the baud rate for example? I have not written any circuit diagram though. See a little resume of the connections though. Arduino has its own power supply Arduino ground hooked to chassis ground. Gecko G251 has its own power supply LCD has its own power supply. All grounds bolted to the chassis. (power supply + arduino + LCD). Motor cable shield grounded.See attached picture of the setup as well as the gibberish i get on shutdown.
I do not run a current limiting resistor, did not know about that... The LCD never comes hot though... I've got some 0.5W 1K5 1% would that do? I am using a serial LCD.



See code below. Be kind I am far from being an expert!

#include <Stepper.h>
#include <NewSoftSerial.h>
#include <SerLCD.h>
NewSoftSerial NSS(0,12); // NewSoftSerial Object on pin 12
SerLCD theLCD(NSS); // SerLCD object using that NSS

const int mtstep = 2; 
const int mtdir = 3;
const int enmot = 4;
const int upsl = 5;
const int dwsl = 6;
const int upfs = 7;
const int rpos = 9;
const int uplm = 10;
const int dwlm = 8;
float pos = 0;
long tmr = 0;
int dly = 0;
int lcdon = 0;
unsigned long msecbegin; 
unsigned long msecend;
unsigned long mtime; 
float posref;
float posend; 
float posbegin; 
float posdif; 
float posmm;
int msectime; 
long p = 0; 
float mmsec; 

void setup ()
{

   // Remember to start the NewSoftSerial port before doing things with the SerLCD
  delay (5000);
  NSS.begin(9600);   // This will attempt to initialize the display to blank with the backlight on 
  delay (500);
  theLCD.begin();
  delay (50); 
  theLCD.setPosition(1,2);
  delay (50); 
  theLCD.print("Linear slide"); 
  delay (50); 
  theLCD.setPosition(2,2); 
  delay (50); 
  theLCD.print("Test"); 
  delay (2000); 
  
  theLCD.clear();   
  pinMode (mtstep, OUTPUT); // Pin 2 motor steps
  pinMode (mtdir, OUTPUT); // Pin 3 motor direction
  pinMode (enmot, OUTPUT); // Pin 4 enable-disable motor
  pinMode (upsl, INPUT); // Pin 5 button up slow 
  pinMode (dwsl, INPUT); // Pin 6 button down slow direction for driver is HIGH
  pinMode (upfs, INPUT); // Pin 7 button up fast direction for driver is LOW
  pinMode (rpos, INPUT); // Pin 9 button reset position on the lcd
  pinMode (uplm, INPUT); // Pin 8 limit switch up
  pinMode (dwlm, INPUT); // Pin 10 limit switch down
  digitalWrite (upsl, HIGH); // pullup pin 5 
  digitalWrite (dwsl, HIGH); // pullup pin 6
  digitalWrite (upfs, HIGH); // pullup pin 7
  digitalWrite (rpos, HIGH);// pullup pin 9
  digitalWrite (uplm, HIGH);// pullup pin 10
  digitalWrite (dwlm, HIGH);// pullup pin 8
  
  msectime = 0; 
  posbegin = 12; 
}

// Prepare to take some steps

  void loop ()
{
  digitalWrite (enmot, LOW); // Turn off the motor to keep it from getting overheated or to allow manual motion
  int upslread = digitalRead (upsl); // read and attribute value to upslread 
  int dwslread = digitalRead (dwsl); // read and attribute value to upslread 
  int upfsread = digitalRead (upfs); // read and attribute value to upfsread
  int rposread = digitalRead (rpos); // read and attribute value to rposread
  int uplmread = digitalRead (uplm); // read and attribute value to uplmread
  int dwlmread = digitalRead (dwlm); // read and attribute value to dwlmread
 
tmr = tmr++; 
lcdon = (tmr/200);

if (upslread == HIGH)  
    {
      if (dwslread == HIGH)
      {
        if (upfsread == HIGH) 
         {           
          if (lcdon > 1)
            {
             p = 0; // reset posbegin
             posend = pos; // the final position is the actual position pos
             posdif = ((posend-posbegin)*1000); // the difference between now and where it was before.
             posdif = (((posdif*0.025))/10);  
             theLCD.setBacklight(157);
             theLCD.clear();
             theLCD.setPosition(1,0); 
             posmm = (((pos*0.025))/10); 
             mtime = ((msecend - msecbegin));
             theLCD.print(posmm);
             //theLCD.print(msecbegin); 
             //theLCD.print(posend); 
             theLCD.setPosition(1,8); 
             theLCD.print("mm");                  
             tmr = 0; 
             lcdon = 0;                      
             theLCD.setPosition(2,0); 
             mmsec = (posdif/mtime); 
             theLCD.print((mmsec)); 
             theLCD.setPosition(2,8); 
             theLCD.print("mm/s"); 
             msectime = 0; 
             }
         }
      }
    }
    
  
    if ((upslread == LOW) && (uplmread == HIGH))
        {                   
            if (p == 0)
            {
              posbegin = pos;
              p = p++;
            }
            for (int i = 0; i  < 1; i++)
          {
          digitalWrite (enmot, HIGH);
          digitalWrite (mtstep, HIGH);
          digitalWrite (mtdir, LOW);
          delayMicroseconds (2600);
          pos = pos++;
          digitalRead (upslread); 
          if (upslread == LOW)
            {
            msecend = millis();  
            int i = i--;
            }
          if (msectime == 0) 
          {
            msecbegin = millis(); 
            msectime = msectime++;        
          }          
       }
     }
       else 
      {
        digitalWrite (mtstep, LOW); 
      }
        

  if ((dwslread == LOW) && (dwlmread == HIGH))
          {
          if (p == 0)
          {
            posbegin = pos; 
            p = p++; 
          }            
              for (int i = 0; i  < 1 ; i++)
              {
              digitalWrite (enmot, HIGH);
              digitalWrite (mtstep, HIGH);
              digitalWrite (mtdir, HIGH);
              delayMicroseconds (2600);
              posref = posref -1; 
              pos = pos - 1; 
              digitalRead (dwslread); 
              if (dwslread == LOW)
                {
                msecend = millis(); 
                int i = i--;
                }  
                if (msectime == 0) 
                    {
                    msecbegin = millis(); 
                    msectime = msectime++;        
                    }  
                 }      
              }
               else 
              {
               digitalWrite (mtstep, LOW); 
              }  
if ((upfsread == LOW) && (uplmread == HIGH))
      {
      if (p == 0)
          {
            posbegin = pos; 
            p = p++; 
          }       
          for (int i = 0; i  < 1; i++)// upfs switch and LCD counting. 
            {        
            digitalWrite (enmot, HIGH);
            digitalWrite (mtstep, HIGH);
            digitalWrite (mtdir, LOW);
            delayMicroseconds (150);
            posref = posref + 1; 
            pos = pos + 1; 
            digitalRead (upfsread); 
            if (upfsread == LOW)
              {
               msecend = millis(); 
               int i = i--;
              }   
               if (msectime == 0) 
                    {
                    msecbegin = millis(); 
                    msectime = msectime++;        
                    }
                }
          }
        else 
          {
          digitalWrite (mtstep, LOW); 
        }
                   
if (rposread == LOW){
     theLCD.clear(); 
     theLCD.print("POSITION RESET");
      
     theLCD.setPosition (2,0); 
     delay (50);
     theLCD.print ("."); 
     theLCD.setPosition (2,1); 
     delay (50); 
     theLCD.print ("."); 
     theLCD.setPosition (2,2); 
     delay (50); 
     theLCD.print (".");
     theLCD.setPosition (2,3); 
     delay (50); 
     theLCD.print ("."); 
     theLCD.setPosition (2,4); 
     delay (50); 
     theLCD.print (".");
          theLCD.setPosition (2,5); 
     delay (50); 
     theLCD.print (".");
          theLCD.setPosition (2,6); 
     delay (50); 
     theLCD.print (".");
          theLCD.setPosition (2,7); 
     delay (50); 
     theLCD.print (".");
          theLCD.setPosition (2,8); 
     delay (50); 
     theLCD.print (".");
          theLCD.setPosition (2,9); 
     delay (50); 
     theLCD.print (".");
          theLCD.setPosition (2,10); 
     delay (50); 
     theLCD.print (".");
          theLCD.setPosition (2,11); 
     delay (50); 
     theLCD.print (".");
          theLCD.setPosition (2,12); 
     delay (50); 
     theLCD.print (".");
          theLCD.setPosition (2,13); 
     delay (50); 
     theLCD.print (".");
          theLCD.setPosition (2,14); 
     delay (50); 
     theLCD.print (".");
          theLCD.setPosition (2,15); 
     delay (50); 
     theLCD.print (".");
          theLCD.setPosition (2,16); 
     delay (50); 
     theLCD.print (".");
      delay (50);
     theLCD.clear();
     pos = 0;
     theLCD.print(pos);
     theLCD.setPosition(1,8);
     theLCD.print("mm"); 
     msecbegin = msecend; // give 0mm/s
     posdif = 0;
           }
            else 
           {
            digitalWrite (enmot, LOW); // shut down the motor
            }
     }

Ok I am fairly happy, sort of, i was able to replicate the problem! After several turn on/off, LCD was still working properly, so i left it on for a while and then all of a suddent, display turned all black, i plugged a display in parallell, and the arduino was still sending proper info. (-0.12mm 0.92 mm/s). Shut it down, power it again, custom bootsplash comes in OK, then after my 5 seconds delay, only giberrish, refreshing at the rate it is supposed to though, see second picture. Last picture is when i press button postion reset, it should write on the display "Positon reset" and on the second line ..........
Same problem as before, i am sure that if i reset to 9600, it will be fine. Any ideas?

void setup()
{
 Serial.begin(9600);
}

void loop()
{
 Serial.print(0x7C, BYTE);  //special character
 Serial.print(0x12, BYTE);  //reset character
 }



I've done my grounds again, and Ill change the LCD library from SerLCD to serLCD, maybe more stable.
Any other ideas?

If you put that other LCD in parallel, and it works fine, it could just mean the first one is just dying or dead.

HazardsMind:
If you put that other LCD in parallel, and it works fine, it could just mean the first one is just dying or dead.

I don't totally agree with this answer but I am also curious how you would interpret the other three possible outcomes.

Don

I agree too, thats why I said,

it could just mean the first one is just dying or dead.

@bobyboucherdownunder
How big is your sketch?
Also, where does the gibberish start, what line?