Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New 1.8 Inch LCD, Works partial with Hack, but still problems. #156

Closed
acpadhi opened this issue Sep 21, 2014 · 15 comments
Closed

New 1.8 Inch LCD, Works partial with Hack, but still problems. #156

acpadhi opened this issue Sep 21, 2014 · 15 comments

Comments

@acpadhi
Copy link

acpadhi commented Sep 21, 2014

I have got a 1.8 LCD which is supposed to be ST7735S if that controller actually exists.
I downloaded the precompiled image which allows dynamic loadable modules for different displays.

With the Arduino Code that came with it, it just worked fine. I have attached a link to the COde from Arduino that works well.

This is a Tiny LCD module. The only driver that exists in FBTFT for tinylcd modules is the one which is 3.5 inch one. So I tried to use the same and Bingo, I got it working . YAY !!! used the command below to actually get it working :

sudo modprobe fbtft_device custom name=fb_tinylcd buswidth=8 speed=32000000 width=128 height=160 gpios=reset:25,dc:24,led:18 rotate=90

Above command makes the screen blank confirming the initialization working fine. Please note how I am sending width and height params to make the driver work with the smaller resolution.

and then

sudo con2fbmap 1 1
Above command Starts the terminal on the LCD. and I can do everything as usual of course with very little space.

Everything works well except the following :

  1. Colors are Swapped - Red colors become Blue and Blues become Red.
  2. Contrast does not seem that good, the Performance Video sample MPEG plays, however colors look washed out lacking contrast completely. I tried sending PWM using wiring command and I could control the back light birghntess, but contrast seems pretty bad, specially when playing videos or showing images using fbi.

I think this is a RGB vs BGR issue. I assume the 3.5 Display is BGR and this one probably expects RGB. Most likely BGR(color space) is hard coded in the driver and hence sending params in module load function do not work.

Sending either bgr=1 or bgr=0 in the module load initialization command do not put any difference.

I looked at the driver code within FBTFT tinylcd driver and also compared it to the Arduino code that shows colors properly. Here are my findings.

Arduino and working commands :
LCD_Write_COM(0x36); //MX, MY, RGB mode
LCD_Write_DATA(0xC0);

FBTFT 3.5 tinylcd driver commands :
write_reg(par, 0x36, 0x58); // There is no comment in this driver, so I assume this is the one that must be sending the RGB/BGR modes and which is hard coded I think.

I am requesting someone who is expert at internal details to generate a modprobe command using the arduino code so that I can test this LCD to be working well with proper colors. I am sure, it should be quite simple for someone who is expert at this.

Here is the link to the complete arduino code that works pretty well.
http://transworldsoft.net/raspberry/lcd/initlcd.h

Code to tinylcd 3.5 inch can be seen in code section in this repo, or you can check the link below too.
http://transworldsoft.net/raspberry/lcd/fb_tinylcd.c

I will be thankful is someone can send me the init code that I can use to send the proper init codes as per the arduino header above. Request you to please provide a complete command that I can run on the shell.

I tried to generate it myself, however, it just went above my head.

@acpadhi
Copy link
Author

acpadhi commented Sep 21, 2014

BTW :

Thanks a lot to the developer(s) of FBTFT. Amazing job.
Also, Thanks tinylcd.com for creating affordable and good products.

MPG sample play, whether someone believes it or not, is close to 20 to 25 FPS, which should be sufficient to play normal videos. So great job Tinylcd and FBTFT.

This is my first Color LCD integration to any Embedded device, and I was thrilled to see it working without a lot of hard work. Even though the colors are swapped, I think, it is still a good thing to be able to get it to this stage and have a terminal running on it.

@acpadhi
Copy link
Author

acpadhi commented Sep 21, 2014

Actually it could be this section :

Working good - Arduino Code :
LCD_Write_COM(0x3a);
LCD_Write_DATA(0x05);

Colors Swapped - FBTFT Driver code :
write_reg(par, 0x3A, 0x55); // Seems driver does not accept this parameter at all from load module command

