texy
Forum Moderator
Forum Moderator
Posts: 5174
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

1.8 TFT LCD add-on shield board

Mon Apr 15, 2013 7:21 pm

Hi,
this seems as good a place as any to announce my new add-on shield TFT board :
Image

You'll need to compile the kernel and modules to enable the fb1 framebuffer, as outlined in Mark's excellent blog here :
http://marks-space.com/2012/11/23/raspberrypi-tft/

Many thanks to Kamal Mostafa for sharing his code : http://www.whence.com/rpi/

Purchase details can be found here :
http://www.raspberrypi.org/phpBB3/viewt ... 59&t=40674

Sample test python code :

Code: Select all

# 1.8" TFT test prog
# v1 11/4/13

import wiringpi2 as wiringpi
from subprocess import call
import pygame, sys, os, time
from pygame.locals import *
os.environ["SDL_FBDEV"] = "/dev/fb1"

IN = OFF = 0
OUT = ON = 1
PUD_DOWN = 1

UP  = 13     # gpio pin 21 = UP
DOWN  = 2    # gpio pin 13 = DOWN
SELECT  = 11 # gpio pin 26 = LEFT

pygame.init()

# set up the window
DISPLAYSURF = pygame.display.set_mode((128, 160), 0, 32)
pygame.mouse.set_visible(0)
pygame.display.set_caption('Drawing')

# set up the colors
BLACK = (  0,   0,   0)
WHITE = (255, 255, 255)
RED   = (255,   0,   0)
GREEN = (  0, 255,   0)
BLUE  = (  0,   0, 255)

# draw on the surface object
DISPLAYSURF.fill(BLACK)
print "black"
time.sleep(.5)
pygame.display.update()

DISPLAYSURF.fill(RED)
print "red"
time.sleep(.5)
pygame.display.update()

DISPLAYSURF.fill(GREEN)
print "green"
time.sleep(.5)
pygame.display.update()

DISPLAYSURF.fill(BLUE)
print "blue"
time.sleep(.5)
pygame.display.update()

DISPLAYSURF.fill(WHITE)
print "white"
time.sleep(.5)
pygame.display.update()

# demo draw some shapes
pygame.draw.polygon(DISPLAYSURF, GREEN, ((16, 0), (111, 106), (36, 277), (56, 27), (0, 106)))
pygame.draw.line(DISPLAYSURF, BLUE, (60, 60), (120, 60), 4)
pygame.draw.line(DISPLAYSURF, BLUE, (120, 60), (60, 120))
pygame.draw.line(DISPLAYSURF, BLUE, (60, 120), (120, 120), 4)
pygame.draw.circle(DISPLAYSURF, BLUE, (40, 50), 20, 0)
pygame.draw.ellipse(DISPLAYSURF, RED, (110, 200, 40, 80), 1)
pygame.draw.rect(DISPLAYSURF, RED, (100, 150, 100, 50))
pygame.display.update()
time.sleep(.5)

#player movie
#sudo mplayer -vo fbdev2:/dev/fb1 -x 128 -y 160 -zoom VfE_html5.mp4
call(["mplayer", "-vo", "fbdev2:/dev/fb1", "-x", "128", "-y", "160", "-zoom", "VfE_html5.mp4"])

#set up the gpio's for the 3 buttons
wiringpi.wiringPiSetup()
for pin in [UP, DOWN, SELECT]:
  wiringpi.pinMode(pin, IN) # set to input
  wiringpi.pullUpDnControl(pin, PUD_DOWN) # enable pull down resistor

