HY28A-LCDB, ili9320 (working)


132 posts   Page 4 of 6   1, 2, 3, 4, 5, 6
by ThomasG » Fri Jun 14, 2013 9:09 pm
Hello notro,

Many thanks for the new image. I just got the HY28A and am trying to get it to work. So far it has been "mostly" successful.

I installed your image and can start an X session in the "simplest-non-rotated" manner with :
Code: Select all
# Normal
modprobe fbtft_device name=hy28afb rotate=0
modprobe hy28afb
modprobe ads7846_device pressure_max=255 gpio_pendown=17 x_plate_ohms=100
modprobe ads7846
FRAMEBUFFER=/dev/fb1 startx

Now I'm trying to do the calibration you described here:

https://github.com/notro/fbtft/wiki/Touchpanel#hy28a

The X session starts successfully, and the mouse pointer reacts to touch events. The problem I run into is that when I move left/right on the touch panel the pointer moves left/right, but when I move it up/down it moves "diagonally" from the bottom left corner to the top right corner. When I check with :
Code: Select all
evtest /dev/input/eventX | grep ABS_X
evtest /dev/input/eventX | grep ABS_Y

I see that when I move left/right ABS_Y stays about the same and only ABS_X changes, but when I move up/down BOTH of them change massively. TO get ABS_X to stay about constant I have to move somewhat diagonally on the touch panel.

Now I'm stumped whether that *can* even be a software problem, or if the touch might even have a wiring problem or hardware defect. Do you have any idea what could cause the movement on one touch axis to be "off by about 45 degrees"?

Thanks for your effort so far, really appreciated.
Posts: 2
Joined: Fri Jun 14, 2013 8:42 pm
Location: Germany
by notro » Fri Jun 14, 2013 9:12 pm
topogigio wrote:Hi notro,
I loaded your new 2013-06-14 image on SD and now what I must do to start x. :)
Thanks

Wiring: https://github.com/notro/fbtft/wiki/LCD-Modules#hy28a
Usage with touch and different rotations: https://github.com/notro/fbtft/wiki/Touchpanel#hy28a
Posts: 530
Joined: Tue Oct 16, 2012 6:21 pm
Location: Norway
by topogigio » Sat Jun 15, 2013 1:07 am
Hi TomasG,
I think that you must install xinput

sudo apt-get -y install xinput

thanks to notro that made this huge work!!!
Now for me works everything perfectly.
User avatar
Posts: 38
Joined: Fri May 10, 2013 1:35 am
by topogigio » Sat Jun 15, 2013 4:55 pm
Hi,
at the end of this story finaly I can start to develope code.
So btw I need a GUI LIB to use with framebuffer.
which one?
I try SDL, no way to output to /dev/fb1.
Any suggestion...
Thanks
User avatar
Posts: 38
Joined: Fri May 10, 2013 1:35 am
by notro » Sat Jun 15, 2013 5:26 pm
topogigio wrote:So btw I need a GUI LIB to use with framebuffer.
which one?
I try SDL, no way to output to /dev/fb1.
This is as far as I have come: https://github.com/notro/fbtft/wiki/Pygame
I tried to make some graphics, but gave after a short time.
Posts: 530
Joined: Tue Oct 16, 2012 6:21 pm
Location: Norway
by texy » Sat Jun 15, 2013 5:43 pm
He is a simple test program using pygame and some of its features:

Code: Select all
import pygame, sys, os
from pygame.locals import *
os.environ["SDL_FBDEV"] = "/dev/fb1"

pygame.init()

# set up the window
DISPLAYSURF = pygame.display.set_mode((240, 320), 0, 32)
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(WHITE)
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))

pixObj = pygame.PixelArray(DISPLAYSURF)
pixObj[120][144] = BLACK
pixObj[122][146] = BLACK
pixObj[124][148] = BLACK
pixObj[126][158] = BLACK
pixObj[126][158] = BLACK
del pixObj

# run the game loop
while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
    pygame.display.update()
"2.8inch TFT LCD + Touch screen" add-on boards for sale here :
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=93&t=65566
50p goes to the Foundation ;-)
Forum Moderator
Forum Moderator
Posts: 2482
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England
by texy » Sat Jun 15, 2013 5:45 pm
So we've got the touchscreen working in x, and the cursor follows your touch as it should. However, I cannot find a way to make the cursor in pygame follow touch, ie use the touch input instead of mouse input to move the cursor. Any idea's ?
Texy
"2.8inch TFT LCD + Touch screen" add-on boards for sale here :
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=93&t=65566
50p goes to the Foundation ;-)
Forum Moderator
Forum Moderator
Posts: 2482
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England
by notro » Sat Jun 15, 2013 11:34 pm
texy wrote:So we've got the touchscreen working in x, and the cursor follows your touch as it should. However, I cannot find a way to make the cursor in pygame follow touch, ie use the touch input instead of mouse input to move the cursor. Any idea's ?
Texy
tslib: http://tslib.berlios.de/ seem to be the thing for pygame.

