Flip text on ST7565
Moderators: adafruit_support_bill, adafruit

Flip text on ST7565

by Scott216 on Wed Jan 23, 2013 1:40 am

I have the ST7565 LCD and I'd like to be able to flip the text so you can read it as if the display was upside down. Is there a function in the library for this?
Scott216
 
Posts: 142
Joined: Sun Apr 12, 2009 11:08 am
Location: New Jersey

Re: Flip text on ST7565

by adafruit_support_bill on Wed Jan 23, 2013 7:46 am

We don't have a function for that in the ST7565 library. It could probably be done with some modifications to the setPixel function.
User avatar
adafruit_support_bill
 
Posts: 30887
Joined: Sat Feb 07, 2009 10:11 am

Re: Flip text on ST7565

by Scott216 on Wed Jan 23, 2013 9:34 am

What about creating a second font table where the letters are upside down. I could generate the table with http://microintegrate.com/?/fontgen, but I don't know if there is a way to switch between these two tables.

I'm using the display for a hot tub controller I'm building with an Arduino Mega. If you are in the hot tub, I want to display to be right side up, if you are outside the hot tub I want it upside down.
Scott216
 
Posts: 142
Joined: Sun Apr 12, 2009 11:08 am
Location: New Jersey

Re: Flip text on ST7565

by adafruit_support_bill on Wed Jan 23, 2013 9:45 am

Two font tables would probably work, although it would consume a lot of memory.

You may also want to look into some of our newer displays that have GFX library support. GFX has direct support for rotating the display:
http://learn.adafruit.com/adafruit-gfx- ... he-display
User avatar
adafruit_support_bill
 
Posts: 30887
Joined: Sat Feb 07, 2009 10:11 am

Re: Flip text on ST7565

by Scott216 on Wed Jan 23, 2013 10:06 am

Maybe in my next version I'll switch displays. I made a PCB that supports this display. I think I've got plenty of memory in my Mega for another font table. How would I go about switching between the two?
Scott216
 
Posts: 142
Joined: Sun Apr 12, 2009 11:08 am
Location: New Jersey

Re: Flip text on ST7565

by adafruit_support_bill on Wed Jan 23, 2013 10:17 am

It is only references in one place:
Code: Select all | TOGGLE FULL SIZE
void ST7565::drawchar(uint8_t x, uint8_t line, char c) {
  for (uint8_t i =0; i<5; i++ ) {
    st7565_buffer[x + (line*128) ] = pgm_read_byte(font+(c*5)+i);
    x++;
  }

  updateBoundingBox(x, line*8, x+5, line*8 + 8);
}


So it should be fairly straightforward to set a "flipped" flag and test for it.

Keep in mind that flipping the font is only half the problem. You will need to write the text right to left & bottom to top too. Might be easier just to hack setPixel.
User avatar
adafruit_support_bill
 
Posts: 30887
Joined: Sat Feb 07, 2009 10:11 am

Re: Flip text on ST7565

by Scott216 on Wed Jan 23, 2013 11:09 am

What were you thinking in regards to hacking setPixel?
Scott216
 
Posts: 142
Joined: Sun Apr 12, 2009 11:08 am
Location: New Jersey

Re: Flip text on ST7565

by adafruit_support_bill on Wed Jan 23, 2013 11:18 am

Looks like "my_setpixel" is the one to hack:
Code: Select all | TOGGLE FULL SIZE
void ST7565::my_setpixel(uint8_t x, uint8_t y, uint8_t color) {
  if ((x >= LCDWIDTH) || (y >= LCDHEIGHT))
    return;

  // x is which column
  if (color)
    st7565_buffer[x+ (y/8)*128] |= _BV(7-(y%8));
  else
    st7565_buffer[x+ (y/8)*128] &= ~_BV(7-(y%8));
}


You could add a test at the beginning:

Code: Select all | TOGGLE FULL SIZE
  if (flipped)
  {
    x = LCDWIDTH - x;
    y = LCDHEIGHT - y;
  }
User avatar
adafruit_support_bill
 
Posts: 30887
Joined: Sat Feb 07, 2009 10:11 am

Re: Flip text on ST7565

by Scott216 on Wed Jan 23, 2013 12:39 pm

Thanks for the help. I'll try my_setpixel changes and see if it works. That's a much simpler solution then separate font tables and writing backwards.
Scott216
 
Posts: 142
Joined: Sun Apr 12, 2009 11:08 am
Location: New Jersey

Re: Flip text on ST7565

