0

Adafuit 3.5 Touch Screen
Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Please be positive and constructive with your questions and comments.

Adafuit 3.5 Touch Screen

by bennshelfer on Sat Feb 13, 2021 1:18 pm

Hi

This is the screen | am using
https://www.adafruit.com/product/2441

I am using a Pi4B as a dev piece but will ultimately be using a ZeroW as the final product.

I am using the the Raspberry pi Lite OS which I have configured as follows:-
I have configured the Pi with a ssh.txt and then configured my Wifi and am running it in a headless mode using Putty.

Basic Setup
sudo apt update
sudo apt-get update
sudo apt-get upgrade
sudo reboot

Install Python3 and Other bits
sudo apt-get install -y python3-pip
pip3 install --upgrade setuptools
sudo apt-get install -y libatlas-base-dev libhdf5-dev libc-ares-dev libeigen3-dev build-essential libsdl-ttf2.0-0 python-pygame festival python3-h5py

Install the Screen as a Console
cd ~
sudo pip3 install --upgrade adafruit-python-shell click==7.0
sudo apt-get install -y git
git clone https://github.com/adafruit/Raspberry-P ... cripts.git
cd Raspberry-Pi-Installer-Scripts
sudo python3 adafruit-pitft.py --display=35r --rotation=90 --install-type=console
sudo reboot

Install pygame and gpio
sudo pip3 install pygame
sudo apt-get install rpi.gpio

From this setup I am able to boot the Pi and the console screen will appear.
I have written some python3 code and have set the screen colour to red

I am stuck with how once I have a python app running I can get touch coordinates from the screen.
I have searched but most of the setups are for the GUI, or am I missing something.

I would like to know what I need to do to be able to run a python3 app which will never stop and get touch screen coordinates

If you need more information pleas do not hesitate to ask.

Thanks in advance

Benn

bennshelfer
 
Posts: 11
Joined: Sat Feb 13, 2021 12:41 pm

Re: Adafuit 3.5 Touch Screen

by aharbick on Thu Feb 18, 2021 2:01 am

I have the same setup but I can't get the screen to show *anything*... I checked all of the the things here https://learn.adafruit.com/adafruit-pit ... rry-pi/faq but the screen doesn't show anything.

Do you know if there is a way to get diagnostics on the screen. It almost seems as if I have a defective screen...

Thanks,
Andy
aharbick
 
Posts: 7
Joined: Tue Oct 26, 2010 5:26 pm

Re: Adafuit 3.5 Touch Screen

by mikeysklar on Thu Feb 18, 2021 6:44 pm

Andy - Please don't hijack Benn's thread. You have a different issue if you have no output at all. Please start your own thread so we can debug your issue seperately.

Benn - I did not see any of your step including the setting up of the touchscreen for input. udev rules, eventX, evtest, manual calibration. You can skip the X Calibration since you are only interested in console mode.

https://learn.adafruit.com/adafruit-pit ... -2859004-4

mikeysklar
 
Posts: 3948
Joined: Mon Aug 01, 2016 8:10 pm

Re: Adafuit 3.5 Touch Screen

by bennshelfer on Sat Feb 20, 2021 10:00 am

Hi Mike

Thanks for replying

I have tried the process you suggested but it does not work for

sudo nano /etc/udev/rules.d/95-stmpe.rules
sudo rmmod stmpe_ts; sudo modprobe stmpe_ts
sudo apt-get install evtest tslib libts-bin

The first first two commands work correctly but the third one fails.
I have looked this up on various forums, lots of people with the same or similar issues.
All of their suggestions do not work for me.

The failure that I get is :
Reading package lists... 0%
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package tslib

https://www.impulseadventure.com/elec/rpi-install-tslib.html
I did find this website which had a useful run through which also tries to install tslib
It also fails.

There was more of the process which went into testing of tslib
I thought, what have I got tot loose, I will try it anyway.

Process:
sudo i2cdetect -y 1 => Worked Fine
ls -l /dev/input/touchscreen => Worked Fine -> Reported event0
sudo evtest /dev/input/touchscreen => Worked Fine
sudo TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/touchscreen ts_print => Did nothing for me but no errors aswell
sudo TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/touchscreen ts_test => Worked Fine, although I did to change 'fb1' to 'fb0'. 'fb1' does not exist on Pi

It seems I do not need the tslib file, I am not sure.

I am now moving on to try some python. I have create a very simple piece of code to colour the screen red.
This does not work for me. (Recurring Theme :-)).

My Code:
import pygame

pygame.init()
screen = pygame.display.set_mode([0,0])
red = [255, 0, 0]