# run the game loop
while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
    input_value1 = wiringpi.digitalRead(UP)
    input_value2 = wiringpi.digitalRead(DOWN)
    input_value3 = wiringpi.digitalRead(SELECT)
    if input_value1 == True:
         font = pygame.font.Font(None, 36)
         text = font.render("UP", 1, RED)
         textpos = text.get_rect(centerx=DISPLAYSURF.get_width()/2)
         DISPLAYSURF.blit(text, textpos)
         pygame.display.update()
    elif input_value2 == True:
         font = pygame.font.Font(None, 36)
         text = font.render("DOWN", 1, GREEN)
         textpos = text.get_rect(centerx=DISPLAYSURF.get_width()/2)
         DISPLAYSURF.blit(text, textpos)
         pygame.display.update()
    elif input_value3 == True:
         font = pygame.font.Font(None, 36)
         text = font.render("SELECT", 1, BLUE)
         textpos = text.get_rect(centerx=DISPLAYSURF.get_width()/2)
         DISPLAYSURF.blit(text, textpos)
         pygame.display.update()
    else:
         DISPLAYSURF.fill(WHITE)
         pygame.display.update()

    print "UP = ",input_value1
    print "DOWN = ",input_value2
    print "SELECT = ",input_value3
    time.sleep(.5)
(you'll need to have wiringpi2 installed to run it)/
Cheers,
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

notro
Posts: 755
Joined: Tue Oct 16, 2012 6:21 pm
Location: Drammen, Norway

Re: 1.8 TFT LCD an-board shield board

Mon Apr 15, 2013 10:32 pm

I have made an image with framebuffer support for the Adafruit 1.8" and the Sainsmart 1.8" displays.
Maybe it can be used with your display to save people the hassle of compiling a kernel: https://github.com/notro/fbtft/wiki

I have detailed here how I made the image, in case you want to roll your own: https://github.com/notro/fbtft/wiki/Remake-SD-image

texy
Forum Moderator
Forum Moderator
Posts: 5174
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: 1.8 TFT LCD add-on shield board

Tue Apr 16, 2013 6:45 am

That's great Notro - I shall give that a go later. It'll be a big help to those who are unsure of compiling the kernel, etc
I tried to download the latest version •2013-02-09-wheezy-raspbian-2013-04-11-fbtft.zip - but its a dead link for me?
The earlier •2013-02-09-wheezy-raspbian-2013-04-07-fbtft.zip does download.
Cheers,
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

notro
Posts: 755
Joined: Tue Oct 16, 2012 6:21 pm
Location: Drammen, Norway

Re: 1.8 TFT LCD add-on shield board

Tue Apr 16, 2013 5:28 pm

texy wrote: It'll be a big help to those who are unsure of compiling the kernel, etc
Yes, and I guess that will include most of the Raspberry Pi userbase. Hopefully it will boost the use of these LCDs on the Pi. And plug&play displays like yours, make it even easier.
texy wrote: I tried to download the latest version •2013-02-09-wheezy-raspbian-2013-04-11-fbtft.zip - but its a dead link for me?
Can you try again, I have moved the file to another server.

texy
Forum Moderator
Forum Moderator
Posts: 5174
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: 1.8 TFT LCD add-on shield board

Tue Apr 16, 2013 9:24 pm

Hi Notro,
yes the new link is working fine. I downloaded the image and configured it for my chinese 1.8" TFT. It is almost working fine -
I selected the sainsmart 1.8" option as that is almost the same as my display however the RGB is swapped. Is there an option to change it?
Also I read on Kamal's blog ( http://www.whence.com/rpi/) that the sainsmart spi bus can be used up to 32mhz, but your driver defaults to 4mhz, the same as the adafruit unit. The adafruit display has an extra buffer chip inline so cannot be used at 32mhz, but the sainsmart does not so it can be run faster. My chinese display also does not have the extra buffer. Playing video back using mplayer seems a lot slower than that of Kamal's kernel as well - have you tried it?

One last question ;)
Is it possible to rotate the console output to landscape mode with con2fbmap ?

Thanks for sharing your work.
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

notro
Posts: 755
Joined: Tue Oct 16, 2012 6:21 pm
Location: Drammen, Norway

Re: 1.8 TFT LCD add-on shield board

Tue Apr 16, 2013 11:06 pm

First a disclaimer:
I don't have an Adafruit 1.8" display, but I have one report of someone that tried it succesfully.
The testing is done on a Sainsmart 1.8" display. Red and blue is swapped when I use the adafruit18fb driver.
texy wrote: I selected the sainsmart 1.8" option as that is almost the same as my display however the RGB is swapped. Is there an option to change it?
No, sorry it's not.
sainsmart18fb and adafruit18fb are identical expect for:
* sainsmart18fb is BGR
* adafruit18fb slows down the SPI bus to 2MHz when sending commands
texy wrote: Also I read on Kamal's blog ( http://www.whence.com/rpi/) that the sainsmart spi bus can be used up to 32mhz, but your driver defaults to 4mhz, the same as the adafruit unit. The adafruit display has an extra buffer chip inline so cannot be used at 32mhz, but the sainsmart does not so it can be run faster. My chinese display also does not have the extra buffer. Playing video back using mplayer seems a lot slower than that of Kamal's kernel as well - have you tried it?
If you don't have a levelshifter you can go full speed (yes, the adafruit18fb default is 4MHz, picked up from Kamal's work).

Code: Select all

# dmesg -C
# modprobe spidevices name=adafruit18fb speed=32000000 fps=50
# dmesg
spidevices:  SPI devices registered:
spidevices:      spidev spi0.1 500kHz 8 bits mode=0x00
spidevices:  'fb' Platform devices registered:
spidevices:      bcm2708_fb id=-1 pdata? no
spidevices: Deleting spi0.1
spidevices:  GPIOS used by 'adafruit18fb':
spidevices:    'reset' = GPIO18
spidevices:    'dc' = GPIO24
spidevices:  SPI devices registered:
spidevices:      adafruit18fb spi0.1 32000kHz 8 bits mode=0x00
Now lets load the driver telling it to display the transfer time for each frame sent (https://github.com/notro/fbtft/wiki/Debug):

Code: Select all

# modprobe adafruit18fb debug=$((2**5))
adafruit18fb spi0.1: Elapsed time for display update:   15.311903 ms (fps: 65, lines=160)
graphics fb1: adafruit18fb frame buffer, 40 KiB video memory, 4 KiB buffer memory, fps=50, spi0.1 at 32 MHz
As you see, I could run this at 65 fps instead of 50 as I set to be the maximum.

A note about fps in the context of fbtft:
fps=50 means the driver waits 1/50 of a second from something in video memory has changed until transfer is begun.
So setting it to 100 won't change the fact that the real fps is ~65.
As far as my understanding goes, it can act as a throttle, and it ensures bulk updates.
texy wrote: One last question ;)
Is it possible to rotate the console output to landscape mode with con2fbmap ?
I learned something new today:

Code: Select all

con2fbmap 1 1
echo "1" > /sys/class/graphics/fbcon/rotate

texy
Forum Moderator
Forum Moderator
Posts: 5174
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: 1.8 TFT LCD add-on shield board

Wed Apr 17, 2013 5:20 pm

Thanks again Notro,
I made a mistake earlier, actually I need to use the sainsmart, not the adafruit driver for the displays I have.
So the correct sequence, using your image from https://github.com/notro/fbtft/wiki to set up fb1 is :

Code: Select all

sudo modprobe spidevices name=sainsmart18fb speed=32000000 fps=50
sudo modprobe sainsmart18fb
Then to make it permanent use

Code: Select all

sudo nano /etc/modules
and add these lines :

Code: Select all

spidevices name=sainsmart18fb verbose=0
sainsmart18fb
Reboot the Pi and check fb1 is present in /dev/

...should be good to go!

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

User avatar
Sheegoth
Posts: 36
Joined: Sun Jan 13, 2013 5:45 am
Location: Louisiana, USA

Re: 1.8 TFT LCD add-on shield board

Thu Apr 18, 2013 12:28 am

I've been researching miniature LCD screens for the Raspberry Pi for a short whiles now, and this certainly suits my fancy! :D So you're using a SainSmart 1.8" LCD Module, huh? Interesting. How's the refresh rate? It looked decent in the video, but that was 240p, so... :lol:

texy
Forum Moderator
Forum Moderator
Posts: 5174
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: 1.8 TFT LCD add-on shield board

Thu Apr 18, 2013 5:09 am

Hi,
No it's not a sainsmart display, the system is just configured that way because it is equivalent.
The refresh rate is set to 50fps as per the driver, but the big buck bunny video I being used is being resized on the fly by the Pi so it not optimal. A better solution would be to have a native 160x128 version of the video, but i didnt get round to editting it.
Cheers
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

User avatar
Sheegoth
Posts: 36
Joined: Sun Jan 13, 2013 5:45 am
Location: Louisiana, USA

Re: 1.8 TFT LCD add-on shield board

Fri Apr 19, 2013 2:44 am

Equivalent, huh? So a SainSmart LCD be modified to work then?

texy
Forum Moderator
Forum Moderator
Posts: 5174
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: 1.8 TFT LCD add-on shield board

Fri Apr 19, 2013 6:25 am

Sorry, I don't understand where your coming from (or aiming too).
Not previously mentioned, but my pcb design actually is compatibable with 4 different 1.8" LCD type's -
Adafruit
Sainsmart
'Chinese' 16 pin (or will be, for revision 2 of the board)
'Chinese' 10 pin

For this initial batch that I am selling, the Chinese 10 pin LCD is used.
If you have your own Adafruit or Sainsmart LCD, I could supply the board ready made, but without a LCD module fitted.
Regards,
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

texy
Forum Moderator
Forum Moderator
Posts: 5174
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: 1.8 TFT LCD add-on shield board

Fri Apr 26, 2013 6:00 pm

texy wrote:Thanks again Notro,
I made a mistake earlier, actually I need to use the sainsmart, not the adafruit driver for the displays I have.
So the correct sequence, using your image from https://github.com/notro/fbtft/wiki to set up fb1 is :

Code: Select all

sudo modprobe spidevices name=sainsmart18fb speed=32000000 fps=50
sudo modprobe sainsmart18fb
Then to make it permanent use

Code: Select all

sudo nano /etc/modules
and add these lines :

Code: Select all

spidevices name=sainsmart18fb verbose=0
sainsmart18fb
Reboot the Pi and check fb1 is present in /dev/

...should be good to go!

Texy
Please note with Notro's latest os download (25th April onwards), you need to use :

Code: Select all

sudo modprobe fbtft_device name=sainsmart18fb speed=32000000 fps=50
sudo modprobe sainsmart18fb
sudo nano /etc/modules


...ie 'spidevices' has been replaced with 'fbtft_device'

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

CopyCatz
Posts: 4
Joined: Mon Oct 29, 2012 9:30 am

Re: 1.8 TFT LCD add-on shield board

Sat May 25, 2013 1:28 pm

Received the shield yesterday, attached it to a model A with Pibow A case. Fits very nicely, now to figure out what purpose this 4th pi will have :)
DSC08124.jpg
DSC08124.jpg (60.32 KiB) Viewed 17636 times
DSC08122.jpg
DSC08122.jpg (52.85 KiB) Viewed 17636 times
DSC08118.jpg
DSC08118.jpg (55.03 KiB) Viewed 17636 times

ivancreations
Posts: 15
Joined: Fri Jul 26, 2013 11:06 am

Re: 1.8 TFT LCD add-on shield board

Fri Jul 26, 2013 11:13 am

Hi Notro - can we have the adafruit18fb (that brings the line to 2Mhz while sending commands) driver to support the rotate and bgr options as the sainsmart18fb please?
I will gladly test it on my device

notro
Posts: 755
Joined: Tue Oct 16, 2012 6:21 pm
Location: Drammen, Norway

Re: 1.8 TFT LCD add-on shield board

Sat Jul 27, 2013 9:40 am

