1

So for the last 3 weeks I have been trying to get this touchscreen(3,5" Resistive) to work properly, but I cannot, for the life of me, figure it out!

I have made a very simple SDL 1.2 program that opens a window, and displays a clickable rectangle. The touch works... but when I "touch move" X the mouse moves Y and vice versa.

I am using Raspbian Stretch Lite, and are not using X11 for the SDL-1.2 program.

When I run "evtest" I can see that the axis is actually inverted, but if I run the tslib test program(when you can draw) the touch works beautifully.

Also if I add "/dev/input/touchscreen" into the program, the mouse just flickers and jumps around.

So could it be some sort of driver problem? or could it be a user error...?

  • I have this exact same issue. evtest shows inverted input, but ts_test and ts_calibrate work perfectly. I am using this with pygame and pygame.mouse.get_pos() returns the wonky inverted results that evtest does. Did you ever figure this out? – Villarrealized Oct 27 '18 at 5:08
  • Hi! Sorry no i did not... maybe its something wrong the screen itself? I don’t know. – Teodor Oct 28 '18 at 8:23
0

I had a very similar problem and when running ts_test and ts_calibrate I had perfect results. But when I used pygame to run a simple test program, the mouse was all over the place and very wonky.

I realized that the issue must be with pygame, but I couldn't figure out what it was. I guess I skipped over the suggestions from Adafruit in their guide, but eventually I figured out that the issue was with my SDL version. To solve it I used this script to downgrade SDL to 1.2 and now everything works properly!

#!/bin/bash

# enable wheezy package sources
echo "deb http://archive.raspbian.org/raspbian wheezy main
" > /etc/apt/sources.list.d/wheezy.list

# set wheezy as default package source
echo "APT::Default-release \"wheezy\";
" > /etc/apt/apt.conf.d/10defaultRelease

# set the priority for libsdl from wheezy higher than the stretch package
echo "Package: libsdl1.2debian
Pin: release n=stretch
Pin-Priority: -10
Package: libsdl1.2debian
Pin: release n=wheezy
Pin-Priority: 900
" > /etc/apt/preferences.d/libsdl

# install
apt-get update
apt-get -y --allow-downgrades install libsdl1.2debian/wheezy

And this is the code I used for a simple test in pygame. Before running the previous script, the mouse was unreliable and all over the place. After running the previous script, it was doing a great job tracking with my finger.

import pygame
import os
from time import sleep

os.environ['SDL_VIDEODRIVER'] = 'fbcon'
os.environ['SDL_FBDEV'] = '/dev/fb1'
os.environ['SDL_MOUSEDRV'] = 'TSLIB'
os.environ['SDL_MOUSEDEV'] = '/dev/input/event0'

pygame.init()
lcd = pygame.display.set_mode((320,480))
lcd.fill((0,0,0))

while True:
        for event in pygame.event.get():
                mouse_position = pygame.mouse.get_pos()
                print ""
                print ("Tap on window at: {}".format(mouse_position))
        pygame.display.update()
        sleep(0.02)

UPDATE:

For this example, in my /boot/config.txt I have the following setting:

dtoverlay=pitft35-resistive,rotate=0,speed=32000000,fps=60

And make sure to run ts_calibrate if you change the rotation.

sudo TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/event0
  • Hi! Wow this sounds promising! will try it as soon as I have my raspberry up and running again... thanks! /Teodor – Teodor Nov 17 '18 at 19:33
  • You're welcome! I hope it works for you :) – Villarrealized Nov 17 '18 at 20:00

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.