@notro
Copy link
Owner

notro commented Sep 23, 2014

Conversion of the Arduino code

ST7735S:

-1,0x11,
-2,120,

-1,0xB0,0x80,
-1,0xC0,0x0F,0x0F,
-1,0xC1,0x45,0xff,
-1,0xC2,0x33,
-1,0xC5,0x00,0x42,0x80,
-1,0xB1,0xD0,0x11,
-1,0xB4,0x02,
-1,0x36,0xC0,
-1,0x35,0xfa,
-1,0x3a,0x05,
-1,0xE5,0x8F,
-1,0xE5,0x01,
-1,0xB3,0x00,
-1,0xE5,0x00,
-1,0x3A,0x55,

-1,0x11,
-2,250,
-1,0x29,

# I'm not sure about this one, where does this comment end?
/*LCD_Write_COM(0xB1); 
-1,0xB1,0x05,0x3C,0x3C,

-1,0xB2,0x05,0x3C,0x3C,
-1,0xB3,0x05,0x3C,0x3C,0x05,0x3C,0x3C,
-1,0xB4,0x03,

-1,0xC0,0x28,0x08,0x04,
-1,0xC1,0xC0,
-1,0xC2,0x0D,0x00,
-1,0xC3,0x8D,0x2A,
-1,0xC4,0x8D,0xEE,
-1,0xC5,0x1A,

-1,0x36,0xC0,

-1,0xE0,0x03,0x22,0x07,0x0A,0x2E,0x30,0x25,0x2A,0x28,0x26,0x2E,0x3A,0x00,0x01,0x03,0x13,
-1,0xE1,0x04,0x16,0x06,0x0D,0x2D,0x26,0x23,0x27,0x27,0x25,0x2D,0x3B,0x00,0x01,0x04,0x13,
-1,0x3A,0x05,
-1,0x29,

#end of sequence
-3

All in one line

sudo modprobe fbtft_device custom name=fb_tinylcd buswidth=8 speed=32000000 width=128 height=160 gpios=reset:25,dc:24,led:18 rotate=90 init=-1,0x11,-2,120,-1,0xB0,0x80,-1,0xC0,0x0F,0x0F,-1,0xC1,0x45,0xff,-1,0xC2,0x33,-1,0xC5,0x00,0x42,0x80,-1,0xB1,0xD0,0x11,-1,0xB4,0x02,-1,0x36,0xC0,-1,0x35,0xfa,-1,0x3a,0x05,-1,0xE5,0x8F,-1,0xE5,0x01,-1,0xB3,0x00,-1,0xE5,0x00,-1,0x3A,0x55,-1,0x11,-2,250,-1,0x29,-1,0xB1,0x05,0x3C,0x3C,-1,0xB2,0x05,0x3C,0x3C,-1,0xB3,0x05,0x3C,0x3C,0x05,0x3C,0x3C,-1,0xB4,0x03,-1,0xC0,0x28,0x08,0x04,-1,0xC1,0xC0,-1,0xC2,0x0D,0x00,-1,0xC3,0x8D,0x2A,-1,0xC4,0x8D,0xEE,-1,0xC5,0x1A,-1,0x36,0xC0,-1,0xE0,0x03,0x22,0x07,0x0A,0x2E,0x30,0x25,0x2A,0x28,0x26,0x2E,0x3A,0x00,0x01,0x03,0x13,-1,0xE1,0x04,0x16,0x06,0x0D,0x2D,0x26,0x23,0x27,0x27,0x25,0x2D,0x3B,0x00,0x01,0x04,0x13,-1,0x3A,0x05,-1,0x29,-3

bgr= isn't supported with fb_tinylcd as it was made for an unknown controller on a display (the seller won't disclose this information.).

Register 0x36 usually sets BGR/RGB and the direction in which the RAM is scanned out to the display. Used to control rotation.
Dull colors can be fixed by changing the gamma curves (E0h/E1h).

@acpadhi
Copy link
Author

acpadhi commented Sep 23, 2014

Cool, SO happy to get a quick response.

My First Try returned in the same result with the colors swapped. There is even now another problem with the init code you provided.

The Rotation does not work well.
In Landscape View :
Rotate 90, makes the screen upside down in landscape mode.
Rotate 270, exactly mirrors the screen of the Rotate 90 output.

Pretty weird.

I will keep trying sending different parameters and check it out today. Will you be able to tell if this display is 8Bit or 9Bit from looking at the Arduino Code ?

If you want, I can post the entire arduino code that actually works well with this display. Or if you can share your email address, I can send it to you by email, Anyway, we can send private messages in GIThub ?

@notro
Copy link
Owner

notro commented Sep 23, 2014

You have to read the datasheet to get this right.
Register 0x36 bit 3 control BGR/RGB on the ST7735R.
3 or 4-line SPI is on the ST7735R at least, decided by the SPI4W mode pin on the controller.
But since you have a D/C pin and you get it to work, it has to be 4-line SPI (SCLK,MOSI,CS and D/C)

@acpadhi
Copy link
Author

acpadhi commented Sep 23, 2014

Hi Notro,

Thanks for the quick response.
If I was experienced enough to comprehend the Datasheets code, I could have probably take one of the existing Arduino code and ported it for FBTFT myself. Alas, that is not the case.

So What I am going to do is spend whatever time I can afford on this and keep this post updated with my findings.

There has to be a way for this to work since it works fine on the Arduino. All code of Arduino is Open and in readable form.

I do not believe if making accessories that are exclusively for Arduino or Raspberry Pi. When the protocols are same, the pins' purposes are same, leaving apart the logic voltage (3.3 and 5V) , everything else being same, it can and should be made to work on the Pi and still be as efficient if not more than the Arduino and obviously without hacks of any kind.

I am from India, and we do not get the regular Adafruit and Sparkfun stuff easily, even if we import or get through someone who has imported, they are far from being affordable.

So we have no other way than to depend on these chinese products unfortunately.

TinyLcd products are the only ones I can vouch being the cheapest anywhere you could source online. Their Customer support is also very friendly on the Phone (at least the people who are in India).

Not disclosing the controller is surely their own choice for their business interests and we cannot force them for the same. They will soon realize that Disclosing the details can only result in far better sales, but I would leave it for their management to decide on that.

What you have done so far is just astounding indeed, Getting so many of these beasty and elusive various LCDs working all under one roof. That is truely commendable ! We need more people like you.

Summarizing, This 1.8 Inch LCD needs to work on the FBTFT platform. It is the most affordable to get going on the Raspberry Pi with an LCD. I am going to keep finding info and look for info in forums to get this working.

In the meantime, I request you not to close this issue at least for a few days so that it draws a little but of whatever attention it deserves.

Regards,

@acpadhi
Copy link
Author

acpadhi commented Sep 23, 2014

From my Findings, so far, I can say, this may not work based on the 7735 codebase.
What is the 3.5 one based on that you have written and works well ?

@acpadhi
Copy link
Author

acpadhi commented Sep 23, 2014

Hi Notro,

From your first reply about asking where the comment was ending :
LCD_Write_COM(0x29);//Display on*/ - it ends in this line.