This is my tslib testing so far. /dev/input/event3 was my touch controller. I found it using evtest
Code: Select all
sudo apt-get install libts-bin

# Moving/Drawing test
sudo TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/event3 ts_test

# 5 crosshairs calibration
sudo TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/event3 ts_calibrate
xres = 240, yres = 320
Took 38 samples...
Top left : X =  993 Y =  783
Took 29 samples...
Top right : X = 3135 Y =  799
Took 36 samples...
Bot right : X = 3135 Y = 3207
Took 46 samples...
Bot left : X = 1024 Y = 3231
Took 42 samples...
Center : X = 2091 Y = 2015
-15.777374 0.065827 -0.000425
-22.170654 0.000161 0.090601
Calibration constants: -1033986 4314 -27 -1452976 10 5937 65536
What do we do with these calibration values?
For some reason it didn't work when I exported the TSLIB_FBDEVICE and TSLIB_TSDEVICE env. variables.
To late to continue on this. Sleep is waiting...

This seem to be coupling between tslib and pygame. Not tested.
Code: Select all
export SDL_MOUSEDRV=TSLIB
export SDL_MOUSEDEV=$TSLIB_TSDEVICE
Posts: 530
Joined: Tue Oct 16, 2012 6:21 pm
Location: Norway
by texy » Sun Jun 16, 2013 7:21 am
Close, but...
This is starts off OK,
Code: Select all
os.environ["SDL_FBDEV"] = "/dev/fb1"
os.environ["SDL_MOUSEDRV"] = "TSLIB"
os.environ["SDL_MOUSEDEV"] = "$TSLIB TSDEVICE"
devices = map(InputDevice, list_devices())
devices = {dev.fd : dev for dev in devices}
pygame.init()
DISPLAYSURF = pygame.display.set_mode((240, 320), 0, 32)


but throws this error :
Code: Select all
Traceback (most recent call last):
  File "touchv2.py", line 12, in <module>
    DISPLAYSURF = pygame.display.set_mode((240, 320), 0, 32)
pygame.error: Unable to open mouse


I need to do some more searching...

Texy
"2.8inch TFT LCD + Touch screen" add-on boards for sale here :
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=93&t=65566
50p goes to the Foundation ;-)
Forum Moderator
Forum Moderator
Posts: 2482
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England
by notro » Sun Jun 16, 2013 10:05 am
These two are not equal
texy wrote:
Code: Select all
export SDL_MOUSEDEV=$TSLIB_TSDEVICE
Code: Select all
os.environ["SDL_MOUSEDEV"] = "$TSLIB TSDEVICE"
The shell one sets SDL_MOUSEDEV to the contents of $TSLIB_TSDEVICE, hence the dollar sign.
The python one sets SDL_MOUSEDEV to the string "$TSLIB TSDEVICE" (missing underscore)
How about:
Code: Select all
os.environ["SDL_FBDEV"] = "/dev/fb1"
os.environ["TSLIB TSDEVICE"] = "/dev/input/eventX"
os.environ["SDL_MOUSEDRV"] = "TSLIB"
os.environ["SDL_MOUSEDEV"] = os.environ["TSLIB TSDEVICE"]
or maybe just:
Code: Select all
os.environ["SDL_FBDEV"] = "/dev/fb1"
os.environ["SDL_MOUSEDRV"] = "TSLIB"
os.environ["SDL_MOUSEDEV"] = "/dev/input/eventX"
Posts: 530
Joined: Tue Oct 16, 2012 6:21 pm
Location: Norway
by texy » Sun Jun 16, 2013 11:03 am
Code: Select all
Traceback (most recent call last):
  File "touchv2.py", line 12, in <module>
    DISPLAYSURF = pygame.display.set_mode((240, 320), 0, 32)
pygame.error: Unable to open mouse


:cry:


Texy
"2.8inch TFT LCD + Touch screen" add-on boards for sale here :
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=93&t=65566
50p goes to the Foundation ;-)
Forum Moderator
Forum Moderator
Posts: 2482
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England
by notro » Sun Jun 16, 2013 2:10 pm
This works for me. Touching the red box exits the script.

Load drivers
Code: Select all
sudo modprobe fbtft_device name=hy28afb
sudo modprobe hy28afb

