createChar() using LiquidCrystal_I2C.h

Hi everyone,

I just bought a new LCD for my Arduino and after figuring out how to make it work using the LiquidCrystal_I2C library, it works. Only I can't manage to display custom characters on it.
Now I have no idea if it's specific to that library or if I would have had that problem anyway because this is the first time ever I try to do this.
I made a hyper simple code to display my custom characters and it gives me the same issue. Here it is :

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// LCD
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

void setup() {
  Serial.begin(9600); // COMMENT OUT IF USING PIN 1
  
  // Characters
  byte whole[8] = {B00000, B00000, B00000, B00000, B00000, B01110, B10001, B01110};
  byte half[8] = {B00001, B00001, B00001, B00001, B00001, B01111, B10001, B01110};
  byte quarter[8] = {B00001, B00001, B00001, B00001, B00001, B01111, B11111, B01110};
  byte eighth[8] = { B01110, B01001, B00101, B00010, B00001, B01111, B11111, B01110};
  byte sixteenth[8] = {B00110, B00101, B00110, B00101, B00100, B01100, B11100, B01000};
  byte sixteenthRest[8] = {B00000, B01001, B10101, B01010, B00100, B01000, B10000, B00000};

  lcd.createChar(0, whole);
  lcd.createChar(1, half);
  lcd.createChar(2, quarter);
  lcd.createChar(3, eighth);
  lcd.createChar(4, sixteenth);
  lcd.createChar(5, sixteenthRest);
  
  // LCD
  
  lcd.begin(16, 2); // set up the LCD's number of columns and rows
}

void loop() {
  lcd.write(byte(0));
  delay(2000);
  lcd.write(byte(1));
  delay(2000);
  lcd.write(byte(2));
  delay(2000);
  lcd.write(byte(3));
  delay(2000);
  lcd.write(byte(4));
  delay(2000);
  lcd.write(byte(5));
  delay(2000);
}

Any idea why it displays wrong characters instead of the ones I made ?

Thanks a lot,

Antoine

move these line to before set-up

byte whole[8] = {B00000, B00000, B00000, B00000, B00000, B01110, B10001, B01110};
byte half[8] = {B00001, B00001, B00001, B00001, B00001, B01111, B10001, B01110};
byte quarter[8] = {B00001, B00001, B00001, B00001, B00001, B01111, B11111, B01110};
byte eighth[8] = { B01110, B01001, B00101, B00010, B00001, B01111, B11111, B01110};
byte sixteenth[8] = {B00110, B00101, B00110, B00101, B00100, B01100, B11100, B01000};
byte sixteenthRest[8] = {B00000, B01001, B10101, B01010, B00100, B01000, B10000, B00000};

Tried it already, it didn't do anything.

Now I tried this :

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

void setup() {
  Serial.begin(9600);
  
  byte customChar[8] = {B00000, B00000, B00000, B00000, B00000, B00000, B00000, B00001};
  lcd.createChar(0, customChar);
  
  lcd.begin(16, 2); // set up the LCD's number of columns and rows
  lcd.clear();
  lcd.write(byte(0));
}

void loop() {
}

Just to see...

And I still get the same character :

xxxxx

xxxxx
   x
xxxxx

xxxxx
   x

test this and see if it works I just copyed parts of a proven program I made a while back into your test code

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
byte temp_char[8] = {B01110, B01010, B01010, B01110, B01110, B11111, B11111, B01110};
byte hum_char[8] = {B00100, B01110, B11111, B00100, B10001, B00100, B10001, B00100};
byte bell_Char[8] = {B00100, B01110, B01110, B01110, B11111, B11111, B00100, B00000};
byte arrow_Char[8] = {B00000, B00000, B10000, B10000, B10111, B10011, B10101, B01000};

void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2); // set up the LCD's number of columns and rows
  lcd.createChar(1, temp_char);
  lcd.createChar(2, hum_char);
  lcd.createChar(3, bell_Char);
  lcd.createChar(4, arrow_Char);

  
  lcd.clear();
  lcd.write(1);
  lcd.write(2);
  lcd.write(3);
  lcd.write(4);
}

void loop() {
}

ops I think the lcd.begin has to be before the createchar will go back and edit that

Thanks.

I get only two different character. One is the same I get all the time, the other is a shrunk down version of it :

.....
.....
.....
.....
xxxxx
.....
xxxxx
...x.

for 1
and

xxxxx
.....
xxxxx
...x.
xxxxx
.....
xxxxx
...x.

for all the others.

Oh! With the lcd.begin(16, 2) before createChar... it works! I get your little symbols!

Now let's try with mine. That would be such a stupid mistake :slight_smile:

HA! That was it! So dumb! Sorry I wasted your time. Thanks a lot for your help!

If I remember correctly custom characters are stored by the lcd that's why you can only have 8 max

so it makes sense that you have to start the lcd before making the characters

Oh ok now I get it. Makes sense indeed.

Thanks again.

Hi
I use liquid crystal i2c.h and make a char but it show in 0,0(col,row) position ,i want to set in 15,1
How do it?

How do it?

You can make your special character appear in any position just like you make any regular character appear in any position, using setCursor().