I have an updated link that you can refer to here with the commented areas removed so that you could check if the init strings were right in your reply.

http://transworldsoft.net/raspberry/lcd/initlcd_comments_removed.h

I think the init string that you posted, will need to be changed again. I will keep trying and posting updates here.

Thanks

@acpadhi
Copy link
Author

acpadhi commented Sep 23, 2014

Hi Notro,

Excellent Work, thanks for guiding me so far.

With a little bit of fiddling around, and then changing the init code to remove the additional characters which were in comment, it worked.

YAY !!!


sudo modprobe fbtft_device custom name=fb_st7735r buswidth=8 speed=32000000 width=128 height=160 gpios=reset:25,dc:24,led:18 rotate=90   init=-1,0x11,-2,120,-1,0xB0,0x80,-1,0xC0,0x0F,0x0F,-1,0xC1,0x45,0xff,-1,0xC2,0x33,-1,0xC5,0x00,0x42,0x80,-1,0xB1,0xD0,0x11,-1,0xB4,0x02,-1,0x36,0xC0,-1,0x35,0xfa,-1,0x3a,0x05,-1,0xE5,0x8F,-1,0xE5,0x01,-1,0xB3,0x00,-1,0xE5,0x00,-1,0x3A,0x55,-1,0x11,-2,250,-1,0x29,-3; 