sudo modprobe ads7846_device pressure_max=255 y_min=190 y_max=3850 gpio_pendown=17 x_max=3850 x_min=230 x_plate_ohms=60
sudo modprobe ads7846
pygame_test.py
Code: Select all
import pygame, sys, os
from pygame.locals import *
os.environ["SDL_FBDEV"] = "/dev/fb1"
os.environ["SDL_MOUSEDRV"] = "TSLIB"
os.environ["SDL_MOUSEDEV"] = "/dev/input/event3"

pygame.init()

# set up the window
DISPLAYSURF = pygame.display.set_mode((240, 320), 0, 32)
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(WHITE)
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)
box = pygame.draw.rect(DISPLAYSURF, RED, (100, 150, 100, 50))

pixObj = pygame.PixelArray(DISPLAYSURF)
pixObj[120][144] = BLACK
pixObj[122][146] = BLACK
pixObj[124][148] = BLACK
pixObj[126][158] = BLACK
pixObj[126][158] = BLACK
del pixObj

# run the game loop
while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
        if event.type == pygame.MOUSEBUTTONDOWN:
            print("Pos: %sx%s\n" % pygame.mouse.get_pos())
            if box.collidepoint(pygame.mouse.get_pos()):
                pygame.quit()
                sys.exit()
    pygame.display.update()
Start script
Code: Select all
sudo python pygame_test.py
Posts: 530
Joined: Tue Oct 16, 2012 6:21 pm
Location: Norway
by topogigio » Sun Jun 16, 2013 2:19 pm
Hi notro,
in fb1 how can I set X Y color pixel? I mean how to address it.
Thanks
User avatar
Posts: 38
Joined: Fri May 10, 2013 1:35 am
by notro » Sun Jun 16, 2013 3:16 pm
topogigio wrote:Hi notro,
in fb1 how can I set X Y color pixel? I mean how to address it.
Thanks
If you mean using pygame, see here: http://stackoverflow.com/questions/1035 ... ngle-pixel

If you mean writing directly to the framebuffer /dev/fb1, you can have look at this python example
Code: Select all
git clone https://github.com/notro/fbtft_test
python fbtft_test/test_fb.py -d /dev/fb1
Posts: 530
Joined: Tue Oct 16, 2012 6:21 pm
Location: Norway
by topogigio » Sun Jun 16, 2013 5:01 pm
Hi notro,
resolved...
I used the same software that I wrote before for not fb lcd version and access to fb using a pointer.
when finished I'll post code. :)
Once again thanks
User avatar
Posts: 38
Joined: Fri May 10, 2013 1:35 am
by texy » Sun Jun 16, 2013 6:11 pm
notro wrote:This works for me. Touching the red box exits the script.

Load drivers
Code: Select all
sudo modprobe fbtft_device name=hy28afb
sudo modprobe hy28afb

sudo modprobe ads7846_device pressure_max=255 y_min=190 y_max=3850 gpio_pendown=17 x_max=3850 x_min=230 x_plate_ohms=60
sudo modprobe ads7846
pygame_test.py
Code: Select all
import pygame, sys, os
from pygame.locals import *
os.environ["SDL_FBDEV"] = "/dev/fb1"
os.environ["SDL_MOUSEDRV"] = "TSLIB"
os.environ["SDL_MOUSEDEV"] = "/dev/input/event3"

pygame.init()

# set up the window
DISPLAYSURF = pygame.display.set_mode((240, 320), 0, 32)
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(WHITE)
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)
box = pygame.draw.rect(DISPLAYSURF, RED, (100, 150, 100, 50))

pixObj = pygame.PixelArray(DISPLAYSURF)
pixObj[120][144] = BLACK
pixObj[122][146] = BLACK
pixObj[124][148] = BLACK
pixObj[126][158] = BLACK
pixObj[126][158] = BLACK
del pixObj

# run the game loop
while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
        if event.type == pygame.MOUSEBUTTONDOWN:
            print("Pos: %sx%s\n" % pygame.mouse.get_pos())
            if box.collidepoint(pygame.mouse.get_pos()):
                pygame.quit()
                sys.exit()
    pygame.display.update()
Start script
Code: Select all
sudo python pygame_test.py


Notro - good job (again!!). I think there may be 1 or 2 factors why pygame cursor movement did not work for me previously.
During my testing today, I had a couple of instances of sd card corruption. This meant I had to reimage the card from a previous backup. On this backup
I did not have the following loaded :

Code: Select all
sudo apt-get install libts-bin evtest python-dev python-pip
sudo pip install evdev

I then needed to confirm which dev/input/eventx my system used - event3 this time, previously event0.
Also I used a compilation prior to your release of fbtft on Friday, so ads7846_test was used instead of ads7846_device.
Once I had sorted that out, and run
Code: Select all
sudo TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/event3 ts_calibrate

you program above works correctly.