screen.fill(red)
pygame.display.update()

If I run this code using the following command, it fails without a useful message.
python3 solidcolour.py

Error rReported:
pygame 2.0.0 (SDL 2.0.9, python 3.7.3)
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "solidcolour.py", line 4, in <module>
screen = pygame.display.set_mode([0,0])
pygame.error

There is no message for the pygame.error output. Not sure what that might mean.

Thank for your help this far.
I feel very close now.

Hope you can help me.
Pleas do not hesitate to ask if you have any questions

Many Thanks

Benn

bennshelfer
 
Posts: 11
Joined: Sat Feb 13, 2021 12:41 pm

Re: Adafuit 3.5 Touch Screen

by mikeysklar on Mon Feb 22, 2021 9:19 pm

Benn,

I was looking at one of our guides on getting started with pygame an the code was just a little different with the device name, putenv and resolution being specified for the lcd. Can you try some of these examples:

https://learn.adafruit.com/raspberry-pi ... s/overview

Code: Select all | TOGGLE FULL SIZE
pi@raspberrypi ~ $ sudo python
Python 2.7.3 (default, Mar 18 2014, 05:13:23)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
>>> import os
>>> os.putenv('SDL_FBDEV', '/dev/fb1')
>>> pygame.init()
(6, 0)
>>> lcd = pygame.display.set_mode((320, 240))
>>> lcd.fill((255,0,0))
<rect(0, 0, 320, 240)>
>>> pygame.display.update()
>>> pygame.mouse.set_visible(False)
1
>>> lcd.fill((0,0,0))
<rect(0, 0, 320, 240)>
>>> pygame.display.update()

mikeysklar
 
Posts: 3948
Joined: Mon Aug 01, 2016 8:10 pm

Re: Adafuit 3.5 Touch Screen

by bennshelfer on Sun Feb 28, 2021 8:03 am

Hi

Thanks for your help. I have tried that code, same error.

So I thought I would try and install the full blown version of Raspbain.
If I now run the code and the system is in console mode, I get the same error.

If I put the system into GUI mode, using this command
sudo python3 adafruit-pitft.py --display=35r --rotation=90 --install-type=fbcp
I get the following error
===================================================================================================================
PITFT Created symlink /etc/systemd/system/multi-user.target.wants/fbcp.service → /etc/systemd/system/fbcp.service.

Setting raspi-config to boot to desktop w/o login...
Configuring boot/config.txt for forced HDMI
Traceback (most recent call last):
File "adafruit-pitft.py", line 699, in <module>
main()
File "/usr/lib/python3/dist-packages/click/core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "/usr/lib/python3/dist-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/usr/lib/python3/dist-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/lib/python3/dist-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "adafruit-pitft.py", line 684, in main
if not install_fbcp():
File "adafruit-pitft.py", line 431, in install_fbcp
default_orientation = int(list(fbcp_rotations.keys())[list(fbcp_rotations.values()).index("0")])
UnboundLocalError: local variable 'fbcp_rotations' referenced before assignment
================================================================================================================

I have bodged the code/install script (adafruit-pitft.py) so that I will now install with a hardcoded configuration.
With this, I am not sure what is wrong, some bug in the code maybe

If I now run the same python code, it works.

Seems something is missing in console mode.

I have tried to switch back to console and tried the code again, it failed.
Going back to GUI mode, it starts to work again.

Is it possible to run pygame apps in console mode?

I am now going to try and get some touch screen coordinates going with some graphics and we will see what happens.

Many Thanks for all you help, it has been really useful.

Benn

bennshelfer
 
Posts: 11
Joined: Sat Feb 13, 2021 12:41 pm

Re: Adafuit 3.5 Touch Screen

by mikeysklar on Sun Feb 28, 2021 3:54 pm

Benn,

So things are working for you in GUI mode?

On some of other PiTFT dispays we are using a kernel pinning technique (locking into an older kernel release) to resolve some support issues. This could be an option to try:

https://learn.adafruit.com/adafruit-min ... leshooting

You are supposed to be able to run pygame in console mode:

https://learn.adafruit.com/adafruit-pit ... 2982158-45

mikeysklar
 
Posts: 3948
Joined: Mon Aug 01, 2016 8:10 pm

Re: Adafuit 3.5 Touch Screen

by bennshelfer on Wed Mar 03, 2021 5:03 pm

Hi Mike

Thank you for your reply.

I have tried that process.

My error is now different.

error PyGame.Error: Unable to Open a Terminal Console

I have quickly looked this up and it states you need a GUI screen something even if it is a HDMI screen
I do not have any screen running in a GUI mode at the moment.

