Pages: [1] 2 3   Go Down
Author Topic: SOLVED - unable to make it work 1.8 SPI TFT 128x160  (Read 14587 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi!

I've recently bought this on ebay:
http://www.ebay.com/itm/261081638769?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649



Unfortunately I'm unable make it work.
I've tried to do it while reading http://learn.adafruit.com/1-8-tft-display
however this obviously doesn't have the same pinout, but I was unable to find any example/hint for this PCB

I linked the VCC to the arduino 5V, so I didn't close JP1.
GND goes to GND
Reset:   PIN8
A0(???): PIN7
SDA:     PIN5
SCK:     PIN4
CS:       PIN6

Then installed the Adafruit_ST7735 library, uploaded the example, then nothing happened.

Please advise smiley-sad

Thanks,
DEx-
« Last Edit: October 01, 2012, 02:14:12 pm by DEx- » Logged

Leeds, UK
Offline Offline
Edison Member
*
Karma: 80
Posts: 1726
Once the magic blue smoke is released, it won't go back in!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

As this is a random board off ebay from China that has no documentation or published schematic, it is difficult to say.

There are two things that jump out.
1) SDA/SCK suggests I2C not SPI, so it may well not work with the adafruit library
2) If (1) is not the case and it is SPI, the adafruit version of the screen has a Data/Command pin (D/C). IF it is the same controller, it is possible that the pin labeled A0 could an equicavalent to the D/C pin, so you could try wiring that up to pin 7 (EDIT: I have just seen that you did, so clearly it is not).

You will need to supply more info about the screen. For example if it is possible to lift it off the board and take a picture of the back of the display and top of the board, it may help in finding more info.

EDIT: there is a link to the datasheet on the ebay page, along with some sample code, which although is not designed for arduino, it should be possible to convert it to work.
« Last Edit: September 30, 2012, 11:21:48 am by Tom Carpenter » Logged

~Tom~

Leeds, UK
Offline Offline
Edison Member
*
Karma: 80
Posts: 1726
Once the magic blue smoke is released, it won't go back in!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This is the example code. I have very quickly modified it to work with Arduino.

*Disclaimer* I didn't write this, and it needs a whole lot of optimisation (quite frankly it it awful coding), but at this point it would be good to know if the display works, and if this code works for the display. If it does, then I might be inclined to rewrite it for you.

Code:
const byte reset = 8;
const byte cs = 6;
const byte scl = 4;
const byte sda = 5;
const byte rs = 7;

void write_command(byte c){
  digitalWrite(cs,0);
  digitalWrite(rs,0);
  digitalWrite(sda,bitSet(c,7));
  digitalWrite(scl,0);
  digitalWrite(scl,1);
  digitalWrite(sda,bitSet(c,6));
  digitalWrite(scl,0);
  digitalWrite(scl,1);
  digitalWrite(sda,bitSet(c,5));
  digitalWrite(scl,0);
  digitalWrite(scl,1);
  digitalWrite(sda,bitSet(c,4));
  digitalWrite(scl,0);
  digitalWrite(scl,1);
  digitalWrite(sda,bitSet(c,3));
  digitalWrite(scl,0);
  digitalWrite(scl,1);
  digitalWrite(sda,bitSet(c,2));
  digitalWrite(scl,0);
  digitalWrite(scl,1);
  digitalWrite(sda,bitSet(c,1));
  digitalWrite(scl,0);
  digitalWrite(scl,1);
  digitalWrite(sda,bitSet(c,0));
  digitalWrite(scl,0);
  digitalWrite(scl,1);
  digitalWrite(cs,1);
}

void  write_data(byte d) {

  digitalWrite(cs,0);
  digitalWrite(rs,1);
  digitalWrite(sda,bitSet(d,7));
  digitalWrite(scl,0);
  digitalWrite(scl,1);
  digitalWrite(sda,bitSet(d,6));
  digitalWrite(scl,0);
  digitalWrite(scl,1);
  digitalWrite(sda,bitSet(d,5));
  digitalWrite(scl,0);
  digitalWrite(scl,1);
  digitalWrite(sda,bitSet(d,4));
  digitalWrite(scl,0);
  digitalWrite(scl,1);
  digitalWrite(sda,bitSet(d,3));
  digitalWrite(scl,0);
  digitalWrite(scl,1);
  digitalWrite(sda,bitSet(d,2));
  digitalWrite(scl,0);
  digitalWrite(scl,1);
  digitalWrite(sda,bitSet(d,1));
  digitalWrite(scl,0);
  digitalWrite(scl,1);
  digitalWrite(sda,bitSet(d,0));
  digitalWrite(scl,0);
  digitalWrite(scl,1);
  digitalWrite(cs,1);
}

