ST7565 Display Help.

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
mountodinman
 
Posts: 4
Joined: Wed Jun 08, 2011 8:00 pm

ST7565 Display Help.

Post by mountodinman »

Hello. I'm trying to use the ST7565 graphical lcd for an alarm clock project. Currently, I have the date and time displayed on the first time of the lcd (shown below). However, if I try to move this line, or right another line, on a lower line, nothing shows up. I'm attempting to use the glcd.drawstring command, ie: glcd.drawstring(xposition, yposition, "string here"). My code:

Code: Select all

#include <SPI.h>
const int  cs=10; //chip select 

#include "ST7565.h"
// 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(A0, A1, A2, A3, A4);

//#define LOGO16_GLCD_HEIGHT 16 
//#define LOGO16_GLCD_WIDTH  16 

//declare array to be used to set time and date
int TimeDateArray[6]={0,0,0,0,0,0};

void setup() {
  Serial.begin(9600);
  RTC_init();
  //day(1-31), month(1-12), year(0-99), hour(0-23), minute(0-59), second(0-59)
  SetTimeDate(8,6,11,20,41,00); 
  //remove above after keypad successfully sets clock
  
  // initialize lcd and set the contrast to 0x18
  glcd.begin(0x18);
}

void loop() {
  //read time and date and convert to printable character array
  String timedate_string = ReadTimeDate(); //read in string of time and date
  char timedate_char[15]; //note: exact size is not important, it will fill as necessary
  timedate_string.toCharArray(timedate_char,15); //this converts string to character array
  
  //below is display shown every cycle
  glcd.clear();
  glcd.drawstring(0, 0, timedate_char);
  //glcd.fillrect(0, 0, 127, 7, 1);
  glcd.display();
  glcd.clear();
  delay(2000);
 }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//above ends the void loop function
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//=====================================
//function to initialize real time clock chip:
int RTC_init(){ 
	  pinMode(cs,OUTPUT); // chip select
	  // start the SPI library:
	  SPI.begin();
	  SPI.setBitOrder(MSBFIRST); 
	  SPI.setDataMode(SPI_MODE3); //mode 1 did not work, mode 3 did 
	  //set control register 
	  digitalWrite(cs, LOW);  
	  SPI.transfer(0x8E);
	  SPI.transfer(0x60); //60= disable Osciallator and Battery SQ wave @1hz, temp compensation, Alarms disabled
	  digitalWrite(cs, HIGH);
	  delay(10);
}
//=====================================
//function used to set time and date of RTC:
int SetTimeDate(int d, int mo, int y, int h, int mi, int s){ 
	int TimeDate [7]={s,mi,h,0,d,mo,y};
	for(int i=0; i<=6;i++){
		if(i==3)
			i++;
		int b= TimeDate[i]/10;
		int a= TimeDate[i]-b*10;
		if(i==2){
			if (b==2)
				b=B00000010;
			else if (b==1)
				b=B00000001;
		}	
		TimeDate[i]= a+(b<<4);
		  
		digitalWrite(cs, LOW);
		SPI.transfer(i+0x80); 
		SPI.transfer(TimeDate[i]);        
		digitalWrite(cs, HIGH);
  }
}
//=====================================
//function used to read time and date from RTC:
String ReadTimeDate(){
	String temp;
	int TimeDate [7]; //second,minute,hour,null,day,month,year		
	for(int i=0; i<=6;i++){
		if(i==3)
			i++;
		digitalWrite(cs, LOW);
		SPI.transfer(i+0x00); 
		unsigned int n = SPI.transfer(0x00);        
		digitalWrite(cs, HIGH);
		int a=n & B00001111;    
		if(i==2){	
			int b=(n & B00110000)>>4; //24 hour mode
			if(b==B00000010)
				b=20;        
			else if(b==B00000001)
				b=10;
			TimeDate[i]=a+b;
		}
		else if(i==4){
			int b=(n & B00110000)>>4;
			TimeDate[i]=a+b*10;
		}
		else if(i==5){
			int b=(n & B00010000)>>4;
			TimeDate[i]=a+b*10;
		}
		else if(i==6){
			int b=(n & B11110000)>>4;
			TimeDate[i]=a+b*10;
		}
		else{	
			int b=(n & B01110000)>>4;
			TimeDate[i]=a+b*10;	
			}
	}
	temp.concat(TimeDate[5]);
	temp.concat("/") ;
	temp.concat(TimeDate[4]);
	temp.concat("/") ;
	temp.concat(TimeDate[6]);
	temp.concat("  ") ;
        if(TimeDate[2]>12){
          TimeDate[2]=TimeDate[2]-12;
        }//removes military time
	temp.concat(TimeDate[2]);
	temp.concat(":") ;
        if(TimeDate[1] < 10){
          temp.concat("0");
        } //loop adds zero if minutes is single digit
	temp.concat(TimeDate[1]);
	//temp.concat(":") ;
	//temp.concat(TimeDate[0]);
        //above eliminates seconds
  return(temp);
}
Image

mountodinman
 
Posts: 4
Joined: Wed Jun 08, 2011 8:00 pm

Re: ST7565 Display Help.

Post by mountodinman »

I might have a working method. I tried using hexadecimal for the vertical reference for some odd reason, and it seems to be working.

ie:
glcd.drawstring(0, 0x0000, "line 1 here");
glcd.drawstring(0, 0x0001, "line 2 here");
glcd.display();

User avatar
jkcbwpnet
 
Posts: 92
Joined: Wed Aug 10, 2011 1:37 pm

Re: ST7565 Display Help.

Post by jkcbwpnet »

i just got my ST7565 a few days ago. I have made some real basic menu code thanks to your post. I was having a problem figuring out the deal with the y... After reading your post I looked closer to the code for testdrawchar();

Code: Select all

void testdrawchar(void) {
  for (uint8_t i=0; i < 168; i++) {
    glcd.drawchar((i % 21) * 6, i/21, i);
  }    
}
I found you could write 8 rows after applying your code 0x0000...0x0007
so since the screen is 64px high and 168/21 (i/21) = 8

it would appear that y-position is actually "row number" row0 at the top row7 at the bottom. you dont have to use 0x0003 for example, you can just use 3.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”