Any help will be appreciated.

Benn

bennshelfer
 
Posts: 11
Joined: Sat Feb 13, 2021 12:41 pm

Re: Adafuit 3.5 Touch Screen

by mikeysklar on Thu Mar 04, 2021 7:37 pm

Benn,

It sounds as if you are getting really close now.

I see two options to proceeed:

1) Use the GUI version of Pi OS it sounds as though you might have installed the LITE version is that correct?

2) follow the recommended "dummy" console setting addion before calling pygame.init

Code: Select all | TOGGLE FULL SIZE
os.environ["SDL_VIDEODRIVER"] = "dummy"
pygame.init()


https://www.raspberrypi.org/forums/view ... hp?t=46096

mikeysklar
 
Posts: 3948
Joined: Mon Aug 01, 2016 8:10 pm

Re: Adafuit 3.5 Touch Screen

by bennshelfer on Fri Mar 05, 2021 1:48 pm

HI Mike

Thanks for your help again

I have made it work on a full blown version of raspbian

So I thought I would be brave and try the lite version

Went through the same install process and it worked straight away

I think it was all down to the firmware version.

The other issues was my bad.
Not sure what was going on.

Again, I can't you thank you enough for your help.

Benn

bennshelfer
 
Posts: 11
Joined: Sat Feb 13, 2021 12:41 pm

Re: Adafuit 3.5 Touch Screen

by bennshelfer on Fri Mar 05, 2021 1:48 pm

HI Mike

Thanks for your help again

I have made it work on a full blown version of raspbian

So I thought I would be brave and try the lite version

Went through the same install process and it worked straight away

I think it was all down to the firmware version.

The other issues was my bad.
Not sure what was going on.

Again, I can't you thank you enough for your help.

Benn

bennshelfer
 
Posts: 11
Joined: Sat Feb 13, 2021 12:41 pm

Re: Adafuit 3.5 Touch Screen

by bennshelfer on Sat Mar 06, 2021 8:24 am

Hi Mike

I have been premature.

I have tried your extra command in the Python code.

If I run the code as python2, the code runs and I get an image on the screen.
If I run the code as python3, the code runs but I there is no image on my screen.

If I remove the new line of code, I get the following.
It seems to run under Python 2 but not under Python 3.

From python3, without the new line of code, I get a blank pygame error (no text).

I have checked the modules that are loaded for each and have added the missing ones that were in Python 2 but not in Python 3.

This has made no difference.

Stuck.

Many Thanks

Benn

bennshelfer
 
Posts: 11
Joined: Sat Feb 13, 2021 12:41 pm

Re: Adafuit 3.5 Touch Screen

by nic579 on Mon Mar 08, 2021 8:54 am

Look here for the information on getting touchscreen working: https://www.raspberrypi.org/forums/view ... p?t=250001

The supplied libsdl does not seem to have the libts compiled into it. In that post you can either download his pre-compiled .dep or compile your own from the instructions. I have tested both and both work with one issue that the compile instructions are a bit confusing or slightly incorrect.

nic579
 
Posts: 42
Joined: Thu Sep 27, 2012 10:49 am

Re: Adafuit 3.5 Touch Screen

by bennshelfer on Wed Mar 10, 2021 6:09 am

Hi Nic

I did find this process and have tried it, there is a but.

I did not work for me at the time.

I have noticed that the touch screen drivers seem to install a version of SDL.
I don't think that the dropbox download version of the process would overwrite the module if it is already installed.

Just to clarify, I think I to do the dropbox process before I install the touch screen drivers.
This way the files will install and they won't be updated by the touch screen drivers install.

Can you tell me if my assumption is correct?

Many Thanks

Benn

bennshelfer
 
Posts: 11
Joined: Sat Feb 13, 2021 12:41 pm

Re: Adafuit 3.5 Touch Screen

by nic579 on Wed Mar 10, 2021 12:21 pm

Do the adafruit bit first but ultimately unless you reinstall the sdl version that lacks the touch screen lib you should be fine either way. Remember for full screen native on SDL you want the pi tp boot to console on the pitft. FYI I did have Pygame and Python installed before this dep was installed.

It would be great if someone at Adafruit built the dep with support and made it part of their installer.


It is not rocket science and is more of a gotcha need to know which most people dont know and waste time trying to find out. Many never do find the solution! Why I posted here. I think many people shop here expecting good support but what is going on with the touch screen drivers is anything but that.

nic579
 
Posts: 42
Joined: Thu Sep 27, 2012 10:49 am

Please be positive and constructive with your questions and comments.