Character text 'back to front' on display from Arduino Pro Micro. [Solved]

Hello all,

I will get straight to the point.

Problem: The text on my 20x4 display is back to front (mirror).

Parts;

LCD

LPC port chip with LCD support. It outputs by spi on 3 wires to a bespoke designed Arduino on a PCB done by someone else.

I have had a look and opened the code and the pdf command sheet.

Ultimately, can any good person on here correct the .ino for me to compile & upload again to the Arduino Pro? I would be most grateful. :smiley:

Thank you for taking a look anyway.

Looks like you need something like....

sendCommand(0x2A); // Set "RE"=1
sendCommand(0x04); // set BDC=0, BDS=0

Depending on the value you require for the BDC/BDS bits you will need to modify the second command to a value between 0x04 and 0x07.

Perhaps your library code already has one of these commands, but I can’t download it on a mobile device to check.

It looks like you will need to send the ENTRYMODE command to map the columns from 0->31 vs. 31->0 (or vise-versa)
in setup()

  hd44780.begin(20, 4);
  hd44780.noCursor();
  byte mode = 0;  // values 0-3
  hd44780.command(LCD_ENTRYMODESET | mode );
  ..

You will have to test the different values of mode to see which one works for you since I do not have that hardware. It most likely will be 2 or 3 (since it is the lower 2 bits that set the column order and segment order)

pcbbc:
Looks like you need something like....

sendCommand(0x2A); // Set "RE"=1

sendCommand(0x04); // set BDC=0, BDS=0




Depending on the value you require for the BDC/BDS bits you will need to modify the second command to a value between 0x04 and 0x07.

Perhaps your library code already has one of these commands, but I can’t download it on a mobile device to check.

Thanks for your reply.
I have tried this but on compile it error'd because the command is not in the Arduino 'LiquidCrystal.h' so replied not found. Which makes sense I suppose as it's an LCD library not for this one.

I guess I would have to add that other library instead, but then no doubt all the code ref's to the old library & commands would need changing, so obviously way beyond my remit.

Thank you for your reply too.

I have just tried this, each time changing the byte mode and uploading to the Arduino.

Results were the same on 2 except it centred the text in the display, but still wrong way around. Same as before on 3 and 1, while 0 was more garbled but back to front still on all of them.

Does it look like it needs that other library? and all the code subsequently changing?

Thanks,
Neil.

You can convert those hex values to binary and they will match up to the 8 bits in the PDF command table.

For example: Sending the command 0x2A = binary 0010 1010
and if you look at the table, That is the 'Function Set' command (pg 8) which explains what the lower bits mean

blh64:
You can convert those hex values to binary and they will match up to the 8 bits in the PDF command table.

For example: Sending the command 0x2A = binary 0010 1010
and if you look at the table, That is the 'Function Set' command (pg 8) which explains what the lower bits mean

Err okay. Strikes me as to why the manufacturer does not just make the table in those 4 digit hex values and save space/ink/paper in the tables as well as make it a lot easier! ie; hex value for each toggle/action/instruction.

Thanks,
Neil.

Post the solution so other may benefit. You can also edit the original title of the thread and insert [SOLVED] to people know there is a solution

Yeah, I was preemptive, thought I had it 100%, but then noticed lines 2 & 4 are only printing to half way.
So now a bit stumped, so not a [solution] yet.

Currently changing a hex value which then works for lines 1 & 2, but then 3 & 4 are off.

Was up all night with it and gave up.

Will post the code I have added shortly - currently on mac boot so will have to load up windows to see my code.

Oh, this is the web page that helped me get this far along with using the example code on the pdf.

Tutorial 3.

Might make it easy/quick for someone here to point out what's wrong.

Did you run the example 3 code? It looks like it should work.

I can't add all the other code because;

  1. There's already the code definition for the arduino pins etc along with constants from the original coder.

  2. If I try to add anything it will just error out.

  3. If I add a library (which I tried) I get page fulls of errors on compile again because of conflict.

This is the first time I have ever even attempted anything with coding - all I have ever done before this is edit an .xml file.

I believe that may be causing my last issue with rows 2 and 4?

I see the manufacturer tutorial code has different values.

I think you have found the issue. A typical LCD has a buffer so line 1 and line 3 are basically one continuous memory segment and line 2 and 4 as a different location. This device is not like that

The LCD_SETDDRAMADDR constant is 0x80 (upper bit set) so to translate the tutorial line values

byte new_line[4] = {0x80, 0xA0, 0xC0, 0xE0};

into the addresses that the LiquidCrystal library wants, just set the upper bit to zero

0x80 = 1000 0000 --> 0000 0000 = 0x00
0xA0 = 1010 0000 --> 0010 0000 = 0x20
0xC0 = 1100 0000 --> 0100 0000 = 0x40
0xE0 = 1110 0000 --> 0110 0000 = 0x60

so edit your setCursor function

void LiquidCrystal::setCursor(uint8_t col, uint8_t row)
{
  //int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
  int row_offsets[] = { 0x00, 0x20, 0x40, 0x60 };
  if ( row > _numlines ) {
    row = _numlines-1;    // we count rows starting w/0
  }
 
  command(LCD_SETDDRAMADDR | (col + row_offsets[row]));
}

Many thanks, unfortunately I get the following error;

Arduino: 1.8.13 (Windows Store 1.8.42.0) (Windows 10), Board: "Arduino Leonardo"


libraries\LiquidCrystal\LiquidCrystal.cpp.o (symbol from plugin): In function `LiquidCrystal::setRowOffsets(int, int, int, int)':

(.text+0x0): multiple definition of `LiquidCrystal::setCursor(unsigned char, unsigned char)'

sketch\spi2par2019.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1

Error compiling for board Arduino Leonardo.

You have to edit the library - LiquidCrystal.cpp. That is where the function is defined.

Ok thanks, will try and do that.

Finally, unequivocally have it working perfectly.

It was a different command that needed an edit.

So thank you anyway.

For anyone. You have to edit the library else it won't work.

Bit of a palarver, but got there in the end.

karma to blh64 for the pointer & hex code conversion :slight_smile:

Now that you have gone to all that trouble... It would be better to just call that function after you initialize your display

void setup() {
  ...
  hd44780.begin(20, 4);
  hd44780.noCursor();
  hd44780.command(0x2A); // Set "RE"=1
  hd44780.command(0x06); // set BDC=0, BDS=0;
  hd44780.setRowOffsets(0x00, 0x20, 0x40, 0x60); 
  ...
}

That way, you can use the LiquidCrystal library as-is.

Well, yeah I could, but since I've done all that I'll just leave mine 'as is'. I could load up the original sketch again easily I suppose on another save in a different folder, with the original library as you say, then add the init. for the display.