and then run :
sudo con2fbmap 1 1 - viola - terminal on tinylcd.

any idea how, the fonts can be made smaller ? this is such a tiny screen, that the prompt itself takes almost all the width. Please guide how I can make those fonts smaller.

Also, please do not close this thead yet. I am going to run a few tests and see how video, images etc go and what framerates I can achieve including the contrast quality. Contrast looks good now, but need to check how it looks in videos.

@acpadhi
Copy link
Author

acpadhi commented Sep 23, 2014

HI Notro,

I was wrong about the contrast in my success message above.

The colors seems to be working well and red and blue are in their correct place.
However, everything looks washed out as if there is a lot of brightness applied. I am sure it would be the contrast, unless otherwise you think different. Background color in terminal is also on brigher side, confirming, the blacks are not proper blacks. I tried adjusting the BL with PWM and Wiring, however, the results are the same.

The overall brightness reduces, but contrast is still poor.

I think I must be getting between 18 to 22 frames from what I can observe, will measure later when the contrast issue is fixed.

Any ideas, how the contrast could be made better ? Any changes to the init string help it ? If so, please help in providing the suitable register part and possible Values that I could try with.

@acpadhi
Copy link
Author

acpadhi commented Sep 23, 2014

Another Query,

Is there a way to find out the sequence of init commands a driver sends in default mode ? Any special debug flag or mode that can be called from command line or checked in dmesg ?

@acpadhi
Copy link
Author

acpadhi commented Sep 23, 2014

cat /sys/class/graphics/fb1/gamma shows :

000f 001a 000f 0018 002f 0028 0020 0022 001f 001b 0023 0037 0000 0007 0002 0010
000f 001b 000f 0017 0033 002c 0029 002e 0030 0030 0039 003f 0000 0007 0003 0010

But I do not know how to use that information in the command line and pass them to the init command.

Can someone please translate above info into a suitable gamma=xxxxx parameter so that I can check with the modprobe command

@notro
Copy link
Owner

notro commented Sep 23, 2014

Is there a way to find out the sequence of init commands a driver sends in default mode ?

debug=$((1<<21))

https://github.com/notro/fbtft/wiki/Debug

This is the default gamma curve from the fb_st7735r:

#define DEFAULT_GAMMA "0F 1A 0F 18 2F 28 20 22 1F 1B 23 37 00 07 02 10\n" \
                      "0F 1B 0F 17 33 2C 29 2E 30 30 39 3F 00 07 03 10"

This is the arduino gamma curve converted to something fbtft can understand:

gamma=0x03,0x22,0x07,0x0A,0x2E,0x30,0x25,0x2A,0x28,0x26,0x2E,0x3A,0x00,0x01,0x03,0x13;0x04,0x16,0x06,0x0D,0x2D,0x26,0x23,0x27,0x27,0x25,0x2D,0x3B,0x00,0x01,0x04,0x13

More info: https://github.com/notro/fbtft/wiki/Gamma

@acpadhi
Copy link
Author

acpadhi commented Sep 23, 2014

Thank you so much for such quick replies, You are a gem already for all of us.

I am going to probe more, will keep doing it till I get it working without a flaw like other devices. Shall keep this post updated as I find more info.

@notro
Copy link
Owner

notro commented Dec 26, 2014

Closing issue since there has been no activity for more than 2 months. Reopen if needed.

@notro notro closed this as completed Dec 26, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants