Touchscreen on a Raspberry Pi

Just got the most recent image of raspbian installed and evtest is in place and working. Note sure what I did to clobber the last one! This gives me a good place to start exploring the Elo characteristics. Thanks…

Finally have some time to work with the Elo touchscreen and have been following your input for the others trying to get the touchscreens working with oF.

First step was to see the contents of /dev/input:

USB devices connected: mouse, Elo-touchscreen, and keyboard

pi@raspberrypi /dev/input $ ls -la
total 0
drwxr-xr-x 4 root root 240 Jul 29 02:20 .
drwxr-xr-x 12 root root 3300 Jul 29 02:23 …
drwxr-xr-x 2 root root 160 Jul 29 02:20 by-id
drwxr-xr-x 2 root root 160 Jul 29 02:20 by-path
crw-rw—T 1 root input 13, 64 Jan 1 1970 event0
crw-rw—T 1 root input 13, 65 Jan 1 1970 event1
crw-rw—T 1 root input 13, 66 Jan 1 1970 event2
crw-rw—T 1 root input 13, 67 Jul 29 02:20 event3
crw-rw—T 1 root input 13, 0 Jul 29 02:20 js0
crw-rw—T 1 root input 13, 63 Jan 1 1970 mice
crw-rw—T 1 root input 13, 32 Jan 1 1970 mouse0
crw-rw—T 1 root input 13, 33 Jul 29 02:20 mouse1

USB devices connected: Elo-touchscreen and keyboard

pi@raspberrypi /dev/input $ ls -la
total 0
drwxr-xr-x 4 root root 200 Jul 29 02:26 .
drwxr-xr-x 12 root root 3280 Jul 29 02:26 …
drwxr-xr-x 2 root root 120 Jul 29 02:26 by-id
drwxr-xr-x 2 root root 120 Jul 29 02:26 by-path
crw-rw—T 1 root input 13, 65 Jan 1 1970 event1
crw-rw—T 1 root input 13, 66 Jan 1 1970 event2
crw-rw—T 1 root input 13, 67 Jul 29 02:20 event3
crw-rw—T 1 root input 13, 0 Jul 29 02:20 js0
crw-rw—T 1 root input 13, 63 Jan 1 1970 mice
crw-rw—T 1 root input 13, 33 Jul 29 02:20 mouse1

USB devices connected: mouse and keyboard

pi@raspberrypi /dev/input $ ls -la
total 0
drwxr-xr-x 4 root root 180 Jul 29 02:27 .
drwxr-xr-x 12 root root 3280 Jul 29 02:27 …
drwxr-xr-x 2 root root 120 Jul 29 02:27 by-id
drwxr-xr-x 2 root root 120 Jul 29 02:27 by-path
crw-rw—T 1 root input 13, 64 Jul 29 02:27 event0
crw-rw—T 1 root input 13, 65 Jan 1 1970 event1
crw-rw—T 1 root input 13, 66 Jan 1 1970 event2
crw-rw—T 1 root input 13, 63 Jan 1 1970 mice
crw-rw—T 1 root input 13, 32 Jul 29 02:27 mouse0

USB devices connected: keyboard only

pi@raspberrypi /dev/input $ ls -la
total 0
drwxr-xr-x 4 root root 140 Jul 29 02:27 .
drwxr-xr-x 12 root root 3260 Jul 29 02:27 …
drwxr-xr-x 2 root root 80 Jul 29 02:27 by-id
drwxr-xr-x 2 root root 80 Jul 29 02:27 by-path
crw-rw—T 1 root input 13, 65 Jan 1 1970 event1
crw-rw—T 1 root input 13, 66 Jan 1 1970 event2
crw-rw—T 1 root input 13, 63 Jan 1 1970 mice


Then explored the contents of /proc/bus/input/devices:

pi@raspberrypi /dev/input $ cat /proc/bus/input/devices
I: Bus=0003 Vendor=05ac Product=024f Version=0111
N: Name=“Apple Inc. Apple Keyboard”
P: Phys=usb-bcm2708_usb-1.3.4.3.2/input0
S: Sysfs=/devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4.3/1-1.3.4.3.2/1-1.3.4.3.2:1.0/0003:05AC:024F.0002/input/input1
U: Uniq=
H: Handlers=sysrq kbd event1
B: PROP=0
B: EV=120013
B: KEY=10000 0 0 0 0 0 0 1007b 1007 ff9f207a c14057ff ffbeffdf ffefffff ffffffff fffffffe
B: MSC=10
B: LED=1f

I: Bus=0003 Vendor=05ac Product=024f Version=0111
N: Name=“Apple Inc. Apple Keyboard”
P: Phys=usb-bcm2708_usb-1.3.4.3.2/input1
S: Sysfs=/devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4.3/1-1.3.4.3.2/1-1.3.4.3.2:1.1/0003:05AC:024F.0003/input/input2
U: Uniq=
H: Handlers=kbd event2
B: PROP=0
B: EV=13
B: KEY=3a 0 e0000 0 0 0
B: MSC=10

I: Bus=0003 Vendor=04e7 Product=0020 Version=0100
N: Name=“Elo TouchSystems, Inc. Elo TouchSystems 2700 IntelliTouch® USB Touchmonitor Interface”
P: Phys=usb-bcm2708_usb-1.3.4.4/input0
S: Sysfs=/devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4.4/1-1.3.4.4:1.0/0003:04E7:0020.0006/input/input5
U: Uniq=20000000
H: Handlers=mouse0 event0 js0
B: PROP=0
B: EV=1b
B: KEY=10000 0 0 0 0 0 0 0 0
B: ABS=100 3
B: MSC=10

I: Bus=0003 Vendor=413c Product=3010 Version=0100
N: Name=“HID 413c:3010”
P: Phys=usb-bcm2708_usb-1.3.4.2/input0
S: Sysfs=/devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4.2/1-1.3.4.2:1.0/0003:413C:3010.0007/input/input6
U: Uniq=
H: Handlers=mouse1 event3
B: PROP=0
B: EV=17
B: KEY=70000 0 0 0 0 0 0 0 0
B: REL=103
B: MSC=10


Finally used evtest to try to determine how to identify event sources:

Started with EVENT0:

pi@raspberrypi /dev/input $ evtest event0
Input driver version is 1.0.1
Input device ID: bus 0x3 vendor 0x4e7 product 0x20 version 0x100
Input device name: “Elo TouchSystems, Inc. Elo TouchSystems 2700 IntelliTouch® USB Touchmonitor Interface”
Supported events:
Event type 0 (EV_SYN)
Event type 1 (EV_KEY)
Event code 272 (BTN_LEFT)
Event type 3 (EV_ABS)
Event code 0 (ABS_X)
Value 0
Min 0
Max 4095
Event code 1 (ABS_Y)
Value 0
Min 0
Max 4095
Event code 40 (ABS_MISC)
Value 0
Min 0
Max 256
Event type 4 (EV_MSC)
Event code 4 (MSC_SCAN)
Properties:
Testing … (interrupt to exit)
Event: time 1438138289.399868, type 3 (EV_ABS), code 0 (ABS_X), value 1917
Event: time 1438138289.399868, type 3 (EV_ABS), code 1 (ABS_Y), value 2267
Event: time 1438138289.399868, type 3 (EV_ABS), code 40 (ABS_MISC), value 20
Event: time 1438138289.399868, -------------- SYN_REPORT ------------
Event: time 1438138289.407874, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90001
Event: time 1438138289.407874, type 1 (EV_KEY), code 272 (BTN_LEFT), value 1
Event: time 1438138289.407874, type 3 (EV_ABS), code 1 (ABS_Y), value 2266
Event: time 1438138289.407874, type 3 (EV_ABS), code 40 (ABS_MISC), value 21
Event: time 1438138289.407874, -------------- SYN_REPORT ------------
Event: time 1438138289.415885, type 3 (EV_ABS), code 1 (ABS_Y), value 2264
Event: time 1438138289.415885, type 3 (EV_ABS), code 40 (ABS_MISC), value 22
Event: time 1438138289.415885, -------------- SYN_REPORT ------------
Event: time 1438138289.463869, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90001
Event: time 1438138289.463869, type 1 (EV_KEY), code 272 (BTN_LEFT), value 0

which was the USB input connection from the Elo touchscreen, I then went through all the other events… and identified the keyboard and USB mouse.

But when I duplicated evtest for event0 after a reboot - it responded to the USB mouse! :

pi@raspberrypi /dev/input $ evtest event0
Input driver version is 1.0.1
Input device ID: bus 0x3 vendor 0x413c product 0x3010 version 0x100
Input device name: “HID 413c:3010”
Supported events:
Event type 0 (EV_SYN)
Event type 1 (EV_KEY)
Event code 272 (BTN_LEFT)
Event code 273 (BTN_RIGHT)
Event code 274 (BTN_MIDDLE)
Event type 2 (EV_REL)
Event code 0 (REL_X)
Event code 1 (REL_Y)
Event code 8 (REL_WHEEL)
Event type 4 (EV_MSC)
Event code 4 (MSC_SCAN)
Properties:
Testing … (interrupt to exit)
Event: time 1438139489.117737, type 2 (EV_REL), code 0 (REL_X), value 1
Event: time 1438139489.117737, type 2 (EV_REL), code 1 (REL_Y), value 3
Event: time 1438139489.117737, -------------- SYN_REPORT ------------
Event: time 1438139489.133749, type 2 (EV_REL), code 0 (REL_X), value -3
Event: time 1438139489.133749, type 2 (EV_REL), code 1 (REL_Y), value 3
Event: time 1438139489.133749, -------------- SYN_REPORT ------------
Event: time 1438139489.149752, type 2 (EV_REL), code 0 (REL_X), value -1
Event: time 1438139489.149752, type 2 (EV_REL), code 1 (REL_Y), value 3

Thus I assume that with multiple USB input devices, they can change each time you boot?? Note I had been unplugging and plugging devices to see what happened…

I haven’t started to modify the ofAppEGLWindow.cpp file and am not sure what “name” to use for the Elo device. Obviously an “eventX” name won’t work and for some others you suggested “ts-event” or “touchscreen” but I don’t see any reference to either in the info I’ve collected.

I also will try to change the “path” name as you’ve suggested.

I’ve also experienced the scaling issues that others have encountered but that is another issue for later.

Hope this info may give you some insight into the differences between the Elo and the TFT. Any and all input will be appreciated.

Cheers.

ADDENDUM:

I went ahead and tried the approach of mjuni and made the changes to “event-mouse”, /dev/input/ and BTN_TOUCH and unfortunately it didn’t “work”. The following is the result:

pi@raspberrypi ~/openFrameworks/apps/myApps/touchScreenBig $ make run
armv6l
checking pkg-config libraries: cairo zlib gstreamer-app-1.0 gstreamer-1.0 gstreamer-video-1.0 gstreamer-base-1.0 libudev freetype2 fontconfig sndfile openal openssl libpulse-simple alsa gtk±2.0 libmpg123
[warning] ofAppEGLWindow: init(): X11 not availble on RPI yet, using a native window instead
[notice ] ofAppEGLWindow: setupRPiNativeWindow(): screenRect: 1024x768
[notice ] ofAppEGLWindow: setupRPiNativeWindow(): windowRect: 500x500
[notice ] ofAppEGLWindow: createSurface(): setting up EGL Display
[notice ] ofAppEGLWindow: createSurface(): EGL Display correctly set
[notice ] ofAppEGLWindow: createSurface(): current renderer type: GL
[notice ] ofAppEGLWindow: createSurface(): default renderer detected
[notice ] ofAppEGLWindow: createSurface(): surface created correctly
[notice ] ofAppEGLWindow: createSurface(): API bound correctly
[notice ] ofAppEGLWindow: createSurface(): -----EGL-----
[notice ] ofAppEGLWindow: createSurface(): EGL_VERSION_MAJOR = 1
[notice ] ofAppEGLWindow: createSurface(): EGL_VERSION_MINOR = 4
[notice ] ofAppEGLWindow: createSurface(): EGL_CLIENT_APIS = OpenGL_ES OpenVG
[notice ] ofAppEGLWindow: createSurface(): EGL_VENDOR = Broadcom
[notice ] ofAppEGLWindow: createSurface(): EGL_VERSION = 1.4
[notice ] ofAppEGLWindow: createSurface(): EGL_EXTENSIONS = EGL_KHR_image EGL_KHR_image_base EGL_KHR_image_pixmap EGL_KHR_vg_parent_image EGL_KHR_gl_texture_2D_image EGL_KHR_gl_texture_cubemap_image EGL_KHR_lock_surface
[notice ] ofAppEGLWindow: createSurface(): GL_RENDERER = VideoCore IV HW
[notice ] ofAppEGLWindow: createSurface(): GL_VERSION = OpenGL ES-CM 1.1
[notice ] ofAppEGLWindow: createSurface(): GL_VENDOR = Broadcom
[notice ] ofAppEGLWindow: createSurface(): -------------
[notice ] ofAppEGLWindow: setupPeripherals(): peripheral setup complete
[notice ] ofAppEGLWindow: setupNativeUDev(): created udev object
[notice ] ofAppEGLWindow: setupMouse(): mouse_fd= -1 devicePath=/dev/input/by-path/event1
[ error ] ofAppEGLWindow: setupMouse(): did not open mouse
[ error ] ofAppEGLWindow: setupMouse(): did not open mouse, mouse_fd < 0
[notice ] ofAppEGLWindow: setupKeyboard(): keyboard_fd= 5 devicePath=/dev/input/by-path/platform-bcm2708_usb-usb-0:1.3.4.3.2:1.0-event-kbd
[notice ] ofAppEGLWindow: setupKeyboard(): keyboard device name = Apple Inc. Apple Keyboard
[notice ] ofAppEGLWindow: setupPeripherals(): native event setup complete
[notice ] ofAppEGLWindow: setupOpenGL(): peripheral setup complete
[notice ] ofAppEGLWindow: runAppViaInfiniteLoop(): entering infinite loop
[notice ] ofAppEGLWindow: runAppViaInfiniteLoop(): setting up notifications complete
[notice ] ofAppEGLWindow: destroyNativeKeyboard()
[notice ] ofAppEGLWindow: destroySurface(): destroying EGL surface

I used “js0” for the touch-mouse as that was the unique “event” name like “touchscreen” that was suggested for the TFT.

For some reason it though the mouse was event 1. Not sure this additional info will help?

To all:

Thanks for the input for this thread. Continuous “digesting” of the input from bakercp and mjuni paid off. Three changes to the file,

openframeworks/libs/openFrameworks/app/ofAppEGLWindow.cpp

involving: “event-mouse” —. “event1”

and “/dev/input/by-path” ----> “/dev/input/”

but keeping " BTN_LEFT" as that appears to be the support event for the Elo.

yielded success, and now screen touch events are active on an openFrameworks app window.

There are still some unresolved issues:

  • The Elo doesn’t always seem to be the “event0” device and I’m not sure how to force that to be the case.

  • at touch still produces an output (terminal)
    "[notice] ofAppEGLWindow: readMouseEvents(): unknown mouse axis (perhaps it’s a scroll wheel)

  • and the touch is improperly scaled/calibrated?

It appears as if others have encountered the calibration issue so that is the next challenge.

Thanks for all the input to date.

1 Like

found an adafruit admin mention this re: no touch

We don’t have any experience with OpenFrameworks, but it sounds like it’s looking at the wrong input device.

The touchscreen appears as /dev/touchscreen

dont know if this is a helpful tip… this is all way over my head

Nice :wink:

I’ve got those issues solved, in a few hours I will put my of AppEGLWindow.cpp changes. I’ve been very busy these days, give me a little more time to put it clean

I am who created that topic, admin made a mistake, touchscreen appears as /dev/input/touchscreen, i will put the changes that i made in ofAppEGLWindow soon

Take a look at this, I’ve made some changes on the original code to recognize adjust and scale touch events

ofAppEGLWindow.cpp-touchscreenModified

Hope will be useful for others
:wink:

1 Like

thank you mjuni!

I’m using your modified EGLwindow with a 2.8" piTFT and the ofxPiTFT addon.

The cursor moves now but is constrained to a small box in the top right corner of the screen. The axes are also inverted. Do I need to specify additional parameters somewhere? Should my main.cpp be set to full screen with the 320x240 resolution of my tft?

And is there any way to get rid of these extra icons… the cursor, this color cube thing, and the bottom of my screen also has a blinking white line.

To All who have commented on this thread. Building on all the input, particularly “bakercp”, I have the Elo working correctly with the Raspberry Pi. Though I had to modify

openFrameworks/libs/openFrameworks/app/ofAppEGLWindow.cpp

in ways somewhat similar to mjuni’s efforts with the adafruit TFT - there were notable differences and my sense is that each touchscreen will have some special features.

Unfortuantely I am leaving tomorrow morning for an extended trip and will not have time to effectively post what I did and why but will do so as soon as I can. :grin:

Thanks again to all who contributed, I would have never achieved success without your input.

Hi,

The colored square in the corner is an “under voltage” warning. It is possible to disable the warning, once you’re sure it is stable enough given your demands, and the power source you’re using.

I’ve done a fair amount of testing and found that a 5.25V 2 Amp USB power adapter from Adafruit works just fine for me. I’m using a WiFi key/mouse during setup, WiFi network adapter for remote access, outputting to a 5" HDMI touchscreen, driving a couple speakers, and using a rotary encoder. I tried up to 5Amps, etc etc, and continued to get the under voltage warning. So I just disabled it.

TO DISABLE UNDER VOLTAGE POWER SQUARE
sudo nano /boot/config.txt
add: avoid_warnings=1

NOTE:
avoid_warnings=1 removes the warning overlay.
avoid_warnings=2 additionally allows turbo when low-voltage is present.

Relevant discussion thread

Hi,

I´m working with a 4" waveshare spotpear screen.
I managed to get the screen working, but with some touch and scaling issues.
There´s no touch events without X running and the framebuffer copy does not scale to the LCD resolution.
It copies all the X framebuffer and scales down. I would like to get only the corner so we can have two screens, and keep a code editor running hd!

With the help of the forum I’ve resolved this issue for the Elo touchscreen. There were issues that appear to be unique to the Elo so I encourage those dealing with other touchscreens to follow this thread as their solution may differ.

The input devices that the Raspberry Pi recognize are in the directory /dev/input but are identified a number of different ways.


pi@raspberrypi /dev/input $ ls
by-id by-path event0 event1 event2 event3 js0 mice mouse0 mouse1
pi@raspberrypi /dev/input $ cd by-id
pi@raspberrypi /dev/input/by-id $ ls
usb-413c_3010-event-mouse
usb-413c_3010-mouse
usb-Apple_Inc._Apple_Keyboard-event-if01
usb-Apple_Inc._Apple_Keyboard-event-kbd
usb-Elo_TouchSystems__Inc._Elo_TouchSystems_2700_IntelliTouch_r__USB_Touchmonitor_Interfac_20000000-event-mouse
usb-Elo_TouchSystems__Inc._Elo_TouchSystems_2700_IntelliTouch_r__USB_Touchmonitor_Interfac_20000000-mouse


OF uses ofAppEGLWindow.ccp to deal with the mouse events and the touch events on the Elo appear as mouse clicks. The distribution of OF uses the directory “/dev/input/by-path/” to identify the mouse but that fails for the Elo. An alternative is to use the directory “/dev/input/by-id” and then to realize that in that directory there are two devices that end in the string “event-mouse”. To properly identify the Elo touch input as a mouse click, two changes to ofAppEGLWindow were required. Please note that the line numbers in my version of the OF code were slightly different than those that backercp cites at other point in this thread. The first change involved extending the device name to differentiate between the Elo “event-mouse” and the USB “event-mouse”


