problems with odd characters on LCD

I am chasing this down again. I had this problem before and I thought it was solved, but it is not. I am having a problem with my LCD characters. If I make the change of 1 character (adding a space at the end of a string) the entire display goes to gibberish. If I remove the space, it is perfectly clear. I am currently working on a 2 line 16 character display.

Now, the things that are slightly out of place in set up is that I am using an analog as a digital for D7 LiquidCrystal lcd( 8, 9, 10, 11, 12, 14 ); //LiquidCrystal(rs, enable, d4, d5, d6, d7)

I am using PWM for the backlight on 6, but I do not think that the PWM would goof up any LCD Timing.

I can post the whole code if it would help, but I wanted to see if others were having similar problems. I tried several searches, but I am not seeing the same slop that I am getting.

Hi, You say that you "add" a space at the end of a string. How do you do that ? If you simply assign the " " char to the char array, be careful not to overwrite the last (hidden) null byte, which serves as a string terminator.


char s[3] = "AB";

Here is the memory situation: s[0] --> A s[1] --> B s[2] --> null character (binary 0)

If you Serial.print(s), you get "AB".

Now if I "add" a space at the end by doing s[2] = ' '; I'm overwriting the string terminator, therefore Serial.print(s) will print the two chars (AB) and then will go on until it finds a null byte, almost certainly printing out garbage.


This is my print script.

void reportMe(){ lcd.clear(); lcd.print( "But=" ); lcd.print( currentVal ); lcd.setCursor(8,0); lcd.print( "An1=" ); lcd.print( sense1Val ); lcd.setCursor(0,1); lcd.print( "An2=" ); lcd.print( sense2Val ); lcd.setCursor(8,1); lcd.print( "T= " ); lcd.print( curPut ); }

All the values are from variable pots so max characters would be 4. So, the top row would be 16 chars and the bottom row would be a max of 12 chars. (curPut is a single digit). Unless something is extremely wrong, all the variables will be 3 digit numbers, not 4. What it odd about this is that if I add the space, it will also botch the strings that show up on the screen during the setup.

At the end of the set up...

lcd.clear(); lcd.print( " BLACK BOX " ); lcd.setCursor (0,1); lcd.print( " TEST SYSTEM " );

fadeIn(); delay(1500); digitalWrite(ledPin, LOW); lcd.clear(); beep(); }

Still you don't say HOW you add the space. Now that you posted the working code, please post the wrong one, so we can see the difference.

How about if you add

char* tmp = “Test”;

just above ‘void ReportMe(){’ ?

I wonder if you’re running out of RAM? This often causes “strange” problems.

I am sorry mromani. You are correct. I did not state where I put in the space. I got home tonight and tried to recreate the situation so I could take some pictures and give you more, but I am battling my arduino and can not get a dang thing loaded. I will try to flog the thing into working and report to you when I am on better standing. To be honest when I was dealing with all this I saved the sketch back in the working set up and right now I do not know. I wanted to get in and make it fail again so I could post exactly what it was doing with pix.

Steve S, I am not sure about a RAM issue as it is only the 6 strings and the 4 values. It it on a 328 so it should not be running out of RAM. the whole sketch loaded is only 3684 bytes. This is a test sketch to make sure that all the IO in this system is happy. I have a test board I can plug into the Arduino to return a known set of values, so I know it is running properly.
It runs through a loop of 3 analog reads, and a counter (a 1 digit count (1-4 indicating which test is being displayed)) It then sends the values and the count number to the LCD, then lights one of the 4 outputs (this is connected to 4 LEDs in test). So, I could be wrong, but I do not know how I could be out of RAM, there is really nothing going on.

Indeed, if that's all you have, it's unlikely to be an SRAM issue. Given that you don't have huge numbers of strings to copy from from PROGMEM into SRAM on startup.