eddieprice7
Posts: 9
Joined: Wed Dec 05, 2018 10:11 am

128x160 tft display

Tue Mar 19, 2019 9:50 am

I am using a small tft display to produce a mimic diagram for a model railway. It works fine except that I am confused as to where the display xy origin is situated and also which axis is 'x' and which is 'y'. At the moment the display is a mirror image of what I want. The display is of chinese origin and does not have a data sheet. Looking at the display there are 8 pins on the right hand side attached to a ribbon cable - this is the shorter side of the rectangle - presumable the 128 pixel side. Is this the x or y axis? It seems to use the ST7735 chip - is it possible to define which is the x-axis and which is the y-axis? When using the 'fill' variable in the 'draw.line' Python command the colour values seem to be BGR rather than RGB. Any information would be useful.

Eddie Price
ps. I am using a Raspberry Pi Zero W.
128x160 display.jpg
128x160 display.jpg (130.16 KiB) Viewed 889 times

dave j
Posts: 116
Joined: Mon Mar 05, 2012 2:19 pm

Re: 128x160 tft display

Tue Mar 19, 2019 4:39 pm

You haven't mentioned/linked to the library you are using which might help people answer. First of all, check if the library you are using has the ability to control display layout - it might already and you won't need the following:

If the display does use the ST7735 chip you can find the datasheet for it here.

If you look at the description of the MADCTL command (page 110) you'll see that you can control which coordinate is the long edge, which direction is for increasing coordinates and whether to use RGB or BGR order.

Somewhere in your library's display initialisation function it will write the value 0x36 followed by another byte. The 0x36 is the MADCTL command and the following byte is the parameter that controls the display layout. You can change this value to get the effect you want. I'd suggest changing one bit at a time - it helps keep track of which bit has what effect.

If the library has hard coded ideas about which is the long edge, etc. you might have to make further changes.

eddieprice7
Posts: 9
Joined: Wed Dec 05, 2018 10:11 am

Re: 128x160 tft display

Tue Mar 19, 2019 6:25 pm

Thanks for your reply. I am using the Adafruit libraries. I did look at the datasheet for the ST7735 but found it rather daunting, however your hint that the MADCTL command controls the axis orientation will allow me to concentrate my investigation.

rudiratlos
Posts: 132
Joined: Tue May 01, 2012 8:47 am

Re: 128x160 tft display

Tue Mar 19, 2019 9:43 pm

I'm using the same display with fbtft. It's a framebuffer /dev/fb1 where you can pass an orientation (like 270 degrees).
No need for direct access the hardware registers for the display itself.

eddieprice7
Posts: 9
Joined: Wed Dec 05, 2018 10:11 am

Re: 128x160 tft display

Wed Mar 20, 2019 6:45 pm

I had a look at fbtft, but it is more than I can manage at the moment. One problem is that I do not have a name for the display. It is a cheap Chinese copy of something.

I have found reference to MADCTL in the ST7735 datasheet on page 110 as mentioned above and also on Page 62 which shows graphically how changing 3 of the bits for MADCTL byte changes the orientation of the shape which is drawn on the display, but where do I find the code for the ST7735? My python code for producing the layout mimic diagram is stored in an examples on the Raspberry Pi SD, which is itself within the Python_ST7735 folder. There are copies of ST7735.py in the same folder, but changing MADCTL within this code has no effect on my display. Trouble is I do not fully understand how Python works.

Return to “Graphics programming”