void write_data(byte LCD_DataH,byte LCD_DataL)
{
  write_data(LCD_DataH);
  write_data(LCD_DataL);
}

void write_data(byte LCD_DataH,byte LCD_DataM,byte LCD_DataL)
{
  write_data(LCD_DataH);
  write_data(LCD_DataM);
  write_data(LCD_DataL);
}

void Reset()
{

  digitalWrite(reset,LOW);
  delay(100);
  digitalWrite(reset,HIGH);
  delay(100);
}
//////////////////////////////////////////////////////////////////////////////////////////////

void lcd_initial(){
  Reset();

  //------------------------------------------------------------------// 
  //-------------------Software Reset-------------------------------//
  //------------------------------------------------------------------//

  write_command(0x11);//Sleep exit
  delay (120);

  //ST7735R Frame Rate
  write_command(0xB1);
  write_data(0x01);
  write_data(0x2C);
  write_data(0x2D);
  write_command(0xB2);
  write_data(0x01);
  write_data(0x2C);
  write_data(0x2D);
  write_command(0xB3);
  write_data(0x01);
  write_data(0x2C);
  write_data(0x2D);
  write_data(0x01);
  write_data(0x2C);
  write_data(0x2D);

  write_command(0xB4); //Column inversion
  write_data(0x07);

  //ST7735R Power Sequence
  write_command(0xC0);
  write_data(0xA2);
  write_data(0x02);
  write_data(0x84);
  write_command(0xC1);
  write_data(0xC5);
  write_command(0xC2);
  write_data(0x0A);
  write_data(0x00);
  write_command(0xC3);
  write_data(0x8A);
  write_data(0x2A);
  write_command(0xC4);
  write_data(0x8A);
  write_data(0xEE);

  write_command(0xC5); //VCOM
  write_data(0x0E);

  write_command(0x36); //MX, MY, RGB mode
  write_data(0xC8);

  //ST7735R Gamma Sequence
  write_command(0xe0);
  write_data(0x0f);
  write_data(0x1a);
  write_data(0x0f);
  write_data(0x18);
  write_data(0x2f);
  write_data(0x28);
  write_data(0x20);
  write_data(0x22);
  write_data(0x1f);
  write_data(0x1b);
  write_data(0x23);
  write_data(0x37);
  write_data(0x00);

  write_data(0x07);
  write_data(0x02);
  write_data(0x10);
  write_command(0xe1);
  write_data(0x0f);
  write_data(0x1b);
  write_data(0x0f);
  write_data(0x17);
  write_data(0x33);
  write_data(0x2c);
  write_data(0x29);
  write_data(0x2e);
  write_data(0x30);
  write_data(0x30);
  write_data(0x39);
  write_data(0x3f);
  write_data(0x00);
  write_data(0x07);
  write_data(0x03);
  write_data(0x10); 

  write_command(0x2a);
  write_data(0x00);
  write_data(0x00);
  write_data(0x00);
  write_data(0x7f);
  write_command(0x2b);
  write_data(0x00);
  write_data(0x00);
  write_data(0x00);
  write_data(0x9f);

  write_command(0xF0); //Enable test command 
  write_data(0x01);
  write_command(0xF6); //Disable ram power save mode
  write_data(0x00);

  write_command(0x3A); //65k mode
  write_data(0x05);


  write_command(0x29);//Display on
}





void  RamAdressSet(){
  write_command(0x2A);
  write_data(0x00);
  write_data(0x00);
  write_data(0x00);
  write_data(0x7f);

  write_command(0x2B);
  write_data(0x00);
  write_data(0x00);
  write_data(0x00);
  write_data(0x9f);  
}

void dsp_single_colour(byte DH,byte DL)
{
  byte i,j;
  //RamAdressSet();
  for (i=0;i<160;i++){
    for (j=0;j<128;j++){
      write_data(DH,DL);
    }
  }
}

void PutPixel(unsigned int x_start,unsigned int y_start,unsigned int color)
{
  write_command(0x2a);
  write_data(x_start);
  write_data(0x5f);
  write_command(0x2b);
  write_data(y_start+0x34);
  write_data(0x7F);
  write_command(0x2c);
  write_data(color>>8);
  write_data(color&0xff);

}

void setup()
{
  // This code will only run once, after each powerup or reset of board
  lcd_initial();

}

