Go Down

Topic: Adafruit ST7565 Display TG12864H3-05A + ST7565 library = problems (Read 1 time) previous topic - next topic

HDS

Hi, all,
Just have the ST7565 controlled monochrome LCD display TG12864H3-05A from Adafruit
http://www.adafruit.com/products/250
on the table and downloaded/installed their library from here:
https://github.com/adafruit/ST7565-LCD
I was not able to use adafruits turorial:
http://www.ladyada.net/learn/lcd/st7565.html
without further web search because the pinout of the delivered TG12864H3-05A differs from the one shown in the tutorial.
Datasheet: http://www.adafruit.com/datasheets/TG12864H3-05A%20EN_V1.0.pdf

Their code examples are running "quite ok" (despite their printing-the-font-chars-example  ;) ) in the setup,
but I had difficulties displaying chars incoming from the serial port in the loop,
until I changed their lib-code in the following drawchar procedure in two places:

(Original Code, ST7565.cpp, line 181ff:)
Code: [Select]
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);
}


Modified code:
Code: [Select]
void  ST7565::drawchar(uint8_t x, uint8_t line, uint8_t 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); //won't work
 updateBoundingBox(x-5, line*8, x, line*8 + 8);   //works well
}


Short explanation of the parameters:
- "x" is the pixel (horizontally, starting leftmost with zero ) where the character's bytes will be drawn verticaly like "|||||"
 with the most significant bit of the five bytes upmost.
- "line" is the line number (0 based) for 8 pixel high characters.
- "c" has been originaly been type "char", but represents only a number of a character in the font pixelmap (glcdfont.c)
and definitely MUST be a byte, otherwise with "char" above 127 you will get bullshit on your LCDscreen, when you want to display
special characters like the ° or € etc from your 256 x 5-byte font.

For your own characters or the modification of the existing 8x6 font dataset use:
https://github.com/pinsonn/st7565-designer

Now everything is fine, and the chars I type on the PC (including special chars)
are appearing on the display:

Sketch:

Code: [Select]
#include "ST7565.h"

int ledPin =  13;    // LED connected to digital pin 13

// the LCD backlight is connected up to a pin so you can turn it on & off
#define BACKLIGHT_LED 10

// pin 9 - Serial data out (SID)
// pin 8 - Serial clock out (SCLK)
// pin 7 - Data/Command select (RS or A0)
// pin 6 - LCD reset (RST)
// pin 5 - LCD chip select (CS)
ST7565 glcd(9, 8, 7, 6, 5);

#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH  16

uint8_t c=0 ;
uint8_t r=0 ;
uint8_t  q;


// The setup() method runs once, when the sketch starts
void setup()   {                
 Serial.begin(57600);
 Serial.print(freeRam());
 
 // turn on backlight
 pinMode(BACKLIGHT_LED, OUTPUT);
 digitalWrite(BACKLIGHT_LED, HIGH);

 // initialize and set the contrast to 0x18
 glcd.begin(0x18);

 glcd.clear();
 for (byte i=42; i<(42+(21*8)); i++){
   glcd.drawchar(c, r, i);
   //glcd.display();
   c+=6;
   if (c>125){
     c=0;
     r++;
     if (r>7){r=0;}
   }
 }
}

void loop() {  
 if (Serial.available()>0) {
   q=Serial.read();
   glcd.drawchar(c, r, q);
   glcd.display();
   c+=6;
   if (c>125){ //line feed before reaching Maxpixels-6
     c=0;
     r++;    
     if (r>7){r=0;} //restart in first line
   }
 }
}

// this handy function will return the number of bytes currently free in RAM, great for debugging!  
int freeRam(void)
{
 extern int  __bss_end;
 extern int  *__brkval;
 int free_memory;
 if((int)__brkval == 0) {
   free_memory = ((int)&free_memory) - ((int)&__bss_end);
 }
 else {
   free_memory = ((int)&free_memory) - ((int)__brkval);
 }
 return free_memory;
}


Took a bit of time to figure out, what was going wrong...
Maybe somebody phone with adafuit to have them correct their library?
I hate half-cooked dishes!  :~

:smiley-mr-green:

Joern



MarkT

I'm sure you could report this on their forum and link to this thread for the details - they are generally
pro-active in sorting out issues...
[ I won't respond to messages, use the forum please ]

Go Up