Thanks,
Texy
"2.8inch TFT LCD + Touch screen" add-on boards for sale here :
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=93&t=65566
50p goes to the Foundation ;-)
Forum Moderator
Forum Moderator
Posts: 2482
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England
by notro » Mon Jun 17, 2013 7:33 pm
I have made a wiki page on installing Multiple Arcade Machine Emulator: https://github.com/notro/fbtft/wiki/MAME
Posts: 530
Joined: Tue Oct 16, 2012 6:21 pm
Location: Norway
by andybiker » Wed Jun 19, 2013 2:45 pm
Notro,
I would like to thank you for all of your hard work.
I have the display working beautifully, the touchpad works in X11 and PyGame, all is good.
The display is quite useable as a terminal being 320x200
I am having the same usb keyboardddddddddd problem that you have.
I think we have to wait for an official fix for this one!
Thanks again
Posts: 11
Joined: Fri Apr 26, 2013 7:46 am
by notro » Wed Jun 19, 2013 5:39 pm
andybiker wrote:Notro,
I would like to thank you for all of your hard work.
Thanks :-)
andybiker wrote:I am having the same usb keyboardddddddddd problem that you have.
I think we have to wait for an official fix for this one!
A workaround for the console (but not for programs reading raw keyboard input)
Code: Select all
setterm -repeat off
Add to ~/.profile to make it stick
Posts: 530
Joined: Tue Oct 16, 2012 6:21 pm
Location: Norway
by nejemia » Wed Jun 26, 2013 2:18 pm
Hello everybody:

I am using the previous .img with fbtft support and driving the little 2.2" Sainsmart Display with no problems.
I want to add the HY28A (only SPI) and just downloaded the last available .img with HY28A support.
QUESTION:
Is it possible to upgrade the .img with the HY28A drivers capabilities WITHOUT replacing all the System File since I have a ton of quite debugged software already installed and working and I do not want to re-invent the wheel?

In other words, just to add the HY28A capabilities to my already working system ... :roll:
Thank you ver y much in advance and congratulations for this fantastic work of yours.

All the best.
nelson.
Posts: 10
Joined: Mon Apr 29, 2013 12:53 pm
by texy » Wed Jun 26, 2013 3:15 pm
Hi,
Yes is the answer. Go to notro' s "Page's" page on GitHub. It explains how to compile to the latest version of fbtft. Only applies I'd you start from a valid fbtft image.
Texy
"2.8inch TFT LCD + Touch screen" add-on boards for sale here :
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=93&t=65566
50p goes to the Foundation ;-)
Forum Moderator
Forum Moderator
Posts: 2482
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England
by notro » Wed Jun 26, 2013 11:01 pm
nejemia wrote:QUESTION:
Is it possible to upgrade the .img with the HY28A drivers capabilities WITHOUT replacing all the System File since I have a ton of quite debugged software already installed and working and I do not want to re-invent the wheel?
Update to the latest FBTFT drivers in 30 minutes: https://github.com/notro/fbtft/wiki/Development
Posts: 530
Joined: Tue Oct 16, 2012 6:21 pm
Location: Norway
by texy » Fri Jun 28, 2013 5:28 pm
notro wrote:I have made a wiki page on installing Multiple Arcade Machine Emulator: https://github.com/notro/fbtft/wiki/MAME



Just trying this but I have a problem :

Code: Select all
pi@raspberrypi ~ $ FRAMEBUFFER=/dev/fb1 advv
No active video driver is able to program your video board.

Ensure to use the 'device_video_output auto' option.
Ensure to have a Frame Buffer driver (other than VESA) in your Linux kernel.
Try to run this program in a TERM=linux terminal.
pi@raspberrypi ~ $

I,m ssh'ing into my Pi, and my 2.8" TFT screen is fully fuctional. I followed your instructions above.

Texy
"2.8inch TFT LCD + Touch screen" add-on boards for sale here :
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=93&t=65566
50p goes to the Foundation ;-)
Forum Moderator
Forum Moderator
Posts: 2482
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England
by notro » Fri Jun 28, 2013 6:08 pm
I struggled with the same problem yesterday until I read my own notes a little more carefully :-)

> advv and advmame must be run from the console.
Posts: 530
Joined: Tue Oct 16, 2012 6:21 pm
Location: Norway
by texy » Sun Jun 30, 2013 2:19 pm
Hi,
advmame is now working for me - thanks.


So I am working on a test program in python, but in order to use the touchpanel, you need to know which /dev/eventX is associated with it. We can manually guess of course, but X will change depending on which other input devices are fitted at the time. Is there are way of finding which eventX is used and importing it into python?

Texy
"2.8inch TFT LCD + Touch screen" add-on boards for sale here :
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=93&t=65566
50p goes to the Foundation ;-)
Forum Moderator
Forum Moderator
Posts: 2482
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England