B4R Library LiquidCrystal_I2C

Kevin

Well-Known Member
Licensed User
Longtime User
For anyone interested, I modified this library to support creating custom characters without the need for using inline C. I gave it a new name (rLiquidCrystal_I2C_Cust) but if Erel chooses, he can just merge the changes into an updated version of his library.

The original C library supports up to 8 custom characters, numbered 0-7.

I use this webpage to generate the characters. It has an option to output hex which seems to work best for me for creating the byte array in B4R. You can copy & paste the hex results, but you'll just need to remove the carriage returns after pasting into the IDE.

Code:
B4X:
Dim CharMap() As Byte = Array As Byte (0x00,0x1B,0x1B,0x00,0x11,0x1F,0x0E,0x00)
lcd.CreateChar (0, CharMap)

'To display the custom character, use this:
lcd.Write (Array As Byte(0))
 

Attachments

  • rLiquidCrystal_I2C_Cust.zip
    6.6 KB · Views: 419

derez

Expert
Licensed User
Longtime User
It doesn't work for me !
 

Cableguy

Expert
Licensed User
Longtime User
I2C screens have addresses, so you should start by that, check if your screen address is the one used in the code and if not change in the code to match your screen!
 

derez

Expert
Licensed User
Longtime User
The LCD works but it does not show the custom char. Using Arduino UNO.
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
    Private lcd As LiquidCrystal_I2C
  
    Dim CharMap() As Byte = Array As Byte (0x00,0x1B,0x1B,0x00,0x11,0x1F,0x0E,0x00)
   
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
    lcd.Initialize(0x3F, 16, 2) 'based on the example from the project.
'   lcd.Initialize(0x27, 20, 4) ' for 20X4 lcd
   lcd.Backlight = True
   lcd.SetCursor(0,0)

    lcd.CreateChar (0, CharMap)
    lcd.Write (Array As Byte(0))
   
    lcd.SetCursor(0,1)
    lcd.Write("99999999")  ' this shows
 
End Sub
 

derez

Expert
Licensed User
Longtime User
I2C screens have addresses, so you should start by that, check if your screen address is the one used in the code and if not change in the code to match your screen!
Good idea but I know that of course.
 

Kevin

Well-Known Member
Licensed User
Longtime User
The only thing I can think of to try would be to uncheck the rLiquidCrystal_I2C_Cust library in the IDE, then right-click and choose Refresh, then re-check the rLiquidCrystal_I2C_Cust library to add it back in. Also, of course, be sure that you have already UN-checked the original rLiquidCrystal_I2C library.

Failing that, perhaps try cleaning the project.

Edit: While working on this change to the library, I recall reading that some people had issues using slot 0 with the original C library, so perhaps you can try changing it to use Slot 1 instead.
 

derez

Expert
Licensed User
Longtime User
Did all that - still nothing.

While working on this change to the library, I recall reading that some people had issues using slot 0 with the original C library, so perhaps you can try changing it to use Slot 1 instead.
I don't understand. I use pins A4 and A5 as sda and scl pins.
 

Kevin

Well-Known Member
Licensed User
Longtime User
Did all that - still nothing.


I don't understand. I use pins A4 and A5 as sda and scl pins.

Replace the 0 with 1 (not in the array)...

B4X:
Dim CharMap() As Byte = Array As Byte (0x00,0x1B,0x1B,0x00,0x11,0x1F,0x0E,0x00)
lcd.CreateChar (0, CharMap)

'To display the custom character, use this:
lcd.Write (Array As Byte(0))
 

derez

Expert
Licensed User
Longtime User
OK but it didn't help either. Both rows show the regular chars (9999999 in my code) but not the custom char. Also tried to have 1 in the charmap.
I guess something in your library does not match with my UNO (a chinese clone), though I never had any compatibility problem with other libraries.
 

XorAndOr

Active Member
Licensed User
Longtime User

Hello, set lcd.SetCursor(0,0) after lcd.CreateChar

B4X:
lcd.CreateChar(0, CharMap)

lcd.SetCursor(0,0)
lcd.Write(Array As Byte(0))
 

Kevin

Well-Known Member
Licensed User
Longtime User
Hello, set lcd.SetCursor(0,0) after lcd.CreateChar

B4X:
lcd.CreateChar(0, CharMap)

lcd.SetCursor(0,0)
lcd.Write(Array As Byte(0))
Good catch! I was pretty baffled as to why it wasn't working for him.

I create my characters just after initializing the lcd and long before I ever actually write to it.
 

derez

Expert
Licensed User
Longtime User
Thanks to all of you trying to help on this mystery...
The results - Hebrew letters:
If anyone is interested I can publish the byte arrays for all the letters.
This is how I write Sunday in Hebrew:
B4X:
Sub write_sunday
    lcd.CreateChar (0, resh)
    lcd.CreateChar (1, aleph)
    lcd.CreateChar (2, shin)
    lcd.CreateChar (3, vav)
    lcd.CreateChar (4, nuns)
    lcd.SetCursor(11,0)
    lcd.Write (Array As Byte(4,3,2,1,0))
End Sub
Note: There can be only 8 different custom chars on the screen at a time, for most of the words it enough but not for full screen text.
 

Attachments

  • Hebrew_letters.png
    237.3 KB · Views: 370
Last edited:

Cableguy

Expert
Licensed User
Longtime User
There can be only 8 different custom chars on the screen at a time, for most of the words it enough but not for full screen text.

Isn't this an available memory issue?
I mean, with a wemos (4mB) you should be able to declare/store more custom characters, right?
 

derez

Expert
Licensed User
Longtime User
Isn't this an available memory issue?
I mean, with a wemos (4mB) you should be able to declare/store more custom characters, right?
The limit of 8 chars exists both in the original library and in Kevin's additions to it.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…