in file - ofAppEGLWindow.ccp ( beginning approximately line 115)

static int filter_mouse(const struct dirent *d) {
if(d->d_type != DT_DIR && string_ends_with(d->d_name,“20000000-event-mouse”)) {
return 1;
} else {
return 0;
}
}


The second modification was to change “/by-path/” to “/by-id/” in two locations as indicated below.


in file - ofAppEGLWindow.ccp (at approximately line 1340)

int n = scandir("/dev/input/by-id/", &eps, filter_mouse, dummy_sort);

devicePathBuffer.append("/dev/input/by-id/");


These two changes resulted in a screen touch on an OF app window being detected but a severe “calibration” problem still existed, somewhat similar to those encountered by “nidiffer” but requiring a different solution. Adding a couple of lines of code allowed me to touch the extremes of the screen and write the OF output to the terminal and determine how to scale the x and y axes. Then I modified the scaling in “ofAppEGLWindow” and those two code blocks are indicated below.


in file - ofAppEGLWindow.ccp (beginning approximately line 1670)

           case 0:
                if(ev.type == EV_REL) {
                    mouseEvent.x += amount * mouseScaleX; 
                } else {
                    
    	   // mouseEvent.x = ofMap(amount, 0, 4095, 0, currentWindowRect.width);
		cout << "amount.x  " << amount<<"\n";
		mouseEvent.x = (amount * 976)/4096;
		cout << "mouseEvent.x " << mouseEvent.x << "\n";
                }

            case 1:
                if(ev.type == EV_REL) {
                    mouseEvent.y += amount * mouseScaleY; 
                } else {
                 //   mouseEvent.y = ofMap(amount, 0, 4095, 0, currentWindowRect.height);
		cout << "amount.y  " << amount<<"\n";
		mouseEvent.y = (amount * 720)/4096;
		cout << "mouseEvent.y " << mouseEvent.y << "\n";

This allowed the use of the entire Elo screen and provided reasonably accurate touch input for numerous OF apps. Obviously all these changes are very hardware dependent but may help others dealing with this problem and with similar calibration problems.

Many thanks to bakercp and all the others for their assistance in resolving this challenge. This forum is a great OF resource!

1 Like

One note – RPI now has an “official” touchscreen that looks pretty slick.

Probably a tiny bit of work to support multi-touch in oF, but with ofxPointer and ofxTouchPad as examples it should be pretty easy to make implement it.

I have the official Raspberry Pi Touch Display, and am working on getting touch to work in an OF app. So far nothings working, I’ve tried ofxPointer to no avail. Anyone out there have any luck? Maybe someone has some thoughts that could point me in the right direction.

Right now, OF apps aren’t even recognizing the touch screen as a mouse, just like the above posts.

I successfully used my PQ Labs frame (but only single touch) with @retprof method.
I had to make some little changes :

  • use /dev/input/by-id/usb-PQLabs_EN400900319_EN400900319-event-if00
  • change the scale values. I used evtest to determine max values.

here’s a tiny addons made for the event input under linux maybe he can be useful to someone.

video:

you can perform a clean debugging for evtest in this way:

script -c 'evtest /dev/input/event0 | grep -E "ABS_X|ABS_Y|ABS_PRESSURE" | cut -d" " -f$(seq -s, 9 11) --only-delimited' --flush | tee -i /tmp/touch.log

Glad this worked for you. Everyone will need to adapt this for their own hardware.

Hi there,

Thanks to @kashim I made an addon for the Raspberry Pi 7" Touchscreen.
You can find it on github: https://github.com/apparentVJ/ofxRPiTouch

have fun :smile:

1 Like

Hey @floatLab - Looks like ofxRPiTouch was removed from your repository. Anyone else have this? Looking at messing around with this. That is unless it was included in the core or something.