LCD-HD44780 custom how to program?

Thank you for your help First, I tried to do the setCursor in several different cols with the HD44780 lib but I was not successful in either decimals or hex, the display has 6 cols in the first line and 6 cols in the second line, these lines and cols I can insert whatever I want but if I exceed 6 cols the display lights up some random icons, there are also on the right side some characters in 7seg format I think each one can be just 1 bit in ddram but I don't know how to access them, I think I'll do my project with just 6 cols and 2 lines because without the datasheet it will be very difficult to figure out how to use these icons. But even so I appreciate your help.

Yes you were successful with setCursor()
There really is no such thing as decimal or hex for a parameter.
A parameter has a value.
A value is assigned to an integer that is passed in as the cols parameter to setCursor()
How you do that assignment is up to you.
i.e. for literal assignment:

col = 40;
col = 0x28;
col = 050;
col = 0b10100;

All of these are the same value of 40 which is the DDRAM address of the first character on the 2nd row.
or with a loop

for(int ddramaddr = 0; ddramaddr < 80; ddramaddr++)
for(int ddramaddr = 0; ddramaddr < 0x28; ddramaddr++)
for(int ddramaddr = 0; ddramaddr < 050; ddramaddr++)
for(int ddramaddr = 0; ddramaddr < 0b10100; ddramaddr++)

All these for statements do the same loop.

Me personally, I be using a for loop with an integer to walk through DDRAM locations and use decimal for the starting and ending values in the for statement.

If you want to set the DDRAM address you then use
lcd.setCursor(ddramaddr, 0);
before you write the desired byte to that location using
lcd.writ(bytevalue);

The behavior you describing is pretty much as I described and what I would have expected
Certain locations of DDRAM are for the two lines of text and others have bytes that that appear to be used to control icons based on bits in the bytes.

Like I said, you need to be methodical and write to consecutive locations in DDRAM to figure out how the DDRAM is mapped to the pixels on the display.

It shouldn't take that long to figure out but you need to be very methodical.

You also need to be aware that the mapping of DDRAM to LCD glass text rows is not consecutive.
i.e. on a 2 line display the 2nd row DDRAM address is not consecutive with the last character on the 1st line.
Typically on a two line display,
row 0 starts at DDRAM address 0 and row 1 starts at DDRAM address 40
This is in the hd44780 datasheet, but here is a link with additional information about address mapping:

The chipset reads from DDRAM, uses that value to look up a font bit pattern and then creates signals that can be used to light the pixels on the LCD glass.
The pixels are scanned across the display.
The chipset assumes a certain mapping of the columns and row signals to turn on the pixels to form characters but the LCD is free to use these signals anyway it wants like to control an icon.

How the LCD glass arranges those pixels vs what is stored in DDRAM and where is what you are trying to determine.

In your case, it sounds like the LCD glass has wired up the first 6 characters of a 2 line display to characters and then DDRAM addresses beyond the 6 characters are being used to control icons.

Again be methodical and you can figure it out.
You have to write to all the memory locations and watch for changes.
The most likely areas to focus on will be
DDRAM locations:
0 to 5 (for text row 0)
40 to 45 (for text row 1)

Locations just beyond 5 and 45 likely control icons.
You will have to experiment with the values you write to these locations to see how to control the icons.

--- bill

I discovered this morning I did the for in setCursor the top line starts with 0 and the bottom one with 46, from what I understand there will be many combinations to be able to use all the icons, in fact I wanted to use only a few, if there was a way to find out which byte controls the icons the problem would be solved, because for example if I write 'A' at address 6, 0 lights up some characters but if I write 'B' it lights up others, it seems like a combination of bits different from the bits of any character.

I also noticed that it is only some addresses after 6, 0 that light up the characters, for example if I write something in 6, 1 no icon lights up. so I think everything is between 6, 0 but it depends on the byte that will be written

Ok,
So sorry. When I said the second row started at 40, I misremembered and that it was actually 40 hex which is 64 Decimal. My bad there. So sorry about that.

Are you sure the bottom text row (row 1) is DDRAM address 46 ? I would have expected it to be 64 or 0x40
which is the most common DDRAM address for the 2nd row.
If you do a setCursor(0,1) and it prints on the second row, the DDRAM address for the 2nd line is 64 or 0x40

if there was a way to find out which byte controls the icons the problem would be solved,

That is what you have to figure out.

They could have implemented it several ways.

How many icons are there?
That might be clue as to how they might have designed the h/w to activate them.

If they are tapping into the segment lines to turn on an icon (which is what I would expect) then the icon is activated by an individual pixel in the font glyph for a given DDRAM address.

So then it becomes do they use multiple DDRAM addresses or a single DDRAM address with varying glyph data in a custom character to activate the pixels.

For an experiment, I would first create a custom character with all the pixels set.

byte Cdata[8] = {
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
};

lcd.creatChar(1, Cdata);

Then write that to the LCD using lcd.write(1); at the desired DDRAM address.

note: I used 1 for the custom character position,
you can use any value between 0 and 15 for the custom character
Just remember that there are not 16 custom characters there are only 8
0-7 is the same as 8 -15 and zero is a bit different do to how C/C++ handles zeros.

If you see all the icons light up when you write that value to a DDRAM address, then you know that this is the way to control them and is just a matter of figuring out which bits in that data controls which icon.

If that is how it works, then you simply alter the data by turning on /off the appropriate bit in the data and call createChar() again to update character definition in CGRAM. There is no need to write the custom character to the LCD again since it is already in DDRAM.
Just updating the glyph definition in CGRAM by calling createChar() is enough since the custom character value in DDRAM is not changing. It is glyph definition in CGRAM that is changing.

