Teensy 4 and TouchScreenUSB

wagetops

Member
Hi,

I'm trying to get multi touch working on a windows 10 machine, but failing miserably. The teensy crashes any time I try to call TouchScreenUSB.press :(

I have a Teensy 4.0, with Arduino 1.8.12 and Teensyduino 1.51 beta.

I have also tried with arduino 1.8.11 and Teensyduino 1.50 with the same results.

The code below prints "press" only one time then stops executing.

Any ideas?!

Thanks

Code:
int yoffset = 8000;

void setup() {
  TouchscreenUSB.begin();
}

void drawcircle(int x, int y) {
  float arc = 2.0 * PI / 10.0;
  float r = 3000.0;
  for (float angle=0; angle < arc; angle += 0.01) {
    for (int i=0; i < 10; i++) {
      float ph = arc * (float)i;
      TouchscreenUSB.press(i, r * cosf(angle+ph) + x, r * sinf(angle+ph) + y);
    }
    delay(10);
  }
  for (int i=0; i < 10; i++) {
    TouchscreenUSB.release(i);
  }
}

void loop() {
    delay(2000);
    Serial.println("press");
    drawcircle(16000, yoffset);
    yoffset += 4200;
    if (yoffset > 24000) yoffset = 8000;
}
 
MacOS 10.13.6, Arduino 1.8.12, TD1.51beta1

Tried both the touchscreen examples on T4 and indeed the T4 crashes after executing the TouchScreenUSB.press commands, so I suspect there might a problem with the TouchscreenUSB.release command.
After the crash T4 is unresponsive and needs to be put in program mode to upload new code.

Both examples were tested to work fine with TLC, T3.2 & T3.6
 
That agrees with results by @neurofun as well. First indication of usage and wasn't changed since enabled on T_4 IIRC.

Will have to be on Paul's list to resolve.
 
I've been investigating this problem for the last couple days. There seems to be a subtle bug somewhere in the HID-based serial emulation. I still haven't found actual root cause of the problem. Very frustrating!

But I do have a workaround for crashing. Here it is:

https://github.com/PaulStoffregen/cores/commit/b141c8b562d93d48eeb9b8c87d421fac0ac0b20b

Next week we'll begin beta testing 1.52. The easiest thing is to just wait for a 1.52-beta1 installer, which should be available in a matter of days.

If you want to fix sooner, you can try to manually edit {Arduino}/hardware/teensy/avr/cores/teensy4/usb.c. But quite a large number of changes have gone into other parts of the USB code, so simply pulling some files off github and putting them into a 1.51 install may or may not work.

FWIW, here is a program which reproduces the remaining bug. It should print the 4 words press, begin, release, done as it runs. It does indeed, but occasionally some of the words appear twice in the serial monitor. It's definitely a bug in the HID-based serial emulation code. This will remain on my list of known bugs, but at a lower priority (unless anyone can reproduce a more severe problem like crashing... which will prompt me to raise it back up to high priority).

Code:
int yoffset = 7000;

void setup() {
  TouchscreenUSB.begin();
}

void drawcircle(int x, int y) {
  Serial.println("begin");
  Serial.send_now();
  delay(100);
  float arc = 2.0 * PI / 10.0;
  float r = 300.0;
  for (float angle = 0; angle < arc; angle += 0.1) {
    for (int i = 0; i < 10; i++) {
      float ph = arc * (float)i;
      TouchscreenUSB.press(i, r * cosf(angle + ph) + x, r * sinf(angle + ph) + y);
    }
    delay(10);
  }
  Serial.println("release");
  Serial.send_now();
  delay(100);
  for (int i = 0; i < 10; i++) {
    TouchscreenUSB.release(i);
  }
  Serial.println("done");
  Serial.send_now();
  delay(100);
}

void loop() {
  delay(2000);
  Serial.println("press");
  //Serial.send_now();
  delay(100);
  drawcircle(30000, yoffset);
  //yoffset += 4200;
  //if (yoffset > 24000) yoffset = 8000;
}
 
This is great!

I have resorted to a 3.2 for the HID part of my project for the time being, but am keen to try it on the 4.

On a related note, I did notice on the 3.2 that multitouch was not actually working correctly. In that touches were being registered individually in quick succession, which meant that gestures and such were not working (pinch to zoom for instance).

It was because the HID report was not including the Contact Count (0x54).

Anyway, I updated the Teensy3 core and now it works great.

This is the post I made about that issue, with a link to the PR

https://forum.pjrc.com/threads/59812-Teensy-3-multi-touch-report-descriptor

Thanks!!
 
I am also encountering this issue. Teensy 4, Windows 10, Arduino 1.8.12, Teensyduino 1.51 stable. I may try 1.52 beta at some point I guess.

before finding this thread i modified the sample SingleFingerLine to also use the LED. What I have seen is that the first button press works, the second button press the LED stays on.

Code:
#include <Bounce.h>
int led = 13;

Bounce mybutton = Bounce(14, 10);
int yoffset = 1000;

void setup() {
  pinMode(14, INPUT_PULLUP);
  pinMode(led, OUTPUT);
  TouchscreenUSB.begin();
}

void drawline(int x, int y) {
  digitalWrite(led, HIGH); 
 for (int i=0; i < 6000; i += 100) {
   TouchscreenUSB.press(0, x + i, y + i/13);
   delay(10);
 }
 TouchscreenUSB.release(0);
 delay(1000);
  digitalWrite(led, LOW); 
}

void loop() {
  mybutton.update();
  if (mybutton.fallingEdge()) {
    Serial.println("press");
    drawline(16000, yoffset);
    yoffset += 1200;
    if (yoffset > 24000) yoffset = 4000;
  }
}
 
Some further information which may be useful (or not).
I have compared the HID report descriptor from USBlyzer for the Teensy4.0 and a working external touchscreen (Asus Zenscreen Touch)

Teensy 4.0 HID Report Descriptor

Code:
Interface 3 HID Report Descriptor Touch Screen
Item Tag (Value) Raw Data 
Usage Page (Digitizer) 05 0D  
Usage (Touch Screen) 09 04  
Collection (Application) A1 01  
    Usage (Finger) 09 22  
    Collection (Logical) A1 02  
        Usage (Tip Switch) 09 42  
        Logical Minimum (0) 15 00  
        Logical Maximum (1) 25 01  
        Report Size (1) 75 01  
        Report Count (1) 95 01  
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02  
        Usage (Contact Identifier) 09 51  
        Logical Maximum (127) 25 7F  
        Report Size (7) 75 07  
        Report Count (1) 95 01  
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02  
        Usage (Tip Pressure) 09 30  
        Logical Maximum (255) 26 FF 00  
        Report Size (8) 75 08  
        Report Count (1) 95 01  
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02  
        Usage Page (Generic Desktop) 05 01  
        Usage (X) 09 30  
        Usage (Y) 09 31  
        Logical Maximum (32767) 26 FF 7F  
        Unit (None) 65 00  
        Report Size (16) 75 10  
        Report Count (2) 95 02  
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02  
    End Collection C0  
    Usage Page (Digitizer) 05 0D  
    Logical Maximum (65535) 27 FF FF 00 00  
    Report Size (16) 75 10  
    Report Count (1) 95 01  
    Usage (Scan Time) 09 56  
    Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02  
    Usage (Contact Count) 09 54  
    Logical Maximum (127) 25 7F  
    Report Count (1) 95 01  
    Report Size (8) 75 08  
    Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02  
    Usage Page (Digitizer) 05 0D  
    Usage (Contact Count Maximum) 09 55  
    Logical Maximum (10) 25 0A  
    Report Size (8) 75 08  
    Report Count (1) 95 01  
    Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02  
End Collection C0

And the ASUS Zenscreen Touch

