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

Re: 2.8" TFT + Touch Shield Board

Wed Aug 07, 2013 4:23 pm

Maybe because you didn't

Code: Select all

sudo apt-mark hold raspberrypi-bootloader
before you

Code: Select all

sudo apt-get update
sudo apt-get upgrade
???

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

allenjh
Posts: 19
Joined: Fri Jul 12, 2013 12:47 pm
Location: Devon, UK

Re: 2.8" TFT + Touch Shield Board

Thu Aug 08, 2013 3:34 pm

texy wrote:Maybe because you didn't

Code: Select all

sudo apt-mark hold raspberrypi-bootloader
before you

Code: Select all

sudo apt-get update
sudo apt-get upgrade
???

Texy
and that's exactly what I did! starting again now!

chnyc
Posts: 25
Joined: Fri Jul 19, 2013 12:26 pm
Location: New York, NY

Re: 2.8" TFT + Touch Shield Board

Sat Aug 10, 2013 1:02 pm

texy wrote:
Download the tft framebuffer os from Notro's github page : https://github.com/notro/fbtft/wiki
Write the image to a SD card, fit the display shield to your pi and 'modprobe' the modules to configure the screen :

Code: Select all

sudo modprobe fbtft_device name=hy28afb rotate=1
sudo modprobe hy28afb
Apologies in advance for some very noob questions here... but I've now purchased one of your slick 2.8" TFTs and am unclear how to proceed with the setup and configuration. My setup:

