Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 9 of 9

Thread: Teensy 4 and TouchScreenUSB

  1. #1
    Junior Member
    Join Date
    Feb 2020
    Posts
    8

    Teensy 4 and TouchScreenUSB

    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;
    }

  2. #2
    Senior Member
    Join Date
    Nov 2017
    Location
    Belgium
    Posts
    215
    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

  3. #3
    Junior Member
    Join Date
    Feb 2020
    Posts
    8
    I now tried it also with the latest TD 1.51 release, and still experience the same issue.

  4. #4
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    10,933
    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.

  5. #5
    Junior Member
    Join Date
    Feb 2020
    Posts
    8
    How do we make sure it is on his list? Is this forum post sufficient?

  6. #6
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    10,933
    Generally yes, and as done posting it on the change request post for TD 1.52 gets it on the list.

  7. #7
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,473
    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/co...421fac0ac0b20b

    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;
    }

  8. #8
    Junior Member
    Join Date
    Feb 2020
    Posts
    8
    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...ort-descriptor

    Thanks!!

  9. #9
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,473
    I've merged your pull request. Thanks!

    Also ported it to Teensy 4.

    https://github.com/PaulStoffregen/co...06a38bd29f428d

    But I don't have any tests or examples for these gestures.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •