Custom characters behaving oddly...

I’ll do my best to try to explain this situation.

I’m writing a script that will print a custom character onto my LCD screen.

It looks like this:

byte customChar[8] = {
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111
};

It simply displays a box.

When I display this to the LCD screen, instead of a box, I get a random scatter of pixels where the box should be.

I also have another byte array that is used to clear that box from the screen (invert it):

byte blankChar[8] = {
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000
};

Similar to the first byte array, I get a random scatter of pixels on the.

Now, here’s where things get REALLY WEIRD.

If I run the Grove_RGB_Backlit_LCD > CustomCharacter example, that works perfectly fine.
HOWEVER! If I re-run the first script (the one that just displays the boxes), instead of just printing the random scatter of pixels like it originally did, it will instead display the custom characters that are shown in the Grove_RGB_Backlit_LCD > CustomCharacter example.

So, I’m guessing that the byte arrays from the Grove_RGB_Backlit_LCD > CustomCharacter example project are somehow being accessed instead of blankChar the customChar arrays?

I honestly have no idea…

My code is as follows:

#include <Wire.h>
#include “rgb_lcd.h”
rgb_lcd lcd;

// Define the pin to which the angle sensor is connected.
const int potentiometer = A0;
int middle = 500;

byte customChar[8] = {
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111
};

byte blankChar[8] = {
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000
};

void setup() {
// Initilize characters
lcd.createChar(0, customChar);
lcd.createChar(1, blankChar);
// Configure the angle sensor’s pin for input.
pinMode(potentiometer, INPUT);
// set up the LCD’s number of columns and rows:
lcd.begin(16,2);
}

void loop() {
// start the Thumbs Up part:
lcdLine();
}

void lcdLine() {
int value = analogRead(potentiometer);

if ( value < (middle-20) ) {
lcd.setCursor(5,1);
lcd.write(1);
lcd.setCursor(5,0);
lcd.write((unsigned char)0);
}

if ( value > (middle+20) ) {
lcd.setCursor(5,0);
lcd.write(1);
lcd.setCursor(5,1);
lcd.write((unsigned char)0);
}
}

The Grove_RGB_Backlit_LCD > CustomCharacter example code is as follows:

#include <Wire.h>
#include “rgb_lcd.h”

rgb_lcd lcd;

// make some custom characters:
byte heart[8] = {
0b00000,
0b01010,
0b11111,
0b11111,
0b11111,
0b01110,
0b00100,
0b00000
};

byte smiley[8] = {
0b00000,
0b00000,
0b01010,
0b00000,
0b00000,
0b10001,
0b01110,
0b00000
};

byte frownie[8] = {
0b00000,
0b00000,
0b01010,
0b00000,
0b00000,
0b00000,
0b01110,
0b10001
};

byte armsDown[8] = {
0b00100,
0b01010,
0b00100,
0b00100,
0b01110,
0b10101,
0b00100,
0b01010
};

byte armsUp[8] = {
0b00100,
0b01010,
0b00100,
0b10101,
0b01110,
0b00100,
0b00100,
0b01010
};

void setup()
{

lcd.begin(16, 2);
#if 1
// create a new character
lcd.createChar(0, heart);
// create a new character
lcd.createChar(1, smiley);
// create a new character
lcd.createChar(2, frownie);
// create a new character
lcd.createChar(3, armsDown);
// create a new character
lcd.createChar(4, armsUp);
#endif
// set up the lcd’s number of columns and rows:

lcd.setCursor(0, 0);
// Print a message to the lcd.
lcd.print("I “);
lcd.write((unsigned char)0);
lcd.print(” Arduino! ");
lcd.write(1);
}

void loop()
{
// read the potentiometer on A0:
int sensorReading = analogRead(A0);
// map the result to 200 - 1000:
int delayTime = map(sensorReading, 0, 1023, 200, 1000);
// set the cursor to the bottom row, 5th position:
lcd.setCursor(4, 1);
// draw the little man, arms down:
lcd.write(3);
delay(delayTime);
lcd.setCursor(4, 1);
// draw him arms up:
lcd.write(4);
delay(delayTime);
}

I don't know if it is the source of the problem, but in your code the lcd.begin() is after the crearChar statements and the Grove code the createChars are after the lcd.begin().

Please use code tags. See the "how to use the forum" stickies.

The only difference I can see is that the code that works uses a delay() to slow the LCD refresh rate. Perhaps your code needs one, too.

groundfungus:
I don’t know if it is the source of the problem, but in your code the lcd.begin() is after the crearChar statements and the Grove code the createChars are after the lcd.begin().

Please use code tags. See the “how to use the forum” stickies.

That did it, thanks.I
I didn’t know the significance of calling lcd.begin() first.
Makes sense when I say it out loud though lol

I ran into the same issue today. As I am working with FM Malpartidas fantastic new liquid crystal library, I found the solution in FM's blog. The custom created characters will be stored in the LCD's little memory, so the LLCd has to be initiated first before one can start the creation process.