0

PiTFT 3.5" driver conflict
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.

PiTFT 3.5" driver conflict

by bradallen on Wed Sep 12, 2018 11:21 pm

I am attempting to create a GUI on a Raspberry pi 3.5" TFT touchscreen using python3 and the graphics module. My program works on my HDMI display with the Rpi but does not work on the touchscreen display. I get the error below. This same error occurs if I create a very simple "Hello World" tkinter program. I have tried all sorts of long-shot fixes I found on various bulletin boards and nothing works.

The error indicates it is occurring when the AditHome.py script imports graphics.py. It appears to be some sort of display variable conflict. Any suggestions?

I actually had a cheap Amazon display that I sent back because they could not resolve this issue. I was sure the Adafruit driver would not conflict with tkinter which is a standard python3 module. It does. I am at the start of this project and simply want to create a GUI interface for the touchscreen. Can you suggest a python3 module that will work seamlessly with your display?

This is the error:

Traceback (most recent call last):
File "/pyprograms/AditHome.py", line 4, in <module>
from graphics import *
File "/pyprograms/graphics.py", line 185, in <module>
_root = tk.Tk()
File "/usr/lib/python3.5/tkinter/__init__.py", line 1880, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable

bradallen
 
Posts: 3
Joined: Wed Sep 12, 2018 10:56 pm

Re: PiTFT 3.5" driver conflict

by adafruit_support_mike on Thu Sep 13, 2018 1:46 am

That error probably means you're trying to run the code outside of an X-windows session.

The easiest way to work around the problem would be to reconfigure the PiTFT so it mirrors the HDMI output. You mentioned that the code already works there, and that should carry over directly to the PiTFT.

adafruit_support_mike
 
Posts: 53579
Joined: Thu Feb 11, 2010 2:51 pm

Re: PiTFT 3.5" driver conflict

by bradallen on Thu Sep 13, 2018 8:39 pm

Thank you for your suggestions. I have it running and here are the results for those who might have similar issues:

1. Python programs that use tkinter and that includes graphics (which is a simple, easy to use graphics module for python3) require an open window to work within. There are discussions on how to use a minimal window to do this but I was not able to make that work (I would just get a blank screen). Run python script with an open window

2. Set up the touchscreen with HDMI mirror as you suggest.

3. I wanted the GUI interface to open on startup. This caused a lot of pain as most forums point towards autostart file in the wrong directory (it's not clear to me why that whole structure is still there but I'm sure there is some good reason). The end result was to open and modify this autostart file:

nano ~/.config/lxsession/LXDE-pi/autostart

4. Then add a final line that looks like this:

@python3 /home/pi/<yourdirectory>/<yourapp>.py

5. It also helps to configure the touchscreen to 720x480 which is 1.5 times the native resolution of the touchscreen.

It's working beautifully. Great little touchscreen with far better display and touchscreen mechanics than the cheap Amazon one I tried first. Adafruit is definitely my go-to source.

bradallen
 
Posts: 3
Joined: Wed Sep 12, 2018 10:56 pm

Re: PiTFT 3.5" driver conflict

by adafruit_support_mike on Fri Sep 14, 2018 12:20 am

Glad to hear you got it working, and thanks for posting the follow-up!

adafruit_support_mike
 
Posts: 53579
Joined: Thu Feb 11, 2010 2:51 pm

Re: PiTFT 3.5" driver conflict

by CoreyWC1 on Tue Oct 02, 2018 1:15 pm

bradallen wrote:Thank you for your suggestions. I have it running and here are the results for those who might have similar issues:

1. Python programs that use tkinter and that includes graphics (which is a simple, easy to use graphics module for python3) require an open window to work within. There are discussions on how to use a minimal window to do this but I was not able to make that work (I would just get a blank screen). Run python script with an open window

2. Set up the touchscreen with HDMI mirror as you suggest.

3. I wanted the GUI interface to open on startup. This caused a lot of pain as most forums point towards autostart file in the wrong directory (it's not clear to me why that whole structure is still there but I'm sure there is some good reason). The end result was to open and modify this autostart file:

nano ~/.config/lxsession/LXDE-pi/autostart

4. Then add a final line that looks like this:

@python3 /home/pi/<yourdirectory>/<yourapp>.py

5. It also helps to configure the touchscreen to 720x480 which is 1.5 times the native resolution of the touchscreen.

It's working beautifully. Great little touchscreen with far better display and touchscreen mechanics than the cheap Amazon one I tried first. Adafruit is definitely my go-to source.

how do you do the part about modifying the autostart file?

CoreyWC1
 
Posts: 6
Joined: Tue Oct 02, 2018 10:02 am

Re: PiTFT 3.5" driver conflict

by bradallen on Wed Oct 10, 2018 8:05 am

Type this line into the command line on the pi: nano ~/.config/lxsession/LXDE-pi/autostart
Nano is the command line editor.
Then add the line: @python3 /home/pi/<yourdirectory>/<yourapp>.py
to the autostart using the nano editor

bradallen
 
Posts: 3
Joined: Wed Sep 12, 2018 10:56 pm

Please be positive and constructive with your questions and comments.