- Macbook Pro
- RPi B board
- Occidentalis distro (Adafruit's version of Raspbian)

Clearly, I've never done this before. So, I'm stuck at step 1...

You say "Write the image to an SD card":
a. "the image" -- do you mean download one of the tft framebuffer os options on this page http://tronnes.org/fbtft/download.html?
b. "Write to SD card" -- what SD card? Is this a separate SD card from the SD card running Raspbian or is it the card running the OS? Either way, I'm unclear on the steps. If you write the image to another card, how does the image become available for writing to the RPi?

I'm obviously missing something basic here. Sorry for that. Many thanks for the help and the great work on the display.

Charles H

Dutch_Master
Posts: 362
Joined: Sat Jul 27, 2013 11:36 am

Re: 2.8" TFT + Touch Shield Board

Sat Aug 10, 2013 2:02 pm

The image is one of the specific images found here: https://github.com/notro/fbtft/wiki (hint: use the latest version ;))

This then should be written to an SD card (get yourself a 2nd card, 4GB suffices), but not copied! There are some GUI tools for your Mac, Piwriter is a free one (there are others too, but I can't recall those right now :P) who'll do the tricky part for you.

Once done, insert the card into the RPi and follow the instructions on page #1. I did, and got it working :)

chnyc
Posts: 25
Joined: Fri Jul 19, 2013 12:26 pm
Location: New York, NY

Re: 2.8" TFT + Touch Shield Board

Sun Aug 11, 2013 12:05 am

Dutchmaster,

Thanks for the speedy and helpful response. One further question, though: does this new image on the SD card become the actual boot disk for the Pi? That's really the thing I keep getting stuck on. If so, what happens to the original boot that had other installs, updates, configs, etc.?
CharlesH

Dutch_Master
Posts: 362
Joined: Sat Jul 27, 2013 11:36 am

Re: 2.8" TFT + Touch Shield Board

Sun Aug 11, 2013 12:14 am

The image I linked to will indeed become your new system. Any settings and data on the old system will evaporate, hence my advice to use another SD card. Technically it is possible to merge both, but it's a hornets nest you'd be stuck into... :? (hint: don't! ;))

chnyc
Posts: 25
Joined: Fri Jul 19, 2013 12:26 pm
Location: New York, NY

Re: 2.8" TFT + Touch Shield Board

Sun Aug 11, 2013 1:19 am

Dutch_Master,

Hmm. Now I really know why the process seemed opaque and a little unintuitive to me: adding a peripheral device (in this case, a display) requires trashing an entire system and starting from scratch. That's a huge time suck. Is this typical for adding a TFT to RPi?

If so, then this is the kind of thing that should be pointed out to noobs (in particular) when starting projects so workflow can follow a more logical path. Otherwise, much work gets repeated, many hours wasted. Or am I missing something again?

One further noob follow up: I'd been using the AdaFruit wheezy variant, Occidentalis, which is ostensibly an optimized build for projects adding hardware to the Pi. Am I now SOL with that?

Thanks again.
Charlesh

Dutch_Master
Posts: 362
Joined: Sat Jul 27, 2013 11:36 am

Re: 2.8" TFT + Touch Shield Board

Sun Aug 11, 2013 1:43 am

Well, I suppose you could use the AdaFruit version to control a TFT display via the GPIO pins as well, but that would require some serious hacking. I hope notro (who baked the FBTFT version) or texy (who supplies the touchscreen units) would step in here, as I can't tell you what changes need to be made. Mind that the GPIO pins required for the unit are no longer available to experiment with!

chnyc
Posts: 25
Joined: Fri Jul 19, 2013 12:26 pm
Location: New York, NY

Re: 2.8" TFT + Touch Shield Board

Sun Aug 11, 2013 2:23 am

Dutch_Master,

I hope my last comment isn't taken as a criticism of Texy's or Notro's excellent work. Just a helpful suggestion on caveats for noobs like myself.

Thanks much for the helpful guidance.
CharlesH

User avatar
bob_binz
Posts: 441
Joined: Thu Feb 02, 2012 7:58 pm
Location: Stockport, UK

Re: 2.8" TFT + Touch Shield Board

Sun Aug 11, 2013 9:16 am

Your other option is to build your own kernel and modules and install them onto your current SD card. Instructions for doing this are here: http://elinux.org/RPi_Kernel_Compilation (it's not as daunting as it seems!) Before building it, you will need to install Notro's FBTFT source code into the kernel tree. Instructions for doing this here: https://github.com/notro/fbtft

chnyc
Posts: 25
Joined: Fri Jul 19, 2013 12:26 pm
Location: New York, NY

Re: 2.8" TFT + Touch Shield Board

Sun Aug 11, 2013 7:53 pm

TFT now working splendidly! Which means Texy's and Notro's files and instructions were spot on. Just had to get past the boot disk hurdle.

Thanks to Dutch_Master for the guidance. And bob_binz, I'll give your suggestion on building my own kernel next.

chnyc
Posts: 25
Joined: Fri Jul 19, 2013 12:26 pm
Location: New York, NY

Re: 2.8" TFT + Touch Shield Board

Mon Aug 12, 2013 4:45 am

texy wrote:Here is a short python script that takes pictures in a loop using the Pi camera, and displays it on the TFT screen :

Code: Select all

#!/usr/bin/python
# camera v4.02
# for pi camera, and TFT set to 0 rotate
# takes picture,loads jpg and rotates onto TFT
# 
from subprocess import call
import pygame, sys, os, time, datetime
from pygame.locals import *
os.environ["SDL_FBDEV"] = "/dev/fb1"
time.sleep(0.5)
pygame.init()

DISPLAYSURF = pygame.display.set_mode((320, 240), 0, 32)

surf = pygame.Surface((240, 320)).convert()

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

#pygame.mouse.set_visible(0)

# draw on the surface object
DISPLAYSURF.fill(WHITE)

pygame.display.flip()
while True:

    start_time = time.time()
    filename = datetime.datetime.fromtimestamp(start_time).strftime('%Y-%m-%d%H:%M:%S')+".jpg"
    argument="raspistill -o " + filename
    call ([argument], shell=True)
    print "argument = ",argument
    print "picture saved = ",filename
    print filename[-3:]
    time.sleep(0.25)
    if (filename[-3:] == "JPG") or (filename[-3:] == "jpg") : 
        surf = pygame.image.load(filename)
        print "image load :",time.time() - start_time
        next_time = time.time()
        picture = pygame.transform.scale(surf, (320, 240))
        DISPLAYSURF.blit(picture,(0,0))
        print "rotate and scale :",time.time() - next_time

    pygame.display.flip()
    end_time = time.time()
    print "time taken :",end_time - start_time

# run the game loop
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
    pygame.display.flip()

I have a different version that uses my Nikon D80 in conjunction with Gphoto.

Texy
So, I set up and ran your TFT successfully for the better part of a day. Then, I moved on to set up and configure my RPi cam and test your script above. Now, the TFT's gone white screen (blank; backlit) on me. The only changes I made after the successful TFT set up were the cam set up steps:

sudo apt-get update
sudo apt-get upgrade
sudo raspi-config > enable camera

Do you have any reports of the RPi camera breaking Notro's drivers? Would you have any thoughts on a fix?

Thanks very much for any suggestions.
CharlesH

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

Re: 2.8" TFT + Touch Shield Board

Mon Aug 12, 2013 5:06 am

Not the camera, but the update/upgrade have broken the drivers. See this post :
http://www.raspberrypi.org/phpBB3/viewt ... 67#p384048
I hope you made a backup of the ad card before your latest changes :shock:
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

allenjh
Posts: 19
Joined: Fri Jul 12, 2013 12:47 pm
Location: Devon, UK

Re: 2.8" TFT + Touch Shield Board

Mon Aug 12, 2013 10:24 am

texy wrote:Here is a test python program than uses pygame :

Code: Select all

#!/usr/bin/python
# touchv5
# Texy 1/6/13

import pygame, sys, os, time
from pygame.locals import *

from evdev import InputDevice, list_devices
devices = map(InputDevice, list_devices())
eventX=""
for dev in devices:
    if dev.name == "ADS7846 Touchscreen":
        eventX = dev.fn
print eventX

os.environ["SDL_FBDEV"] = "/dev/fb1"
os.environ["SDL_MOUSEDRV"] = "TSLIB"
os.environ["SDL_MOUSEDEV"] = eventX

pygame.init()

# set up the window
screen = pygame.display.set_mode((320, 240), 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)
CYAN  = (  0, 255, 255)
MAGENTA=(255,   0, 255)
YELLOW =(255, 255,   0)
 
# Fill background
background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill(WHITE)
box = pygame.draw.rect(background, YELLOW,(0, 0, 40, 240))
box = pygame.draw.rect(background,  CYAN, (40, 0, 40, 240))
box = pygame.draw.rect(background, GREEN, (80, 0, 40, 240))
box = pygame.draw.rect(background,MAGENTA,(120, 0, 40, 240))
box = pygame.draw.rect(background, RED,   (160, 0, 40, 240))
box = pygame.draw.rect(background, BLUE  ,(200, 0, 40, 240))
box = pygame.draw.rect(background, BLACK ,(240, 0, 40, 240))

# Display some text
font = pygame.font.Font(None, 36)
text = font.render("Touch here", 1, (150, 10, 250))
#text = pygame.transform.rotate(text,270) 
textpos = text.get_rect(centerx=background.get_width()/2,centery=background.get_height()/2)
background.blit(text, textpos)

screen.blit(background, (0, 0))
pygame.display.flip()

running = True
# run the game loop
while running:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
            running = False  
        elif event.type == pygame.MOUSEBUTTONDOWN:
            print("Pos: %sx%s\n" % pygame.mouse.get_pos())
            if textpos.collidepoint(pygame.mouse.get_pos()):
                pygame.quit()
                sys.exit()
                running = False
        elif event.type == KEYDOWN and event.key == K_ESCAPE:
            running = False
    pygame.display.update()

Texy
When I run the test code above, I get the window opening on the main display (HDMI) and not on your 2.8" screen. Is there something I'm missing? I do have a USB keyboard/mouse plugged in as well, so I had to adjust the code to get the screen working originally.

The screen works as I can force display replication using the

Code: Select all

./fbcp
and the touch screen works fine as the mouse moves on the screen when I prod it.

Any help greatly appreciated.

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

Re: 2.8" TFT + Touch Shield Board

Mon Aug 12, 2013 10:40 am

Run without the hdmi cable connected and report back.
It shouldn't matter if keyboard or mouse is connected - they will only interfer with the touchscreen if eventX isn't set correctly, depending on what you are doing. The program above checks for the correct eventX input and acts accordingly.
Rgds,
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

allenjh
Posts: 19
Joined: Fri Jul 12, 2013 12:47 pm
Location: Devon, UK

Re: 2.8" TFT + Touch Shield Board

Mon Aug 12, 2013 10:57 am

Thanks Texy, that worked a treat.

(for anyone else reading this with a similar problem, I shutdown the pi, disconnected the HDMI, SSH'd in and ran the program, then used the shutdown command to turn it off then plugged in the HDMI so I could post this reply!)

chnyc
Posts: 25
Joined: Fri Jul 19, 2013 12:26 pm
Location: New York, NY

Re: 2.8" TFT + Touch Shield Board

Tue Aug 13, 2013 8:30 pm

texy wrote:Not the camera, but the update/upgrade have broken the drivers. See this post :
http://www.raspberrypi.org/phpBB3/viewt ... 67#p384048
I hope you made a backup of the ad card before your latest changes :shock:
Texy
Arrgh. Oh well. Redone and all's working again.

I now remember reading your warning elsewhere, but didn't remember when it mattered. I'm glad to see that you've put the caveat about apt-get upgrade and rpi-update in red at the top of the instructions post, which is a good idea.

Now that I'm overly cautious about breaking the drivers, one quick follow up: Would there be any reason ant rebuild or ant run would break anything?

Thanks much, Texy.
Last edited by chnyc on Tue Aug 13, 2013 8:55 pm, edited 1 time in total.

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

Re: 2.8" TFT + Touch Shield Board

Tue Aug 13, 2013 8:35 pm

Sorry never used those commands or know what they do, so can't help :oops:
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

Aikidokajeff
Posts: 68
Joined: Fri May 25, 2012 3:31 pm

Re: 2.8" TFT + Touch Shield Board

Tue Aug 13, 2013 8:38 pm

I've been busy changing the UI to use fbcp to allow you to see the preview output on screen.
Certainly a little more tricky than my simple click buttons interface.
(still too much flicker for me as fbcp and python fight for the screen at times :-) )

Kensho
Posts: 2
Joined: Sat Jan 05, 2013 4:49 pm

Re: 2.8" TFT + Touch Shield Board

Wed Aug 14, 2013 7:49 pm

Would this display work for a nes emulator or mame?

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

Re: 2.8" TFT + Touch Shield Board

Wed Aug 14, 2013 8:01 pm

Probably not directly, but using fbcp it should. Fbcp is a background service that copies the main output to fb1 (which thus display is routed from).
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

Ik0adr
Posts: 50
Joined: Fri Jul 12, 2013 6:32 pm

Re: 2.8" TFT + Touch Shield Board

Mon Aug 19, 2013 12:46 pm

Hi all.
Got the board + tft, works perfectly.
Only a little annoyance I am unable to fix:
On X, the desktop is somehow larger than the 320x240 that the Tft may handle, and there is no way to pan around.
It is something in the monitor configuration on X, but I am unable to find and fix it.
Some help will be much appreciated.
Thanks!
--Federico

Foggy
Posts: 18
Joined: Mon Aug 20, 2012 12:26 pm
Location: Reading UK

Re: 2.8" TFT + Touch Shield Board

Fri Aug 23, 2013 12:57 pm

Hi All,

Just got my board, Thank you Texy.

Can you confirm that this is the latest image: http://tronnes.org/downloads/2013-05-25 ... -fbtft.zip
Then I just follow the instructions for configuration.

I'm sure that I read on the wiky https://github.com/notro/fbtft/wiki
That the next release would be available from RPI-Update, did I imagine this? As I can no longer see the comments and if correct, any idea when it would be available?


Best wishes.

James.

Squirrel61
Posts: 1
Joined: Tue Jan 24, 2012 8:56 am
Contact: Website

Re: 2.8" TFT + Touch Shield Board

Fri Aug 23, 2013 3:09 pm

I got my board already some time ago, but just recently got into assembling it. Because I wanted to keep the GPIO connector easily reachable, I decided to modify the assembly a bit. I bought an angled 26-pin male boxed header, which I mounted on the adapter board, on the pass-through GPIO port. This enabled me to access the GPIO pins from the outside with the TFT screen still mounted. Because the angled header uses some space, I also mounted two sockets for the TFT, to lift it from the adapter board. I have made some pictures which probably tell the story more clearly.

Notes:
1. Since the 26-pin header extrudes from the adapter board, the assembly doesn't fit the RPi's footprint anymore. That means that no standard case will fit the assembly. Not a problem for me, but if you need a case, you have to design your own.
2. Of course, you can't use the GPIO pins that are already in use for driving the TFT+Touch shield. But you can still use the other pins as you like!

Now for the pics:

https://www.dropbox.com/s/dqwk0fd99502f ... .42.39.jpg
https://www.dropbox.com/s/bl8m3yhqhots1 ... .42.53.jpg
https://www.dropbox.com/s/d3e78pg5szxbg ... .43.19.jpg
https://www.dropbox.com/s/kspoppgp8rtxo ... .44.42.jpg
https://www.dropbox.com/s/6yx1sdghl87qt ... .45.03.jpg
https://www.dropbox.com/s/p3ct5ylh00vha ... .46.02.jpg
https://www.dropbox.com/s/nrm0ods7osd3i ... .46.12.jpg
https://www.dropbox.com/s/3tb15e1c9os9e ... .46.36.jpg

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

Re: 2.8" TFT + Touch Shield Board

Fri Aug 23, 2013 4:21 pm

Foggy wrote:Hi All,

Just got my board, Thank you Texy.

Can you confirm that this is the latest image: http://tronnes.org/downloads/2013-05-25 ... -fbtft.zip
Then I just follow the instructions for configuration.

I'm sure that I read on the wiky https://github.com/notro/fbtft/wiki
That the next release would be available from RPI-Update, did I imagine this? As I can no longer see the comments and if correct, any idea when it would be available?


Best wishes.

James.
Hi James,
yes notro has just released updated drivers, and new method of configuration/installation.
Now you can start with your foundation supplied raspbian image via the downloads page, I would recommend
http://downloads.raspberrypi.org/images ... spbian.zip
and then follow notro's installation instructions from this page :
https://github.com/notro/fbtft/wiki
then for configuration for the 2.8" TFT :

'modprobe' the modules to configure the screen :

Code: Select all

sudo modprobe fbtft_device name=hy28afb rotate=270
At this point, the screen will go from white to black - the display has been successfully initialised.

Then to configure the touch panel

Code: Select all

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=100 swap_xy=1 verbose=3
sudo modprobe ads7846
Alternatively, to make the modules permanent after reboots, modify the /etc/module file :

Code: Select all

sudo nano /etc/modules
and add :

Code: Select all

fbtft_device name=hy28afb rotate=270
ads7846_device pressure_max=255 y_min=190 y_max=3850 gpio_pendown=17 x_max=3850 x_min=230 x_plate_ohms=100 swap_xy=1 verbose=3
ads7846
After a reboot the display and touchscreen will be initialised. To check, type dmesg and the following lines should be included :

Code: Select all

[   13.210784] fbtft_device:  'fb' Platform devices registered:
[   13.218779] fbtft_device:      bcm2708_fb id=-1 pdata? no
[   13.226470] fbtft_device: Deleting spi0.0
[   13.236360] spi spi0.0: setup: want 32000000 Hz; bus_hz=250000000 / cdiv=8 == 31250000 Hz; mode 3: cs 0x0000000C
[   13.236393] spi spi0.0: setup: cd 0: 32000000 Hz, bpw 8, mode 0x3 -> CS=0000000c CDIV=0008
[   13.236552] fbtft_device:  GPIOS used by 'hy28afb':
[   13.252450] fbtft_device:    'reset' = GPIO25
[   13.259023] fbtft_device:    'led' = GPIO18
[   13.278997] fbtft_device:  SPI devices registered:
[   13.286098] fbtft_device:      spidev spi0.1 500kHz 8 bits mode=0x00
[   13.294870] fbtft_device:      hy28afb spi0.0 32000kHz 8 bits mode=0x03
[   13.549535] hy28afb spi0.0: setup: want 2000000 Hz; bus_hz=250000000 / cdiv=125 == 2000000 Hz; mode 3: cs 0x0000000C
[   14.037694] graphics fb1: hy28afb frame buffer, 320x240, 150 KiB video memory, 4 KiB buffer memory, fps=20, spi0.0 at 32 MHz
[   14.500734]
[   14.500734]
[   14.500734] ads7846_device: ads7846_device_init()
[   14.527093] ads7846_device: SPI devices registered:
[   14.533848] ads7846_device:    spidev spi0.1 500kHz 8 bits mode=0x00
[   14.541924] ads7846_device:    hy28afb spi0.0 32000kHz 8 bits mode=0x03
[   14.554844] ads7846_device:
[   14.564223] ads7846_device: Settings:
[   14.573068] ads7846_device:   model = 7846
[   14.583249] ads7846_device:   gpio_pendown = 17
[   14.595359] ads7846_device:   swap_xy = 1
[   14.614010] ads7846_device:   x_min = 230
[   14.632830] ads7846_device:   x_max = 3850
[   14.651464] ads7846_device:   y_min = 190
[   14.671784] ads7846_device:   y_max = 3850
[   14.693592] ads7846_device:   x_plate_ohms = 100
[   14.722665] ads7846_device:   pressure_min = 0
[   14.746167] ads7846_device:   pressure_max = 255
[   14.768610] ads7846_device:   keep_vref_on = 1
[   14.791097] ads7846_device:   vref_delay_usecs = 0
[   14.818938] ads7846_device:   vref_mv = 0
[   14.840925] ads7846_device:   settle_delay_usecs = 0
[   14.867582] ads7846_device:   penirq_recheck_delay_usecs = 0
[   14.892499] ads7846_device:   y_plate_ohms = 0
[   14.917645] ads7846_device:   debounce_max = 0
[   14.943912] ads7846_device:   debounce_tol = 0
[   14.984602] ads7846_device:   debounce_rep = 0
[   15.008253] ads7846_device: Deleting spi0.1
[   15.008654] spi spi0.1: setup: want 2000000 Hz; bus_hz=250000000 / cdiv=125 == 2000000 Hz; mode 0: cs 0x00000001
[   15.008670] spi spi0.1: setup: cd 1: 2000000 Hz, bpw 8, mode 0x0 -> CS=00000001 CDIV=007d
[   15.008786] ads7846_device: SPI devices registered:
[   15.008797] ads7846_device:    hy28afb spi0.0 32000kHz 8 bits mode=0x03
[   15.008805] ads7846_device:    ads7846 spi0.1 2000kHz 8 bits mode=0x00
[   15.008807] ads7846_device:
[   15.208312] ads7846 spi0.1: setup: want 2000000 Hz; bus_hz=250000000 / cdiv=125 == 2000000 Hz; mode 0: cs 0x00000001
[   15.208346] ads7846 spi0.1: setup: cd 1: 2000000 Hz, bpw 8, mode 0x0 -> CS=00000001 CDIV=007d
[   15.221030] ads7846 spi0.1: touchscreen, irq 187
[   15.336256] input: ADS7846 Touchscreen as /devices/platform/bcm2708_spi.0/spi_master/spi0/spi0.1/input/input0
In order to use the touch panel with python, X, and to calibrate it, a few packages need loading :

Code: Select all

sudo apt-get update
sudo apt-get install libts-bin evtest xinput python-dev python-pip
Then use pip to install evdev :

Code: Select all

sudo pip install evdev
To calibrate the touch panel :

Code: Select all

sudo TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/event0 ts_calibrate
Use a stylus (or a pencil!) to select each point in turn. This will be the first time you see anything on the screen too ;)
Note that if you have other input devices, ie keyboard and/or mouse, /dev/input/event0 may be, for example /dev/input/event1 or /dev/input/event2 or /dev/input/event3, etc.

Here is a test python program than uses pygame :

Code: Select all

#!/usr/bin/python
# touchv5
# Texy 1/6/13

import pygame, sys, os, time
from pygame.locals import *

from evdev import InputDevice, list_devices
devices = map(InputDevice, list_devices())
eventX=""
for dev in devices:
    if dev.name == "ADS7846 Touchscreen":
        eventX = dev.fn
print eventX

os.environ["SDL_FBDEV"] = "/dev/fb1"
os.environ["SDL_MOUSEDRV"] = "TSLIB"
os.environ["SDL_MOUSEDEV"] = eventX

pygame.init()

# set up the window
screen = pygame.display.set_mode((320, 240), 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)
CYAN  = (  0, 255, 255)
MAGENTA=(255,   0, 255)
YELLOW =(255, 255,   0)
 
# Fill background
background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill(WHITE)
box = pygame.draw.rect(background, YELLOW,(0, 0, 40, 240))
box = pygame.draw.rect(background,  CYAN, (40, 0, 40, 240))
box = pygame.draw.rect(background, GREEN, (80, 0, 40, 240))
box = pygame.draw.rect(background,MAGENTA,(120, 0, 40, 240))
box = pygame.draw.rect(background, RED,   (160, 0, 40, 240))
box = pygame.draw.rect(background, BLUE  ,(200, 0, 40, 240))
box = pygame.draw.rect(background, BLACK ,(240, 0, 40, 240))

# Display some text
font = pygame.font.Font(None, 36)
text = font.render("Touch here", 1, (150, 10, 250))
#text = pygame.transform.rotate(text,270) 
textpos = text.get_rect(centerx=background.get_width()/2,centery=background.get_height()/2)
background.blit(text, textpos)

screen.blit(background, (0, 0))
pygame.display.flip()

running = True
# run the game loop
while running:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
            running = False  
        elif event.type == pygame.MOUSEBUTTONDOWN:
            print("Pos: %sx%s\n" % pygame.mouse.get_pos())
            if textpos.collidepoint(pygame.mouse.get_pos()):
                pygame.quit()
                sys.exit()
                running = False
        elif event.type == KEYDOWN and event.key == K_ESCAPE:
            running = False
    pygame.display.update()
The above is mainly a copy and paste from the first post of this htread, with alterations for the updated install and config. I will update the that post shortly.
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

Return to “HATs and other add-ons”