i have an 1.8" st7735r screen i am using for a project the screen is quite old (approx 5 years or so) i am using the adafruit st7735 library (because its the only one i can find?!)
what i would like to know is how to send the actual byte commands to the display so i can shut the output buffer off while i update the ram buffer then turn the screen back on it makes it look better because you dont have to wqtch the buffer load you can blink on and off etc.
i tried to use the method from the library for write command and write data but arduino ide says that its a private function.kind of sloppy if you ask me to not have a method you can use in your programs to use the power save modes iof the screen. js. also the gamma settings in this library arent right and i cant experiment with them to get them right if i cant write commands to the screen.
this screen i had hard coded originally in picbasic, but ive only been in arduino for a year now and while the big things are easy the small things are often a pain.
this is the funtion form the adafruit code :
void Adafruit_ST7735::writecommand(uint8_t c) {
#if defined (SPI_HAS_TRANSACTION)
SPI.beginTransaction(mySPISettings);
#endif
*rsport &= ~rspinmask;
*csport &= ~cspinmask;
//Serial.print("C ");
spiwrite(c);
*csport |= cspinmask;
#if defined (SPI_HAS_TRANSACTION)
SPI.endTransaction();
#endif
}
void Adafruit_ST7735::writedata(uint8_t c) {
#if defined (SPI_HAS_TRANSACTION)
SPI.beginTransaction(mySPISettings);
#endif
*rsport |= rspinmask;
*csport &= ~cspinmask;
//Serial.print("D ");
spiwrite(c);
*csport |= cspinmask;
#if defined (SPI_HAS_TRANSACTION)
SPI.endTransaction();
#endif
}
this is my current working code
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
#include <EEPROM.h>
#include <DS1302RTC.h>
//#include <Time.h>
int tempPin = A0; // make variables// thermistor is at A0
int led =13; // led is at pin
float temp; // make a variable called temp
float settemp; // make a variable called temp
int swtu = 7; // switch up is at pin 7
int swtd = 6; // switch down is at pin 6
int rstatus = 0;
char cyear[2];
char cmonth[2];
char cday[2];
char chour[2];
char cminute[2];
char csecond[2];
char* timestamp[]={};
// For the breakout, you can use any 2 or 3 pins
// These pins will also work for the 1.8" TFT shield
#define TFT_CS 3
#define TFT_SCLK 4 // set these to be whatever pins you like!
#define TFT_MOSI 5 // set these to be whatever pins you like!
#define TFT_DC 6
#define TFT_RST 7 // you can also connect this to the Arduino reset // in which case, set this #define pin to 0!
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
DS1302RTC RTC(10, 11, 12);
void setup(void) {
Serial.begin(9600);
Serial.print("Hello! ST7735 TFT Test");
// Use this initializer if you're using a 1.8" TFT
tft.initR(INITR_GREENTAB); // initialize a ST7735S chip, black tab
// Use this initializer (uncomment) if you're using a 1.44" TFT
//tft.initR(INITR_144GREENTAB); // initialize a ST7735S chip, black tab
Serial.println("Initialized");
uint16_t time = millis();
tft.fillScreen(ST7735_BLACK);
time = millis() - time;
Serial.println(time, DEC);
delay(500);
tft.fillScreen(ST7735_BLACK);
pText("RTC activated", ST7735_WHITE, 1,1,1);
delay(500);
if (RTC.haltRTC()){
pText("Clock stopped!", ST7735_WHITE, 1,8,1);
}
else{
pText("Clock working.", ST7735_WHITE, 1,8,1);
}
if (RTC.writeEN()){
pText("Write allowed.", ST7735_WHITE, 1,17,1);
}
else{
pText("Write protected.", ST7735_WHITE, 1,17,1);
}
delay ( 2000 );
// Setup time library
pText("RTC Sync", ST7735_WHITE, 1,25,1);
setSyncProvider(RTC.get); // the function to get the time from the RTC
if(timeStatus() == timeSet){
pText(" Ok!", ST7735_WHITE, 1,33,1);
}
else{
pText(" FAIL!", ST7735_WHITE, 1,33,1);
}
pDateStamp(ST7735_WHITE, 1,41,1);
pTimeStamp(ST7735_WHITE, 1,49,1);
delay ( 5000 );
TFTClear();
StringStamp();
// large block of text
/*tft.fillScreen(ST7735_BLACK);
pText("Temp:", ST7735_WHITE, 0,2,2);
pText("120", ST7735_BLUE, 40,18,4);
pText("o", ST7735_WHITE, 113,18,1);
pText("F", ST7735_WHITE, 113,28,2);
pText("Set Temp:", ST7735_WHITE, 130,34,2);
pText("100", ST7735_RED, 40,70,4);
pText("o", ST7735_WHITE, 113,70,1);
pText("F", ST7735_WHITE, 113,80,2);
pText("ON", ST7735_GREEN, 40,110,4);
pText("OFF", ST7735_RED, 40,110,4);
*/
MainDisplay(128.06, 127.22, 1);
delay(1000);
}
void loop() {
setSyncProvider(RTC.get);
int tvalue = analogRead(tempPin); // make tvalue what ever we read on the tempPin
float millivolts= (tvalue/1024.0) * 5000;
float fahrenheit= millivolts/10;
float celsius= (fahrenheit - 32) * (5.0/9.0);
temp = fahrenheit;
settemp = EEPROM.read(1); // read the settemp on the eeprom
if ((settemp == 255) or (settemp == 0))
{
settemp = 70;
}
delay (250); // wait for the lcd to refresh every 250 milliseconds
if (digitalRead(swtu)== 1 )
{
settemp ++;
EEPROM.write (1,settemp);
}
if (digitalRead (swtd) == 1)
{
settemp --;
EEPROM.write (1,settemp);
}
if (temp < settemp) // if the temperature exceeds your chosen settemp
{
digitalWrite (led, 1); // turn on the led
rstatus = 1;
}
else // if that doesn't happen, then turn the led off
{
digitalWrite (led,0);
rstatus = 0;
}
StringStamp();
setSyncProvider(RTC.get);
MainDisplay(temp, settemp, rstatus);
delay (2000);
}
void pText(char *text, uint16_t color, int x, int y, int tSize) {
tft.setCursor(x, y);
tft.setTextSize(tSize);
tft.setTextColor(color);
tft.setTextWrap(true);
tft.print(text);
}
void pDateStamp(uint16_t color, int x, int y, int tSize) {
tft.setCursor(x, y);
tft.setTextSize(tSize);
tft.setTextColor(color);
tft.setTextWrap(true);
tft.print(month());
tft.print("/");
tft.print(day());
tft.print("/");
tft.print(year());
}
void pTimeStamp(uint16_t color, int x, int y, int tSize) {
tft.setCursor(x, y);
tft.setTextSize(tSize);
tft.setTextColor(color);
tft.setTextWrap(true);
tft.print(hour());
tft.print(":");
tft.print(minute());
tft.print(":");
tft.print(second());
}
void MainDisplay(float ctemp, float stemp, int offon) {
char ctemp1[8];
char stemp1[8];
dtostrf(ctemp, 3, 0, ctemp1);
dtostrf(stemp, 3, 0, stemp1);
// large block of text
TFTClear();
tft.fillRect(40,110,80,120, ST7735_BLACK);
pText("Temp:", ST7735_WHITE, 0,2,2);
pText(ctemp1, ST7735_BLUE, 40,18,4);
pText("o", ST7735_WHITE, 113,18,1);
pText("F", ST7735_WHITE, 113,28,2);
tft.fillRect(40,110,80,120, ST7735_BLACK);
pText("Set Temp:", ST7735_WHITE, 130,34,2);
pText(stemp1, ST7735_RED, 40,70,4);
pText("o", ST7735_WHITE, 113,70,1);
pText("F", ST7735_WHITE, 113,80,2);
if (offon == 1)
{
pText("ON", ST7735_GREEN, 40,110,4);
}
else {
pText("OFF", ST7735_RED, 40,110,4);
}
pDateStamp(ST7735_WHITE, 1,143,1);
pTimeStamp(ST7735_WHITE, 1,151,1);
}
void TFTClear() {
tft.fillScreen(ST7735_BLACK);
}
void StringStamp(){
dtostrf(year(), 2, 0, cyear);
dtostrf(month(), 2, 0, cmonth);
dtostrf(day(), 2, 0, cday);
dtostrf(hour(), 2, 0, chour);
dtostrf(minute(), 2, 0, cminute);
dtostrf(second(), 2, 0, csecond);
timestamp[0]={cday};
timestamp[1]={cmonth};
timestamp[2]={cyear};
timestamp[3]={chour};
timestamp[4]={cminute};
timestamp[5]={csecond};
}
its just a small test of a much larger project...