--- bill

It worked, unbelievable, you're awesome. I can control most of the icons with this array, but the small 7-segment digits didn't appear, nor the battery icon. There's probably still some binary code missing. It's already evolved a lot.


  byte Cdata[8] = {
  B01000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
};


void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(5, 2);
  lcd.createChar(1, Cdata);
  lcd.setCursor(6, 0);
  lcd.write(1);

}

void loop() {

      
}

With these bits, only the letter icon lights up, as shown in the photo.

If you set all bits to 1, all icons light up except the small 7-segment digits and the battery icon.

Getting closer.
Now you know how to control all the icons but the battery icon using DDRAM location 6.
Have you fully mapped out which bit in the Cdata RAM array controls which icon?

The 7 segment digits and the battery icon are likely a different DDRAM address or multiple addresses but may use the same technique to control individual 7 segment segments and the battery icon.

What about the pairs of little "75" and "25" that are between the rows of text
and the seven segment numbers?

Now you need to try writing an "all pixels on" character at other DDRAM locations (initially I'd just loop through all of DDRAM memory) to see if you can turn on the battery icon and the seven segment pieces and the two 75s and the two 25s

--- bill

Page 5 has the full display.

I count about 64 controllable icon / "things" outside of the 2 writable lines.
This is more things than pixels in a single custom character.
A single custom character is 40 pixels max.

--- bill

Yes, I discovered it using the same array, but in position 7, 0 only lights up the 7 segment digits and the battery icon. I haven't mapped the bits yet, but I already know how everything works thanks to you. Now I have to learn how to use p createChar to make these icons move, but I'll learn that later. For now, I have a lot to thank you for.

I just want to use the digits, the battery icon and the progress bar at the bottom is actually an S-meter used in amateur radio. I'm going to turn this radio into a DSP radio.

Later I will send photos and the code of our discoveries.

huh?
All you have to do is modify the bits in the array and then call createChar() with the array again to update the glyph in CGRAM. Thats it.

So to turn on the mailbox icon

bitSet(Cdata[0], 5);
lcd.createChar(Cdata, 1);

or

bitClear(Cdata[0], 5);
lcd.createChar(Cdata, 1);

If you have a bunch of icons you want/need to update at once then set/clear the all the various bits in the data array then when ready to update the display call createChar() just one time, and all the icons will be updated at once.

You could wrap the bit manipulation in a macro or inline function to make the mailine code a bit more readable

--- bill

#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs=PA5, en=PA4, d4=PA0, d5=PA1, d6=PA2, d7=PA3;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);


  byte Icons[7] = {
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
};

  byte segMents[7] = {
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
};


void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(5, 2);
  lcd.createChar(1, segMents);
    lcd.createChar(2, Icons);


}

void loop() {
  lcd.clear();
  lcd.setCursor(7, 0);
  lcd.write(1);
   delay(1000);
  lcd.setCursor(0, 0);
  lcd.print("7Seg");
  delay(1000);

  lcd.clear();

// 7 seg and battery
  lcd.setCursor(6, 0);
  lcd.write(2);
  delay(1000);
  lcd.setCursor(0, 1);
  lcd.print("Icons");
  delay(1000);      
}

This is the final code of the prototype, now I will have to create each character for each icon and each segment of the smaller display and the battery, it will be a lot of work but it will work the way I want =D

LCD Test.

nice.
printable LCD is 6 columns by 2 rows
row 0 text starts at DDRAM location 0
row 1 text starts DDRAM location 64

DDRAM locations 6 and 7 are used to control icons / segments / battery

In your final code, you will only need 2 and only 2 custom characters.
One for the all the icons and one for all the segment and battery stuff.
You will set/clear the appropriate bits inside the custom character definition data array to turn on whatever icons or segments you want to light up or turn off and then call createChar() to update the character glyph data for that custom character in CGRAM for that custom character.

Before that, you will have to figure out is which bit in the data array controls which icon or segment so you know which bits to set or clear.

You could write a sketch with a loop (actually two loops - one for the index and one for the bit) that walks a single bit through the entire data array.
It sets a bit does a createChar() then waits for a button press to advance. And each time print the array index and bit number in the data on either the LCD or the serial port.
After the button press, it clears the bit it previous set
and then advances the bit number and/or index


I thought you were using the hd44780 library.

The example code you posted is using the LiquidCrystal library.
There is an issue related to createChar() in the LiquidCrystal library.
The LiquidCrystal library leaves the hd44780 chipset in CGRAM mode when createChar() returns. You must do a clear(), home(), or setCursor() to put the chipset back into DDRAM mode so you can print again. If you don't and attempt to write characters to the LCD, it will corrupt the CGRAM.
This is not the case with the hd44780 library.

There are also some other capabilities in the hd44780 library that are not in the LiquidCrystal library. To name a few, it is faster and it can be initialized to do line wrapping on printing if you give it the the proper geometry in begin()

--- bill

Today I will try to do it with the HD44780 library because I really can't do some things, especially the bargraph that is below the display, but the important thing is that now I understand how it works thanks to your help. Thank you very much.

The bar graph along the bottom lit up in the video.
I assume that there is a pixel in the custom character that controls each bar in the bar graph.

I'd write a test sketch with a loop that sets/clears each bit/pixel so you can see what each bit in the data array controls.
You could use the serial port and just wait on reading a character between each iteration of the loop that advances through each bit in the data array.
Then use use the serial monitor to print out the index and bit number for each iteration and press the enter/return key to advance to the next bit in the data array.

--- bill