ivancreations wrote:Hi Notro - can we have the adafruit18fb (that brings the line to 2Mhz while sending commands) driver to support the rotate and bgr options as the sainsmart18fb please?
I will gladly test it on my device
Sorry, but I probably won't have time to add that functionality in the near future.
Have you tried the sainsmart18fb driver with the adafruit18fb default speed?

Code: Select all

sudo modprobe fbtft_device name=sainsmart18fb speed=4000000 gpios=reset:25,dc:24,led:23
sudo modprobe sainsmart18fb
If it works, try increasing the speed until it stops working. Please post back you're results.

ivancreations
Posts: 15
Joined: Fri Jul 26, 2013 11:06 am

Re: 1.8 TFT LCD add-on shield board

Sat Jul 27, 2013 3:51 pm

Hi Notro,

Thanks, it worked!

I have tested it with this python script (paints a 128x160 png image)

Code: Select all

# 1.8" TFT test prog
# v1 11/4/13

import wiringpi2 as wiringpi
from subprocess import call
import pygame, sys, os, time
from pygame.locals import *

os.environ["SDL_FBDEV"] = "/dev/fb1"

def main():
    global screen
    pygame.init()
 
    size = width, height = 160, 128
    black = 0, 0, 0
 
    pygame.mouse.set_visible(0)
    screen = pygame.display.set_mode(size)
    graph = pygame.image.load("test.png")
    #graph = pygame.transform.rotate(graph, 270)
    graphrect = graph.get_rect()
    screen.fill(black)
    screen.blit(graph, graphrect)
    pygame.display.update()
    pygame.display.flip()
    
    time.sleep(100)

if __name__ == '__main__':
    main()
And that thing worked fine untill I have tested with this code (essentially 55Mhz - higher than this was not possible but i beleive that is because of the long wires I am using):

Code: Select all

sudo modprobe -r sainsmart18fb
sudo modprobe -r fbtft_device 
sudo modprobe fbtft_device name=sainsmart18fb speed=55000000 gpios=reset:25,dc:24,led:23
sudo modprobe sainsmart18fb
sudo python test.py
And finally I have tested with http://www.ebay.com/itm/400466715624?ss ... 1439.l2649

notro
Posts: 755
Joined: Tue Oct 16, 2012 6:21 pm
Location: Drammen, Norway

Re: 1.8 TFT LCD add-on shield board

Sat Jul 27, 2013 8:46 pm

Ok, since you mentioned the 2MHz command speed, I assumed you had an Adafruit display.
The HY-1.8 works with the sainsmart18fb driver: https://github.com/notro/fbtft/wiki/Mor ... #hy-18-spi
Interesting that you could go as high as 55MHz. I tried a loopback test on the SPI bus, and the data was garbled above 48MHz.
If you use the fbtft_device argument: fps=50, you get ~25fps framerate (default 10-15fps). Nice to have when showing movies.

ivancreations
Posts: 15
Joined: Fri Jul 26, 2013 11:06 am

Re: 1.8 TFT LCD add-on shield board

Sun Jul 28, 2013 7:17 am

Hi,

The display I am using is not HY-1.8 SPI ... it is some other chineese thing :)
And I managed to make it work only with the adafruit18fb driver ... I have tried with sainsmart18fb but it was not working at all.
Once I added the arguments about the pins at the end (that you have sent) it started working (I thought that is not needed beacsue the pins for RESET,DC are one and the same).

The problem was either the arguments at the end or I forgot to call

Code: Select all

sudo modprobe sainsmart18fb
after the load of the fbtft_device driver ...

>Interesting that you could go as high as 55MHz. I tried a loopback test on the SPI bus, and the data was garbled above 48MHz.
Good point ... my test was not that scientific - I was pushing an image and I was observing whether the image pops up Ok or not.

>If you use the fbtft_device argument: fps=50, you get ~25fps framerate (default 10-15fps). Nice to have when showing movies.
Thanks for the hint!

Best Regards,
Ivan Rangelov

Return to “Other projects”