void loop()
{
  static byte i = 0;
  i += 10;
  // This code loops consecutively
  delay(100);
  write_command(0x2C);
  dsp_single_colour(i,i);
}

Logged

~Tom~

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Tom, first of all thanks for your support. I didn't think that somebody will ever look so much into this.

Unfortunately the code you posted doesn't work either.
Am I wrong if I think, that connecting only the VCC should bright up the LCD already?
It just remains dark...

Shall I try to lift it off the PCB?

Thanks,
Logged

Leeds, UK
Offline Offline
Edison Member
*
Karma: 80
Posts: 1726
Once the magic blue smoke is released, it won't go back in!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Does the backlight come on?
Logged

~Tom~

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
SDA/SCK suggests I2C not SPI

The datasheet says 4-/3-wire spi, no mention of i2c. If it were truly i2c compliant, it would have used SCL / SDA. SDA can be used to mean serial data for spi. The datasheet you linked to has code to drive this lcd, written (poorly) for C51. It also follows the spi sequence as specified in the datasheet.

You can either port that C51 code to arduino (not difficult) or you can use the adafruit code. Or you can write your own: more fun.
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void write_command(byte c){
  digitalWrite(cs,0);
  digitalWrite(rs,0);
  digitalWrite(sda,bitSet(c,7));

I don't think bitSet() does what you had wanted - it sets the bit specified but doesn't return anything.

A simpler way would be this:

Code:
void write_command(byte c) {
  unsigned char mask = 0x80;
  digitalWrite(cs, 0);
  digitalWrite(rs, 0);
  do {
    digitalWrite(scl, 0);
    if (c & mask) digitalWrite(sda, 1);
    else digitalWrite(sda, 0);
    digitalWrite(scl, 1);
    mask = mask >> 1;
  } while (mask);
  digitalWrite(cs, 1);
}

Make similar changes to the other routines.

Most of the times, you will need to start with initialization routines to make sure that they conform to the datasheet.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Does the backlight come on?

No there is no backlight!
Is it already bad?
Logged

Leeds, UK
Offline Offline
Edison Member
*
Karma: 80
Posts: 1726
Once the magic blue smoke is released, it won't go back in!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

yup sorry, that was supposed to be bitRead(). I always get those mixed up. As I had said though that piece of code needs a complete rewrite, it was just a 2 minute port from the example to arduino.

If the backlight doesn't come on when power is applied, you may wan't to check your wiring to make sure everything is correct. One thing to note is that the backlight needs to be connected to between 3.0V and 3.3V
Logged

~Tom~

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nothing to be sorry about as we all make mistakes.

The bitSet() routine is said to return nothing so presummably it is prototyped as void. Yet digitalWrite() requires a value for its 2nd argument and I was curious as to why the compiler did not complain about that inconsistency.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If the backlight doesn't come on when power is applied, you may wan't to check your wiring to make sure everything is correct. One thing to note is that the backlight needs to be connected to between 3.0V and 3.3V

The wiring is o.k... at least the power smiley I can measure 5V between the VCC and GND with a multimeter on the pins of the PCB.
But actually I connected it to arduino 5V as the JP1 is open and according to the description in this case 5V must be supplied to the board.

I guess there is no separate pin for backlight and we are talking about the VCC...

Anyway, thanks guys for the sample codes I wouldn't try them out as long as this backlight issue is not solved...

Thanks,


Logged

Leeds, UK
Offline Offline
Edison Member
*
Karma: 80
Posts: 1726
Once the magic blue smoke is released, it won't go back in!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

There is a very distinct difference.

There are two pins labeled LED+ and LED-. These are for the backlights - LED+ goes to +3.3v, LED- goes to GND.
Logged

~Tom~

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There is a very distinct difference.

There are two pins labeled LED+ and LED-. These are for the backlights - LED+ goes to +3.3v, LED- goes to GND.

This sounds very logical, I'll try that at home, thanks!
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

"LED+ goes to +3.3v, LED- goes to GND."

I would put a resistor there, to get a sense of the forward voltage drop on the diode first.

Just to be safe.
Logged

Leeds, UK
Offline Offline
Edison Member
*
Karma: 80
Posts: 1726
Once the magic blue smoke is released, it won't go back in!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

There is a 100 ohm resistor on the PCB, unless I misread the schematic. I'll check.
« Last Edit: October 01, 2012, 11:41:21 am by Tom Carpenter » Logged

~Tom~

Pages: [1] 2 3   Go Up
Jump to: