Forum Rule: Always post complete source code & details to reproduce any issue!
Page 1 of 2 1 2 LastLast
Results 1 to 25 of 34

Thread: 2.8 in ili9341_touch display code differences vs ili9341_t3 library

  1. #1

    2.8 in ili9341_touch display code differences vs ili9341_t3 library

    Just wondering if anyone has modified the Audio Workshop Tutorial Part 3-3:"Add a TFT Display" code to work with a 2.8 IN ILI9341_TOUCH display (sold by PJRC) use the touch screen functions. It seems the present code is just for the non-touch ILI9341_t3 display version. The following web link is not too clear about if there is specific libraries that use the extra five pins called T_CLK, T_CS, T_DIN, T_DG and T_IRQ (normally not used). I presume that without connecting these five pins, the touch functions do not work. Has anyone used this 14-pin display? If so, can you point me to the library that supports it? Much thanks!

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,698
    I have done the Audio tutorial with the PJRC board, the breadboard doesn't offer room for the touch pins as configured so I have not yet used that.

    There is a touch library in the TeensyDuino install : XPT2046_Touchscreen. It is linked from the PJRC store and should work - though with a unique pin for the touch IRQ as #2 is used for the one button. If you search the forum I've left a thread and links to some github work I did on the XPT2046_Touchscreen, very cool device. The SPI pins will need to be adjusted for touch to map to those used by the ILI9341 and you'll need to arrange a unique pin for the Touch CS, but it should work. Note: external search like BING is sometimes/often the best way to find stuff in forum threads. Post back with your findings - that should get you started.

  3. #3
    In the XPT2046_Touch_Example code on GitHub list the following pin definitions:

    #include <XPT2046_Touchscreen.h>
    #include <SPI.h>
    #include <Wire.h>
    #include <ILI9341_t3.h>

    // SPI COMMON assumed :: MOSI=11, MISO=12, SCK=13
    #define CS_PIN 8
    XPT2046_Touchscreen ts(CS_PIN);
    #define TFT_CS 10
    #define TFT_DC 9
    ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC);

    However, the Part_3_03_TFT_Display that is part of the audio project files lists and does not use touch functions lists the following connections:

    #define TFT_DC 20
    #define TFT_CS 21
    #define TFT_RST 255 // 255 = unused, connect to 3.3V
    #define TFT_MOSI 7
    #define TFT_SCLK 14
    #define TFT_MISO 12
    ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCLK, TFT_MISO);ILI931_t3

    If I redefine the SPI pins to the XPT2046_Touch_Example will there be any pin compatibilty issues between the two library used (i.e. XPT2046 vs. ILI9341_t3)? For example: CS_PIN 8 and TFT_CS 10 in the XPT2046 vs. TFT_CS 21 in the ILI9241_t3. Not sure if the libraries are expecting a specific pin number or if this is all dependant on the way you interconnect the Teensy and XPT2046 based on top level .ino configuration. Thanks much!

  4. #4
    Hi Defrayster, I have referenced a long thread back in 2016 started by Duncabar inwhich he posted the same problem of not being able to play audio SD along with TFT 2.8 Touchscreen ili9241_t3 lib (see https://forum.pjrc.com/threads/34424...h-Touch-Screen). Not sure if that is the same as the XPT2046 issue I am having, but maybe so. Anyway, several things were stated in the thread concerning the SPI mapping/connections and that is one thing I am still confussed about. In the original Tutorial Part 3-3: the TFT Display uses the MOSI=7, MISO=12 and SCLK=14. However, Duncabar change his usage of the Audio Board to the Wiz820 and used the normal MISO=12, MOSI=11 and SCK=13. So if I stay with Paul's original code using the audio board and ili9241/xpt2046 combination, do I stay with the original pin mapping?

    Secondly, the partial code below starts to execute but gets stuck in the SD card while loop at the end. Do you see any reason for this? Is there a issue with the order in which the SD card is executed relative to the pin and labruary declarations? This code works with the exclusion of the XPT2036 references.

    // Advanced Microcontroller-based Audio Workshop
    // Commented out guitar code per defragster form post suggestion
    // Part 3-1: Fourier Transform
    //Last Change Date: 1/5/2016 Time: 14:13

    #include <Bounce.h>
    //#include "AudioSampleGuitar.h"
    Bounce button0 = Bounce(0, 15);
    Bounce button1 = Bounce(1, 15); // 15 = 15 ms debounce time
    Bounce button2 = Bounce(3, 15);
    //int ledPins[] = {6}; //Set LED for transmission indicator

    ///////////////////////////////////
    // copy the Design Tool code here
    ///////////////////////////////////
    #include <XPT2046_Touchscreen.h> //New
    #include <ILI9341_t3.h>
    #include <font_Arial.h> // from ILI9341_t3
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>

    // GUItool: begin automatically generated code
    AudioSynthWaveform waveform1; //xy=254,251
    AudioPlaySdWav playSdWav1; //xy=257,155
    AudioMixer4 mixer1; //xy=454,195
    AudioOutputI2S i2s1; //xy=622,168
    AudioAnalyzeFFT1024 fft1024_1; //xy=629,211
    AudioConnection patchCord1(waveform1, 0, mixer1, 3); //Sine wave actuated by button 3
    AudioConnection patchCord2(waveform1, 0, mixer1, 2); //Sine wave actuated by button 2 (random)
    AudioConnection patchCord3(playSdWav1, 0, mixer1, 0); //SD card sterio input
    AudioConnection patchCord4(playSdWav1, 1, mixer1, 1); //SD card sterio input
    AudioConnection patchCord5(mixer1, 0, i2s1, 0);
    AudioConnection patchCord6(mixer1, 0, i2s1, 1);
    AudioConnection patchCord7(mixer1, fft1024_1);
    AudioControlSGTL5000 sgtl5000_1; //xy=466,287
    // GUItool: end automatically generated code

    char freq[2]; //Create frequency bin #
    char avalue[2]; //Create audio FP string array
    int freqamp; //Create int variable for freq float
    const int audioprc = 6; //Create processed output pin
    int audval[32]; //Initialize audio int value array
    int ch1audval = 0;
    int ch2audval = 0;
    int ch3audval = 0;
    int ch4audval = 0;
    int ch5audval = 0;
    int ch6audval = 0;
    int ch7audval = 0;
    int ch8audval = 0;
    int rcvflag = 0; //Set receive flag pin
    int audioflag = 0; //Create audio received flag

    // SPI COMMON assumed :: MOSI=11, MISO=12, SCK=13
    //#define TFT_CS 10
    //#define TFT_DC 9
    #define TFT_DC 20
    #define TFT_CS 21
    #define TFT_RST 255 // 255 = unused, connect to 3.3V
    #define TFT_MOSI 7
    #define TFT_SCLK 14
    #define TFT_MISO 12
    ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCLK, TFT_MISO);
    // set this to the hardware serial port you wish to use
    #define SIZE 10 //Was 10
    elapsedMillis msecs;
    int height = 20; //Set mode button height
    int Audmode = 0;
    int Seqmode = 0;
    int Ranmode = 0;
    int Cnvmode = 0;
    int Hltmode = 0;
    int Spmode = 0;
    //const int audioprc = 3; //Create processed output pin

    #define CS_PIN 8
    #define TIRQ_PIN 2
    //XPT2046_Touchscreen ts(CS_PIN); // Param 2 - NULL - No interrupts
    //XPT2046_Touchscreen ts(CS_PIN, 255); // Param 2 - 255 - No interrupts
    XPT2046_Touchscreen ts(CS_PIN, TIRQ_PIN); // Param 2 - Touch IRQ Pin - interrupt enabled polling

    void setup() {
    Serial.begin(9600); //SERIAL USB buad rate
    while ( !Serial && (millis() < 3000));
    pinMode(audioprc, OUTPUT); //Transmit flag
    // delay(500);
    ts.begin(); //Added for touch display
    tft.begin();
    tft.fillScreen(ILI9341_BLACK);
    tft.setTextColor(ILI9341_YELLOW);
    tft.setFont(Arial_10);
    tft.setTextSize(3);
    tft.setCursor(40, 8);
    tft.println("LIGHTING CONTROL");
    AudioMemory(10);
    sgtl5000_1.enable();
    sgtl5000_1.volume(0.5);
    SPI.setMOSI(7);
    SPI.setSCK(14);
    if (!(SD.begin(10))) {
    while (1) {
    Serial.println("Unable to access the SD card");
    delay(500);
    }
    }

  5. #5
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,698
    This posts shows the Audio card + TFT + (tft)SD working if I read right - when using the non_T3 adafruit version of the ILI9341 library. The earlier code was using the SD physically on the display before I got the audio tutorial hardware. Based on the posts where my stuff worked when others didn't - they had to use explicit pin declares in setup.

    But this following post I claim to have played SD audio with the ILI9341 that was with #include <ILI9341_t3.h> code. That was using the Audio Tutorial base code extended for the TFT - set up on the breadboard solution from PJRC audio T_3.2 pre-assembled kit where I added display - I did it with both ILI9341 and smaller ILI9163C at that time. I'm not sure what the sketch I attached shows - a quick scan of the INO shows it doing this in setup():: playSdWav1.play("SDTEST1.WAV"); That sketch doesn't use Touch - but should work with IRQ on a usable pin ( audio hardware has a button on pin2 - I see that moved to #3 in sketch above)

    If there is a conflict I didn't hit it as I used it - check wiring against that shown here store/audio_tutorial_kit.html and in the PDF and code for the indicated sketch perhaps?

    With the Audio adapter active pin 13 is owned by Audio Adapter for I2S IIRC and that is why SCK must be moved to pin 14.

    Are you using a T_3.2? If you try my posted sketch and have trouble I can get back to that as the Audio tutorial board is still here.

  6. #6

    XPT2046/ILI92341 with Audio SD Card

    I am using the Teensy 3.2, but not the pre-assemblied kit. I double checked the pin connections to the XPT2046/ILI9341 display including explicitly declaring it in the Setup loop (i.e. #define SC_PIN 8 and #define TIRQ_PIN 2 (in case that made a difference). I also checked for the playSdWav1.play("SDTEST1.WAV"); in setup and it is there (not shown in the partial code above). What I don't understand is why the above code gets stuck in the last part of the Setup loop in accessing the SD card just because the #include <XPT2046_touchscreen.h> was added:

    if (!(SD.begin(10))) {
    while (1) {
    Serial.println("Unable to access the SD card");
    delay(500);
    }
    }

    Is there any chance that adding the interrupt line for the XPT2046 is effecting the initialization of the SD card? As I said before, this does not happen if the #include <XPT2046_touchscreen.h> is not used. Has anyone actually used the touch display function with interrupts and the SD card as opposed to just the ILI9341? I supposed I could try to use polling instead, but it's not really what I need. The code I am using for the touch function is from the TouchTest example posted on either Github or the forum.pjrc (can't remember which one).

  7. #7
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,698
    I used the 2.4" non-touch so I didn't use the TIRQ_PIN when I was using audio board SD, but I got the idea from the linked posts that others did.

    With audio tutorial breadboard spaced for non-touch would have to wire differently to use that board for the touch display - would use pin#3 for TIRQ_PIN and have to fit the other added SPI touch pins . . .

  8. #8

    XPT2046 Interrupts

    I tried switching the TIRQ pin from 2 to 3 as you suggested, but it didn't make any difference as far as the SD initialization being stuck in the setup routine. If I comment out all the XPT2046 library calls and code references for touch reading from the TouchTest example (see code below), the ILI9341 display part works fine, the SD card gets initialized and the music plays (Paul's FFT Peak Meter sketch). One thing I noticed is that the XPT2046 IRQ pin is contantly pulsing low when music is being played. I thought that was just when the touch screen was being pressed or reading the touch location. It appears like this pin is activiate even when writing to the ILI9341 display. That doesn't make much sense. This even happens during setup when the XPT2046_Touchscreen.h library is included and SD card is being initialized. I am wondering if this IRQ is interferring with the SD setup timing wise even though they are not using the same bus (i.e. SPI vs. I2C). Maybe I should try just polling the touch function instead of using the IRQ. Any suggestion on code for polling XPT2046?

    #include <XPT2046_Touchscreen.h>
    #include <SPI.h>

    #define CS_PIN 8
    // MOSI=11, MISO=12, SCK=13

    //XPT2046_Touchscreen ts(CS_PIN);
    #define TIRQ_PIN 2 //Change to pin 3 as you suggested
    //XPT2046_Touchscreen ts(CS_PIN); // Param 2 - NULL - No interrupts
    //XPT2046_Touchscreen ts(CS_PIN, 255); // Param 2 - 255 - No interrupts
    XPT2046_Touchscreen ts(CS_PIN, TIRQ_PIN); // Param 2 - Touch IRQ Pin - interrupt enabled polling

    void setup() {
    Serial.begin(38400);
    ts.begin();
    while (!Serial && (millis() <= 1000));
    }

    void loopB() {
    TS_Point p = ts.getPoint();
    Serial.print("Pressure = ");
    Serial.print(p.z);
    if (ts.touched()) {
    Serial.print(", x = ");
    Serial.print(p.x);
    Serial.print(", y = ");
    Serial.print(p.y);
    }
    void loop() {
    if (ts.touched()) {
    TS_Point p = ts.getPoint();
    Serial.print("Pressure = ");
    Serial.print(p.z);
    Serial.print(", x = ");
    Serial.print(p.x);
    Serial.print(", y = ");
    Serial.print(p.y);
    delay(30);
    Serial.println();
    }
    }

  9. #9
    Defragster,

    I finally found the problem with the SD Card and XPT2046 touch. In setup, before the SD Card is initialized, you cannot write anything to the display. Otherwise, the interrupts producted by the XPT2046 will prevent the SD Card from completing the initialization. All write to the display most be after the following code.

    if (!(SD.begin(10))) {
    while (1) {
    Serial.println("Unable to access the SD card");
    delay(500);
    }

  10. #10
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    Do you have pullups attached to the display chipselect lines ?

  11. #11
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,698
    jshooks - that was a note to myself - needing to move T_IRQ if I tried that as the pre-made Audio board has the buttons on 0,1,2.

    Are all CS pins using pullups (touch, sd, display, ...) as Frank notes? if they aren't held high - they won't stay inactive while other devices are being addressed. With CS held high the devices should be inactive unless the software pulls it down. Not having that could explain odd behavior.

  12. #12
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,421
    Note: I have not seen any issues with the display CS/DC pins with the ILI9341 and I have never used PU resistors on these. And I don't think it is shown in the hook up guide: https://www.pjrc.com/store/display_ili9341_touch.html

    The ILI9341_t3 library sets these pins to mode(2) which I believe will hold the high level except when asserted... But if there is an issue at initialization order. At the beginning of your setup code you could simply set these pins to output and set the value high... Then when the display init is called it will take it over...

    So far I have not tried using the interrupts with the touch controller. I simply use the polling functions. Example of which with my ILI9341_t3n version of the library I have a Touch paint program that was converted to use this touch controller. https://github.com/KurtE/ILI9341_t3n...nt_xpt2046.ino

    Maybe at some point I will try using the interrupts to see what happens... But then again I am using these displays on a board with a T3.6, so normally use the built-in sd card

  13. #13
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,698
    When Paul updated OSHPark display Purple test board to Touch: 10K pull-ups were part of that design, I never tried touch without them on any I set up.

  14. #14
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,421
    Thanks defragster. Note to Paul. If there are cases where they are needed, maybe good to add to notes on Product page.

    Thanks again.

  15. #15
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    In general, they are a good idea for every SPI-Slave.
    They prevent floating chipselects _before_ initialization of the libraries, even _before_ setup() is run.
    On Teensy and many other devices, this is a "long" time (>400ms, because of a delay(400) for USB).
    They prevent that the slave interpret signals on the clock-lines as real clocks. The outputs on the master (aka Teensy) are floating too, or, maybe, the teensy initializes an other SPI device, incl. CS, first ( => wrong commands?)

    It depends on the individual circumstances if the pullups are really needed, and they make sense for the startup only - but adding them makes your board more reliable.

    I really don't know if missing pullups are the reason for jshooks's xpt-problems, but, as said, they are a good idea.
    Last edited by Frank B; 01-31-2017 at 04:53 PM.

  16. #16
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    @Paul and all: Perhaps it would be better to initialize CS-Pins in every lib that uses SPI earlier - in the constructor - not in begin(), which is a bit late.

  17. #17
    Member
    Join Date
    Sep 2016
    Location
    NYC, USA
    Posts
    44
    I got the touch working on a t3.6 with audio board. I found that the order of calling begin mattered. If I called ts.begin() before tft.begin() (for reasons I don't understand) no audio would be output, though the tft and touch appeared to be working.
    The following code works for me. It's the audio tft tutorial slightly modified so that a touch on the screen causes it to randomly choose and then play a different file:
    Code:
    /*************************************************************************************************************
    * Advanced Microcontroller-based Audio Workshop
    * Part 3-3: Add a TFT Display
    * https://github.com/PaulStoffregen/AudioWorkshop2015/raw/master/workshop.pdf
    * https://hackaday.io/project/8292-microcontroller-audio-workshop-had-supercon-2015
    *************************************************************************************************************/
    
    #include <ILI9341_t3.h>
    #include <XPT2046_Touchscreen.h>
    #include <font_Arial.h>  // from ILI9341_t3
    #define TFT_DC      20
    #define TFT_CS      21
    #define TFT_RST    255                // 255 = unused, connect to 3.3V
    #define TFT_MOSI     7
    #define TFT_SCLK    14
    #define TFT_MISO    12
    #define BACKLIGHT 5
    #define TS_CS 8                       // Touchscreen CS
    #define TS_TIRQ 39                    // IRQ instead of polling...?
    XPT2046_Touchscreen ts = XPT2046_Touchscreen(TS_CS, TS_TIRQ);
    ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCLK, TFT_MISO);
    elapsedMillis sampleTime;
    
    //------------------------------------------- GUItool output ------------------------------------------------+
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    Sd2Card card;
    SdVolume volume;
    SdFile root;
    AudioPlaySdWav           playSdWav1;
    AudioAnalyzePeak         peak2;
    AudioAnalyzePeak         peak1;
    AudioOutputI2S           i2s1;
    AudioConnection          patchCord1(playSdWav1, 0, i2s1, 0);
    AudioConnection          patchCord2(playSdWav1, 0, peak1, 0);
    AudioConnection          patchCord3(playSdWav1, 1, i2s1, 1);
    AudioConnection          patchCord4(playSdWav1, 1, peak2, 0);
    AudioControlSGTL5000     sgtl5000_1;
    
    //=========================================== setup ====================================================+
    void setup() {
      randomSeed(analogRead(A10));
      Serial.begin(230400);
      while (!Serial && (millis() < 2000));
      pinMode(BACKLIGHT, OUTPUT);
      digitalWrite(BACKLIGHT, HIGH);
      tft.begin();
      ts.begin();
      tft.fillScreen(ILI9341_BLACK);
      tft.setTextColor(ILI9341_RED);
      tft.setFont(Arial_16);
      tft.setRotation(2);
      tft.setCursor(63, 10);
      tft.println("Peak Meter");
      AudioMemory(12);
      sgtl5000_1.enable();
      sgtl5000_1.volume(0.3);
      SPI.setMOSI(7);
      SPI.setSCK(14);
      if (!(SD.begin(BUILTIN_SDCARD))) {
        while (1) {
          Serial.println("Unable to access the SD card");
          delay(500);
        }
      }
      delay(500);
    }
    
    //=========================================== loop =====================================================+
    void loop() {
      const int8_t quantFiles = 4;
      static int8_t wavToPlay = chooseFile(quantFiles);
      boolean wasTouched = false;
      if (ts.touched()) {
        delay(75);            // Debounce
        wasTouched = true;
        wavToPlay = chooseFile(quantFiles);
      }
      if (playSdWav1.isPlaying() && wasTouched) { 
        playSdWav1.stop();
        wasTouched = false;
      }
      else if (playSdWav1.isPlaying() == false) {
        if (wasTouched) wasTouched = false;
        switch(wavToPlay) {
          case 0:
            playSdWav1.play("SDTEST1.WAV"); break;
          case 1:
            playSdWav1.play("SDTEST2.WAV"); break;
          case 2:
            playSdWav1.play("SDTEST3.WAV"); break;
          case 3:
            playSdWav1.play("SDTEST4.WAV"); break;
        }
        delay(10);            // Wait for library to parse WAV info
      }
      if (sampleTime > 20) {
        if (peak1.available() && peak2.available()) {
          sampleTime = 0;
          float leftPeak = peak1.read();
          float rightPeak = peak2.read();
          int height = leftPeak * 240;                          // Draw the vertical bars
          tft.fillRect(60, 284 - height, 40, height, ILI9341_GREEN);
          tft.fillRect(60, 284 - 240, 40, 240 - height, ILI9341_BLACK);
          height = rightPeak * 240;
          tft.fillRect(140, 284 - height, 40, height, ILI9341_GREEN);
          tft.fillRect(140, 284 - 240, 40, 240 - height, ILI9341_BLACK);  // ("Would be smarter to redraw only changed portion")
          tft.setFont(Arial_14);                                // Draw numbers underneath each bar
          tft.setTextColor(ILI9341_BLACK);
          tft.fillRect(60, 284, 40, 16, ILI9341_GREEN);
          tft.setCursor(60, 284);
          tft.print(leftPeak);
          tft.fillRect(140, 284, 40, 16, ILI9341_GREEN);
          tft.setCursor(140, 284);
          tft.print(rightPeak);
        }
      }
    }
    //------------------------------------------- chooseFile ----------------------------------------------------+
    int8_t chooseFile(int8_t quantFiles) {
      static int8_t lastFile = random(quantFiles);
      int8_t choice = random(quantFiles);
      if (choice == lastFile) chooseFile(quantFiles);
      else {
        lastFile = choice;
        return choice;
      }
    }
    best,
    Michael

    edit: Works without adding pullup resistors

  18. #18
    Michael,

    Wow, I must have moved the ts.begin in my setup and the audio music stop playing. Moved it back after tft.begin and it works! It must be that touch should only be initialized after ILI9341 and SD card are started. I guess to find out why, you would have to use a logic analyzer to trace code execution.

  19. #19
    Member
    Join Date
    Sep 2016
    Location
    NYC, USA
    Posts
    44
    For me, as you can see in my code, initializing both tft and touch before the SD worked fine. (I did set the alternate SPI data and clock lines before the SD.begin.) Note that my posted example uses the SD slot on the T3.6 (SD.begin(BUILTIN_SDCARD)), but I also tried it successfully using the audio board's slot (SD.begin(10)).

    --Michael

    edit: I did get hung up quite a while before I noticed the superfluous SD library in my sketchbook lib folder and deleted it.
    Last edited by Michael Ward; 01-31-2017 at 09:23 PM.

  20. #20
    When you say "alternate SPI data and clock lines" you talking about the following, right?

    #define TFT_MOSI 7
    #define TFT_SCLK 14
    #define TFT_MISO 12

    That is what I have always used. Of course, on the XPT2046 you have to jumper these over to the extra touch pins on the display. I am displaying five buttons and am having a little trouble with the display touch resolution X,Y position being constant values. I probably need to make the buttons a little bigger for touch point range correlation (i.e. have to use a stylist to make it work). Do you find your delay(75) enough time for the debouncing of the touch?

  21. #21
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,698
    Quote Originally Posted by jshooks View Post
    When you say "alternate SPI data and clock lines" you talking about the following, right?

    #define TFT_MOSI 7
    #define TFT_SCLK 14
    #define TFT_MISO 12

    That is what I have always used. Of course, on the XPT2046 you have to jumper these over to the extra touch pins on the display. I am displaying five buttons and am having a little trouble with the display touch resolution X,Y position being constant values. I probably need to make the buttons a little bigger for touch point range correlation (i.e. have to use a stylist to make it work). Do you find your delay(75) enough time for the debouncing of the touch?
    The alternate pins noted are set with these lines as I see it:
    SPI.setMOSI(7);
    SPI.setSCK(14);
    if (!(SD.begin(BUILTIN_SDCARD))) {
    How does the TouchPaint demo work with drawing a line and touching the color buttons? The raw touch values X&Y needs to be mapped to TFT display pixels - AFAIK that sketch should work unless the touch hardware has changed. I posted some samples of buttons in use on the XPT2046 and had a map function for any orientation wasn't included when I had IRQ code PULL'ed in - Though KurtE did something similar recently

  22. #22
    Member
    Join Date
    Sep 2016
    Location
    NYC, USA
    Posts
    44
    Yes, what defragster said about alternate lines. The "non-alternates" are the default pins that are the same for Arduino Uno etc.
    As for my debounce delay--that's not an ideal way to do it. It's just good enough for my simple application, where a brief hiccup is not noticeable between file switches.
    --Michael

    edit: I played a little with the touchpoint demo and it worked. I recommend checking out defragster's examples re mapping.
    Last edited by Michael Ward; 02-01-2017 at 02:11 PM.

  23. #23
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,421
    Quote Originally Posted by defragster View Post
    The alternate pins noted are set with these lines as I see it:


    How does the TouchPaint demo work with drawing a line and touching the color buttons? The raw touch values X&Y needs to be mapped to TFT display pixels - AFAIK that sketch should work unless the touch hardware has changed. I posted some samples of buttons in use on the XPT2046 and had a map function for any orientation wasn't included when I had IRQ code PULL'ed in - Though KurtE did something similar recently
    Yep - I have it in my Example program touchpaint for the XPT... It is up at: https://github.com/KurtE/ILI9341_t3n...nt_xpt2046.ino

    It might be good to standardize on what are the valid ranges for the touch and come up with a set of mapping functions that works correctly for several of the displays...

    Yesterday I tried turning on the interrupt code of the touch driver and it appeared to work ok on my board which has it going to pin 3.

    It is also interesting that I am not sure what all triggers the IO line, but I know that if I simply add something like:
    pinMode(3, INPUT);
    You will see lots of transisitions going on when/if your code calls functions like:
    TS_Point p = ts.getPoint();

    But it appeared to work fine where you do not get a transition on that pin when the interrupt code is configured (unless again you call the functions like ts.getPoint();

    But with it on in the Touch paint code, the call I make at the start of the function:
    Code:
      // See if there's any  touch data for us
      if (ts.bufferEmpty()) {
        return;
      }
    the return will be taken and nothing happens on the IO pin until you touch the screen. At which point again you will see lots of transitions on the IO pin until you are no longer touching the display and stop calling ts.getpoint...

  24. #24
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,698
    Of course it works If you read Paul's Caveat ( if still posted ) - testing interrupt is great for trouble - the int fires on each touch call made during touch. My solution is just an enable flag set on int - and removed after touch goes away - ended up at like 20 lines of code with header stuff. So you can attempt to poll all day long and will be quickly ignored saving SPI traffic - unless there was a prior int.

  25. #25
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,698
    As far as debounce - I had something I found to be effective in my linked sample. There was no delay - but it only takes a button touch if two samples are seen as the same (pixel and time) within 3 pixels as coded. And falling out of that I detected what was needed for a slider button not just a toggle. That code got to functional in my sample - but not pretty as I got pulled off to other things.

    Follow up to my quick post #24 above - is there a benefit to detaching the interrupt after it was detected and then re-attachinterrupt when the touch is detected to have stopped? I assumed that would add as much overhead as letting this code just get hit on each command issued during touch - but never tested it { ...\hardware\teensy\avr\libraries\XPT2046_Touchscr een\XPT2046_Touchscreen.cpp }:
    Code:
    void isrPin( void )
    {
    	XPT2046_Touchscreen *o = isrPinptr;
    	o->isrWake = true;
    }
    It would be easy to detach there when setting true, and then do the attach here when set false and should be otherwise unaffected:
    Code:
    		if (z < Z_THRESHOLD_INT) { //	if ( !touched ) {
    			if (255 != tirqPin) isrWake = false;
    		}

Posting Permissions

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