I2C programming problem

Hi,

I'm new to Arduino but having a lot of fun. Most things have worked fine, but I connected an I2C 2004 display and it works fine with letters and special characters.

I decided to try to make a smile. Everything is straight forward, and it works fine as I add each additional block (up through lcd.createChar(7,H); it works perfect - see photo #1. But when I add lcd.creatChar(8,I); it stops displaying the first box. Then adding lcd.creatChar(9,J) it adds an completely new, undefined box (see photo #2) I have tried starting over on a new design and the same problem happens after 8 commands again.

The attached sketch has those last too commands removed (actually just //) and then it gives Photo #1. Then the // is removed on those two commands then I get Photo#2.

Thanks so much for any help or direction.

Jim

//* Make an LCD Smile
// Include the library:
#include <LiquidCrystal_I2C.h>
// Create lcd object of class LiquidCrystal_I2C:
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 20, 4); // Change to (0x27,16,2) for 16x2 LCD.
// Make custom design:

byte A[] = {
  B11000,
  B11000,
  B01100,
  B01100,
  B01100,
  B00110,
  B00110,
  B00011
};
byte B[] = {
  B00011,
  B00001,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000
};
byte C[] = {
  B00000,
  B10000,
  B11000,
  B11000,
  B01100,
  B00110,
  B00011,
  B00001
};
byte D[] = {
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B11000
};
byte E[] = {
  B11100,
  B00111,
  B00011,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000
};
byte F[] = {
  B00000,
  B10000,
  B11111,
  B01111,
  B00000,
  B00000,
  B00000,
  B00000
};
byte G[] = {
  B00000,
  B00001,
  B11111,
  B11110,
  B00000,
  B00000,
  B00000,
  B00000
};
byte H[] = {
  B01111,
  B11100,
  B10000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000
};
byte I[] = {
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00011
};
byte J[] = {
  B00000,
  B00001,
  B00001,
  B00011,
  B00110,
  B01100,
  B11000,
  B10000
};
void setup() {
  // Initialize LCD and turn on the backlight:
  lcd.init();
  lcd.backlight();
  // Create new characters:
  lcd.createChar(0, A);
  lcd.createChar(1, B);
  lcd.createChar(2, C);
  lcd.createChar(3, D);
  lcd.createChar(4, E);
  lcd.createChar(5, F); 
  lcd.createChar(6, G);
  lcd.createChar(7, H);
  //lcd.createChar(8, I);
  //lcd.createChar(9, J);
  
  // Clear the LCD screen:
  lcd.clear();
  // Print a message to the lcd:
  //lcd.print("Custom Character");
}
// Print all the custom characters:
void loop() {
  lcd.setCursor(6, 1);
  lcd.write(0);
  lcd.setCursor(6, 2);
  lcd.write(1);
  lcd.setCursor(7, 2);
  lcd.write(2);
  lcd.setCursor(8, 2);
  lcd.write(3);
  lcd.setCursor(8, 3);
  lcd.write(4);
  lcd.setCursor(9, 3);
  lcd.write(5);
  lcd.setCursor(10, 3);
  lcd.write(6);
  lcd.setCursor(11, 3);
  lcd.write(7);
  //lcd.setCursor(11, 2);
  //lcd.write(8);
  //lcd.setCursor(12, 2);
  //lcd.write(9);
 
  
}

Photo 1.JPG

Photo 2.JPG

There are only 8 characters that can be defined, numbered 0 to 7.

Well, that explains it!!

Thank you,

Jim

There are 8 code points for custom characters. You can use 0-7 or 8-15. 8-15 are the same as 0-7

--- bill

BTW, you may want to take a look at the hd44780 library.
It is simpler to use as it will auto locate the i2c address, is quite a bit faster, and comes with better documentation and examples.
The i/o class for your LCD device is hd44780_I2Cexp
The LCDCustomChars examples has lots of information in it about creating custom characters and how to use them, including inside your own character strings.

It is available in the IDE library manager.
Once installed you can have a look at the included Documentation
Before using it for the first time, make sure to run the included I2CexpDiag sketch to verify that everything is working properly.
Then you can proceed to using any of the other hd44780_I2Cexp i/o class examples.

--- bill

Wow, thank you.... I really appreciate it!

A lot to play with!

Jim