by Scott216 on Wed Jan 23, 2013 7:51 pm

adafruit_support wrote:Looks like "my_setpixel" is the one to hack:
Code: Select all | TOGGLE FULL SIZE
void ST7565::my_setpixel(uint8_t x, uint8_t y, uint8_t color) {
  if ((x >= LCDWIDTH) || (y >= LCDHEIGHT))
    return;

  // x is which column
  if (color)
    st7565_buffer[x+ (y/8)*128] |= _BV(7-(y%8));
  else
    st7565_buffer[x+ (y/8)*128] &= ~_BV(7-(y%8));
}


You could add a test at the beginning:

Code: Select all | TOGGLE FULL SIZE
  if (flipped)
  {
    x = LCDWIDTH - x;
    y = LCDHEIGHT - y;
  }


This worked with glcd.drawbitmap() but not with glcd.drawstring()
Scott216
 
Posts: 142
Joined: Sun Apr 12, 2009 11:08 am
Location: New Jersey

Re: Flip text on ST7565

by adafruit_support_bill on Thu Jan 24, 2013 6:35 am

It looks like drawChar draws directly to the display buffer without using drawpixel. So you would need to invert the coordinates inside drawChar as well.
User avatar
adafruit_support_bill
 
Posts: 30887
Joined: Sat Feb 07, 2009 10:11 am

Re: Flip text on ST7565

by Scott216 on Fri Jan 25, 2013 9:49 am

adafruit_support wrote:It is only references in one place:
Code: Select all | TOGGLE FULL SIZE
void ST7565::drawchar(uint8_t x, uint8_t line, char c) {
  for (uint8_t i =0; i<5; i++ ) {
    st7565_buffer[x + (line*128) ] = pgm_read_byte(font+(c*5)+i);
    x++;
  }

  updateBoundingBox(x, line*8, x+5, line*8 + 8);
}




I'm trying to figure out how this is working. So I think the st7565_buffe[] is just a long array where each element corresponds to a pixel. So if st7565_buffe[0] = 1, then the top-left most pixel would be on. If st7565_buffe[128] =1, that's the beginning of the next row of pixels, so the pixel below the top-left would be on.

I assume pgm_read_byte[] is reading one byte from the font table. But this is where I'm staring to have trouble understanding how the bits are going into st7565_buffer[]. It looks to me like the first loop of i the program would put 8 bits into the display, all on the same row. Then the next loop of i would put 8 more bits right below the first row. And so on for 5 rows. But 5 rows is not enough to build a character on the display. Do I have things sideways? Also, since the for loop goes 5 times, then I assume it takes 5 bytes in the font table to display one letter.
Scott216
 
Posts: 142
Joined: Sun Apr 12, 2009 11:08 am
Location: New Jersey

Re: Flip text on ST7565

by adafruit_support_bill on Fri Jan 25, 2013 10:03 am

The memory layout of the ST7565 is optimized for displaying characters on 8-pixel line boundaries. You are writing 8 pixels at a time vertically with each byte. See the screen layout section of this tutorial:
http://edeca.net/wp/electronics/the-st7 ... ontroller/
User avatar
adafruit_support_bill
 
Posts: 30887
Joined: Sat Feb 07, 2009 10:11 am

Re: Flip text on ST7565

by Scott216 on Fri Jan 25, 2013 12:22 pm

adafruit_support wrote:The memory layout of the ST7565 is optimized for displaying characters on 8-pixel line boundaries. You are writing 8 pixels at a time vertically with each byte. See the screen layout section of this tutorial:
http://edeca.net/wp/electronics/the-st7 ... ontroller/


According to the edeca.net article, you can flip the display around by issuing two commands,
Flip horizontally with "ADC Select" command.
Flip vertically with "COM Output Mode Select" command

Any idea how I could send these commands to the display?
Scott216
 
Posts: 142
Joined: Sun Apr 12, 2009 11:08 am
Location: New Jersey

Re: Flip text on ST7565

by adafruit_support_bill on Fri Jan 25, 2013 12:35 pm

That looks like an even easier method.

The command constants are defined in the .h file:

Code: Select all | TOGGLE FULL SIZE
#define CMD_SET_ADC_NORMAL 0xA0
#define CMD_SET_ADC_REVERSE 0xA1

#define CMD_SET_COM_NORMAL 0xC0
#define CMD_SET_COM_REVERSE 0xC8


You should be able to send them using the st7565_command() function.
User avatar
adafruit_support_bill
 
Posts: 30887
Joined: Sat Feb 07, 2009 10:11 am