Flip text on ST7565
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- scott216
- Posts: 163
- Joined: Sun Apr 12, 2009 11:08 am
Flip text on ST7565
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?
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: Flip text on ST7565
We don't have a function for that in the ST7565 library. It could probably be done with some modifications to the setPixel function.
- scott216
- Posts: 163
- Joined: Sun Apr 12, 2009 11:08 am
Re: Flip text on ST7565
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.
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.
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: Flip text on ST7565
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
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
- scott216
- Posts: 163
- Joined: Sun Apr 12, 2009 11:08 am
Re: Flip text on ST7565
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?
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: Flip text on ST7565
It is only references in one place:
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.
Code: Select all
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);
}
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.
- scott216
- Posts: 163
- Joined: Sun Apr 12, 2009 11:08 am
Re: Flip text on ST7565
What were you thinking in regards to hacking setPixel?
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: Flip text on ST7565
Looks like "my_setpixel" is the one to hack:
You could add a test at the beginning:
Code: Select all
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));
}
Code: Select all
if (flipped)
{
x = LCDWIDTH - x;
y = LCDHEIGHT - y;
}
- scott216
- Posts: 163
- Joined: Sun Apr 12, 2009 11:08 am
Re: Flip text on ST7565
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: 163
- Joined: Sun Apr 12, 2009 11:08 am
Re: Flip text on ST7565
This worked with glcd.drawbitmap() but not with glcd.drawstring()adafruit_support wrote:Looks like "my_setpixel" is the one to hack:You could add a test at the beginning:Code: Select all
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)); }
Code: Select all
if (flipped) { x = LCDWIDTH - x; y = LCDHEIGHT - y; }
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: Flip text on ST7565
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.
- scott216
- Posts: 163
- Joined: Sun Apr 12, 2009 11:08 am
Re: Flip text on ST7565
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.adafruit_support wrote:It is only references in one place:Code: Select all
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 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.
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: Flip text on ST7565
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/
http://edeca.net/wp/electronics/the-st7 ... ontroller/
- scott216
- Posts: 163
- Joined: Sun Apr 12, 2009 11:08 am
Re: Flip text on ST7565
According to the edeca.net article, you can flip the display around by issuing two commands,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/
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?
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: Flip text on ST7565
That looks like an even easier method.
The command constants are defined in the .h file:
You should be able to send them using the st7565_command() function.
The command constants are defined in the .h file:
Code: Select all
#define CMD_SET_ADC_NORMAL 0xA0
#define CMD_SET_ADC_REVERSE 0xA1
#define CMD_SET_COM_NORMAL 0xC0
#define CMD_SET_COM_REVERSE 0xC8
Please be positive and constructive with your questions and comments.