Code:
Interface 0 HID Report Descriptor Touch Screen
Item Tag (Value) Raw Data 
Usage Page (Digitizer) 05 0D  
Usage (Touch Screen) 09 04  
Collection (Application) A1 01  
    Report ID (6) 85 06  
    Usage Page (Digitizer) 05 0D  
    Usage (Contact Count) 09 54  
    Report Size (8) 75 08  
    Logical Minimum (0) 15 00  
    Logical Maximum (12) 25 0C  
    Report Count (1) 95 01  
    Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02  
    Usage (Finger) 09 22  
    Collection (Logical) A1 02  
        Usage (Tip Switch) 09 42  
        Logical Minimum (0) 15 00  
        Logical Maximum (1) 25 01  
        Report Size (1) 75 01  
        Report Count (1) 95 01  
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02  
        Report Count (7) 95 07  
        Input (Cnst,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 03  
        Report Size (8) 75 08  
        Usage (Contact Identifier) 09 51  
        Report Count (1) 95 01  
        Logical Minimum (0) 15 00  
        Logical Maximum (31) 25 1F  
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02  
        Usage Page (Generic Desktop) 05 01  
        Logical Maximum (4095) 26 FF 0F  
        Report Size (16) 75 10  
        Unit Exponent (-2) 55 0E  
        Unit (SI Lin: Length (cm)) 65 11  
        Usage (X) 09 30  
        Physical Minimum (0) 35 00  
        Physical Maximum (3465) 46 89 0D  
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02  
        Physical Maximum (1945) 46 99 07  
        Usage (Y) 09 31  
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02  
        Report Size (8) 75 08  
        Report Count (2) 95 02  
        Input (Cnst,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 03  
        Input (Cnst,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 03  
    End Collection C0  
    Usage Page (Digitizer) 05 0D  
    Usage (Finger) 09 22  
    Collection (Logical) A1 02  
        Usage (Tip Switch) 09 42  
        Logical Minimum (0) 15 00  
        Logical Maximum (1) 25 01  
        Report Size (1) 75 01  
        Report Count (1) 95 01  
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02  
        Report Count (7) 95 07  
        Input (Cnst,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 03  
        Report Size (8) 75 08  
        Usage (Contact Identifier) 09 51  
        Report Count (1) 95 01  
        Logical Minimum (0) 15 00  
        Logical Maximum (31) 25 1F  
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02  
        Usage Page (Generic Desktop) 05 01  
        Logical Maximum (4095) 26 FF 0F  
        Report Size (16) 75 10  
        Unit Exponent (-2) 55 0E  
        Unit (SI Lin: Length (cm)) 65 11  
        Usage (X) 09 30  
        Physical Minimum (0) 35 00  
        Physical Maximum (3465) 46 89 0D  
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02  
        Physical Maximum (1945) 46 99 07  
        Usage (Y) 09 31  
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02  
        Report Size (8) 75 08  
        Report Count (2) 95 02  
        Input (Cnst,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 03  
        Input (Cnst,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 03  
    End Collection C0  
    Usage Page (Digitizer) 05 0D  
    Usage (Finger) 09 22  
    Collection (Logical) A1 02  
        Usage (Tip Switch) 09 42  
        Logical Minimum (0) 15 00  
        Logical Maximum (1) 25 01  
        Report Size (1) 75 01  
        Report Count (1) 95 01  
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02  
        Report Count (7) 95 07  
        Input (Cnst,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 03  
        Report Size (8) 75 08  
        Usage (Contact Identifier) 09 51  
        Report Count (1) 95 01  
        Logical Minimum (0) 15 00  
        Logical Maximum (31) 25 1F  
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02  
        Usage Page (Generic Desktop) 05 01  
        Logical Maximum (4095) 26 FF 0F  
        Report Size (16) 75 10  
        Unit Exponent (-2) 55 0E  
        Unit (SI Lin: Length (cm)) 65 11  
        Usage (X) 09 30  
        Physical Minimum (0) 35 00  
        Physical Maximum (3465) 46 89 0D  
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02  
        Physical Maximum (1945) 46 99 07  
        Usage (Y) 09 31  
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02  
        Report Size (8) 75 08  
        Report Count (2) 95 02  
        Input (Cnst,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 03  
        Input (Cnst,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 03  
    End Collection C0  
    Usage Page (Digitizer) 05 0D  
    Usage (Finger) 09 22  
    Collection (Logical) A1 02  
        Usage (Tip Switch) 09 42  
        Logical Minimum (0) 15 00  
        Logical Maximum (1) 25 01  
        Report Size (1) 75 01  
        Report Count (1) 95 01  
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02  
        Report Count (7) 95 07  
        Input (Cnst,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 03  
        Report Size (8) 75 08  
        Usage (Contact Identifier) 09 51  
        Report Count (1) 95 01  
        Logical Minimum (0) 15 00  
        Logical Maximum (31) 25 1F  
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02  
        Usage Page (Generic Desktop) 05 01  
        Logical Maximum (4095) 26 FF 0F  
        Report Size (16) 75 10  
        Unit Exponent (-2) 55 0E  
        Unit (SI Lin: Length (cm)) 65 11  
        Usage (X) 09 30  
        Physical Minimum (0) 35 00  
        Physical Maximum (3465) 46 89 0D  
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02  
        Physical Maximum (1945) 46 99 07  
        Usage (Y) 09 31  
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02  
        Report Size (8) 75 08  
        Report Count (2) 95 02  
        Input (Cnst,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 03  
        Input (Cnst,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 03  
    End Collection C0  
    Usage Page (Digitizer) 05 0D  
    Usage (Finger) 09 22  
    Collection (Logical) A1 02  
        Usage (Tip Switch) 09 42  
        Logical Minimum (0) 15 00  
        Logical Maximum (1) 25 01  
        Report Size (1) 75 01  
        Report Count (1) 95 01  
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02  
        Report Count (7) 95 07  
        Input (Cnst,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 03  
        Report Size (8) 75 08  
        Usage (Contact Identifier) 09 51  
        Report Count (1) 95 01  
        Logical Minimum (0) 15 00  
        Logical Maximum (31) 25 1F  
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02  
        Usage Page (Generic Desktop) 05 01  
        Logical Maximum (4095) 26 FF 0F  
        Report Size (16) 75 10  
        Unit Exponent (-2) 55 0E  
        Unit (SI Lin: Length (cm)) 65 11  
        Usage (X) 09 30  
        Physical Minimum (0) 35 00  
        Physical Maximum (3465) 46 89 0D  
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02  
        Physical Maximum (1945) 46 99 07  
        Usage (Y) 09 31  
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02  
        Report Size (8) 75 08  
        Report Count (2) 95 02  
        Input (Cnst,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 03  
        Input (Cnst,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 03  
    End Collection C0  
    Usage Page (Digitizer) 05 0D  
    Logical Minimum (0) 17 00 00 00 00  
    Logical Maximum (2147483647) 27 FF FF FF 7F  
    Report Size (32) 75 20  
    Report Count (1) 95 01  
    Unit Exponent (0) 55 00  
    Unit (None) 65 00  
    Usage (Scan Time) 09 56  
    Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02  
    Usage (Contact Count Maximum) 09 55  
    Report ID (14) 85 0E  
    Usage (Device Identifier) 09 53  
    Report Size (8) 75 08  
    Report Count (2) 95 02  
    Logical Maximum (128) 26 80 00  
    Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02  
    Usage Page (Vendor-Defined 1) 06 00 FF  
    Usage (Vendor-Defined 197) 09 C5  
    Report ID (7) 85 07  
    Logical Minimum (0) 15 00  
    Logical Maximum (255) 26 FF 00  
    Report Size (8) 75 08  
    Report Count (256) 96 00 01  
    Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02  
End Collection C0  
Usage Page (Vendor-Defined 1) 06 00 FF  
Usage (Vendor-Defined 1) 09 01  
Collection (Application) A1 01  
    Usage (Vendor-Defined 1) 09 01  
    Logical Minimum (0) 15 00  
    Logical Maximum (255) 26 FF 00  
    Report ID (3) 85 03  
    Report Size (8) 75 08  
    Report Count (63) 95 3F  
    Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02  
    Usage Page (Vendor-Defined 1) 06 00 FF  
    Usage (Vendor-Defined 1) 09 01  
    Logical Minimum (0) 15 00  
    Logical Maximum (255) 26 FF 00  
    Report Size (8) 75 08  
    Report Count (63) 95 3F  
    Output (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) 91 02  
End Collection C0  
Usage Page (Digitizer) 05 0D  
Usage (Configuration) 09 0E  
Collection (Application) A1 01  
    Report ID (5) 85 05  
    Usage (Finger) 09 22  
    Collection (Logical) A1 02  
        Usage (Device Mode) 09 52  
        Usage (Device Identifier) 09 53  
        Logical Minimum (0) 15 00  
        Logical Maximum (10) 25 0A  
        Report Size (8) 75 08  
        Report Count (2) 95 02  
        Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02  
    End Collection C0  
End Collection C0  
Usage Page (Generic Desktop) 05 01  
Usage (Mouse) 09 02  
Collection (Application) A1 01  
    Report ID (1) 85 01  
    Usage (Pointer) 09 01  
    Collection (Logical) A1 02  
        Usage Page (Button) 05 09  
        Usage Minimum (Button 1) 19 01  
        Usage Maximum (Button 2) 29 02  
        Logical Minimum (0) 15 00  
        Logical Maximum (1) 25 01  
        Report Count (2) 95 02  
        Report Size (1) 75 01  
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02  
        Report Count (1) 95 01  
        Report Size (6) 75 06  
        Input (Cnst,Ary,Abs) 81 01  
        Usage Page (Generic Desktop) 05 01  
        Usage (X) 09 30  
        Usage (Y) 09 31  
        Logical Minimum (0) 16 00 00  
        Logical Maximum (4095) 26 FF 0F  
        Physical Minimum (0) 36 00 00  
        Physical Maximum (1945) 46 99 07  
        Unit (None) 66 00 00  
        Report Size (16) 75 10  
        Report Count (2) 95 02  
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02  
    End Collection C0  
End Collection C0

Also when the ZenscreenTouch is used I get Pen & Touch and Tablet PC Settings become available in Control Panel\Hardware and Sound

I'm still learning on the USB front but am getting more knowledgeable every day :)
 
Tested with the released Teensyduino 1.52 and still no touchscreen or multitouch emulation functionality.

The teensy4.0 does not seem to properly be recognised as a touchscreen by Windows 10 as the Pen & Touch and Tablet PC Settings do NOT become available in Control Panel\Hardware and Sound.

Is this being looked at by anyone that knows the usb code more intimately?
 
Latest update.

Now tried running with 1.53-beta3 Arduino 1.8.13 on Windows 10.
Have tried Pauls sketch from message #7. The touchscreen still does not work and also I am seeing some corruption on the serial monitor.
Also tried Sinsids sketch from message #12 but still nothing.

I think the that although the device is listed as hid-touchscreen in device manager the fact that there is no real recognition as a touchscreen by Windows 10 as the Pen & Touch and Tablet PC Settings do NOT become available in Control Panel\Hardware and Sound.
This means that it isn't really working as it should and I was really wanting this functionality with the Teensy.

Will this be looked at by the development team? Otherwise it looks like I will have to use another platform for this development as the Teensy documentation is too difficult for me to trace through especially the USB stack.

I am wanting to use the Teensy to send touchscreen controlling info to Windows 10 using HID so don't need to write or install a separate driver.
 
Updated to 1.53 release, still no change. Touchscreen emulation is still non-functional.

Guess I will give up trying with the Teensy platform :(
 
@sinsid does the Teensy 3.6 get properly recognised as a touchscreen by Windows 10 as the Pen & Touch and Tablet PC Settings do NOT become available in Control Panel\Hardware and Sound. So when you select the screen associated with the touch input it then is visible on that screen when doing the touch emulation?
 
Same goes for Teensy 4.1 Touch emulation not working on Windows 10, it works fine on android thou, on Ubuntu 20 only single touch example seems to work:confused:
 
Does anyone know if the status of the touchscreen emulation issue for the Teensy 4 hardware has been changed recently? We all know, there isn't any Teensy 3 hardware available anymore to use them as a workaround.
 
I've committed a fix on github. Teensy 4.x with Tools > USB Type set to Keyboard + Touch Screen should now work with Windows. I tested with Windows 10 (22H2). Hopefully will also work with other Windows versions?

https://github.com/PaulStoffregen/cores/commit/1ffeed641f386a8c139767550aa920b5f63c2a3f

A copy of usb.c with this fix is attached to this message. If you want to get this update (before the next beta or 1.59 release), find teensy4\usb.c on your PC and replace it with this file. If using Arduino IDE 2.1.0, on Windows should be in {LocalData}\Arduino15\packages\teensy\hardware\avr\0.59.2\cores\teensy4. If using Arduino IDE 1.8.19, look in C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy4.
 

Attachments

  • usb.c
    33.6 KB · Views: 28
Back
Top