Arduino XPT2046 Touchscreen Calibration and Coding - ILI9341 LCD with XPT2046 Touch screen

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 ธ.ค. 2020
  • A touchscreen makes a great user interface for your Arduino projects. The LCD panel lets you create dials, and instruments that you can then control using buttons, sliders and anything else you want to code.
    In this tutorial I'll show you how to write a simple calibration function so you can quickly map your touchscreen data to the screen coordinates and then show you how to monitor for touch events and create a simple user interface button.
    You can easily get hold of one of these touchscreens at Amazon or eBay.
    Amazon: amzn.to/39ZyWMD
    eBay : ebay.us/sOCSyI
    Make sure you have a look at my setup and animation tutorials to get your panel up and running.
    Setup
    • Connect an SPI TFT wit...
    Animation
    • Basic animation in you...
    All the code for this tutorial is available on the project page in my website.
    bytesnbits.co.uk/arduino-touc...

ความคิดเห็น • 70

  • @danielewusi-essel219
    @danielewusi-essel219 3 ปีที่แล้ว +2

    This is amazing. It completely breaks down the calibration of a TFT display. After this, I don't need to watch another video on calibrating TFT's.
    I'm subscribing too!

    • @BytesNBits
      @BytesNBits  3 ปีที่แล้ว

      Hi Daniel. Thanks for the comments and I'm glad you found it useful. Thanks for the sub!

  • @jumbo999614
    @jumbo999614 2 ปีที่แล้ว +1

    Finally found a video that explained the code. Thank you for putting this video on youtube.
    Do you have more video? I want to learn to use TFT function to draw graphics.

    • @BytesNBits
      @BytesNBits  2 ปีที่แล้ว +1

      Hi. I've got a short series on using the LCD screen from simple graphics up to coding a game. Have a look at the Arduino playlist
      th-cam.com/video/qNgTjCcv9vM/w-d-xo.html

  • @coby1kenobii
    @coby1kenobii 3 ปีที่แล้ว +1

    love the animations!

  • @funky7823
    @funky7823 3 ปีที่แล้ว

    Thank you for a great series of videos. You've put a lot of work into them, and I appreciate that greatly. I have been trying to get my display to work for several days, came across your videos, and had it working in 30 minutes. Could I perhaps suggest that you put the words XPT2046 and ILI9341 in the title of the videos, I was searching for a long time before finding them! Thanks again.

    • @BytesNBits
      @BytesNBits  3 ปีที่แล้ว

      Hi Gavin. Great to hear it helped. Good idea on the title changes.

  • @viktorhugo8252
    @viktorhugo8252 ปีที่แล้ว

    Very good explained touch calibration. The const have to put in eeprom variables after first calibration.

    • @BytesNBits
      @BytesNBits  ปีที่แล้ว

      Yes. That will save you having to recalibrate each time you start up. Or just hard code them into your project after you've got the values.

  • @pw3111
    @pw3111 2 ปีที่แล้ว +1

    loving these videos - thanks.
    I have a problem compiling this example as it says "lt, gt etc not defined. Can you help please.
    Problem fixed. I just read Hal's post further down.

    • @BytesNBits
      @BytesNBits  2 ปีที่แล้ว

      Hi. The web code viewer is not working very well on this page. It's translated the < and > symbols into their html codes. lt should be .

  • @PeetHobby
    @PeetHobby ปีที่แล้ว

    I have always relied on a single point to determine the screen offset in my code. This one point provides enough information to obtain both the X and Y offsets.

    • @BytesNBits
      @BytesNBits  ปีที่แล้ว

      A single point will give you a reasonable result but doesn't allow you to explicitly measure the offsets and scaling factors. On these small screen sizes any errors you introduce will probably be hard to notice.

  • @gnather
    @gnather ปีที่แล้ว +2

    I am sure that someone has informed you that the code on your webpage won't run. The fault is that when it was copied over the , and && coded as lg; , gt; and & respectively.
    Weird 😁, It had me stumped for an hour then it dawned on to compare the code in the video to the one on your webpage. Runs great now. Good explanations ,good video series....Thanks!!!

    • @BytesNBits
      @BytesNBits  ปีที่แล้ว

      Hi. Thanks for the bug report. The Wordpress editor has issues with the code dumps. The newer videos are sorted out. I'll have to go back and fix this one.

    • @semirdzhyan
      @semirdzhyan 10 หลายเดือนก่อน

      @@BytesNBits I second this. Just came across your website and I tried using the calibration code posted there by copying/pasting it. Got the same errors mentioned by @gnather. I'm now going over your video to see where it differs from the posted code and hopefully get the calibration up and running.

  • @rompipelotas
    @rompipelotas ปีที่แล้ว

    THANKS A LOT !!!!!!

  • @paulunsinn6670
    @paulunsinn6670 6 หลายเดือนก่อน

    THX

    • @BytesNBits
      @BytesNBits  6 หลายเดือนก่อน

      No problem

  • @bhagyashrirajput3357
    @bhagyashrirajput3357 3 ปีที่แล้ว

    Can u plz tell me how to add this TFT display in Proteus for simulation purpose ?? Can u plz give it exact library link where I can download it

    • @BytesNBits
      @BytesNBits  3 ปีที่แล้ว

      Hi. I don't use Proteus so I don't know if there is a package. Good luck in finding one :)

  • @mevmevmev
    @mevmevmev ปีที่แล้ว

    Very well explained and easy to follow.
    My touchscreen draws both red targets before even touching the screen.
    Somehow it thinks it was touched after the first target and goes past the line "while(!ts.touched());"
    Then it waits at the 2nd target and that one seems to work, but the first one not working invalidates the calibration.
    confirmed this with some Serial.print debug text.
    Using "TouchTest.ino" the Pressure reading is 321 when not touched and around 2000 when touched.

    • @BytesNBits
      @BytesNBits  ปีที่แล้ว

      I'd try putting a delay in the startup code before it tries to see the first touch. It might be getting a false positive as it starts.

    • @larrybud
      @larrybud 6 หลายเดือนก่อน

      Ever get this working? I'm trying to get this touchscreen working with a pico and all I get are false positives. Bought a 2nd display thinking it might be hardware but it does the same thing. I had no problem getting the display portion working.

    • @mevmevmev
      @mevmevmev 6 หลายเดือนก่อน

      @@larrybud I had to put the project aside. Hoping to get back to it at some point.

  • @halalbach1855
    @halalbach1855 2 ปีที่แล้ว +1

    I copied the "Touchscreen Calibration Code" from your website and discovered via the compiler that at least ten lines had garbled contents. For instance, line 50 reads:
    if(xCoord < 0) xCoord = 0;
    but it should read, according to the code in the video;
    if (xCoord < 0) xCoord = 0;
    It seems that a (less than symbol) "" symbol is supplanted with " > ".
    Also line 128;
    ScreenPoint sp = ScreenPoint();
    differs slightly from that shown in your video presentation where it appears as;
    ScreenPoint sp = ScreenPoint(0, 0);
    After I made the corrections the compiler was happy and the program ran beautifully, just like in the video. Line 128 seems to work just fine with or without the "0,0".
    Your presentation was masterful in explaining how and why touchscreen calibration is done. Thank you very much.
    Just wondering if the garbling was done because of international travel?

    • @BytesNBits
      @BytesNBits  2 ปีที่แล้ว

      Hi. Thanks for spotting that. I'll have a look. The < changing to < looks like an html thing.

    • @johnvine5731
      @johnvine5731 2 ปีที่แล้ว +1

      It might be a browser problem.
      The browser cannot display the 'greater than' and 'less than symbols' .
      So, instead of < and >, the browser displays < and >.
      It happened to me as well.

    • @MHTSAPAS
      @MHTSAPAS ปีที่แล้ว

      @@BytesNBits It's been a year mate. What's the point of a tutorial when it's left with open holes. You need to fix or remove that code.

  • @atihrot755
    @atihrot755 ปีที่แล้ว

    I wish you a good day. I was thinking about your codes. I've tried almost all of the programs from the library. Everything works. Only those codes that you published during the calibration gave me an error at the end of the code. And when I tried the touch screen drawing program, it said chiba somewhere in the middle. Please some advice. Well thank you.

    • @BytesNBits
      @BytesNBits  ปีที่แล้ว

      Hi. The code on the web page has gotten corrupted by the website display. If you replace the < and > codes with < and > it should work. I'll try and update the code listing over the next few days.

  • @user-mg2gb3tl1g
    @user-mg2gb3tl1g 9 หลายเดือนก่อน

    Благодарим ви!

    • @BytesNBits
      @BytesNBits  9 หลายเดือนก่อน

      You're welcome

  • @Jerryg225OnRoblox
    @Jerryg225OnRoblox ปีที่แล้ว

    Im having a hard time understanding where the "20 - " value is coming from. I understand that y=mx+b that is where we cross the x/y axis, but in terms of this example I dont quite understand how you came to the value of 20. Can you please explain?

    • @BytesNBits
      @BytesNBits  ปีที่แล้ว

      Is the 20 for the block size values? That's just so I can easily change the size of the on screen square that is drawn where you touch the screen. It's not part of the calibration code.

    • @ThePrintHouse
      @ThePrintHouse ปีที่แล้ว

      @@BytesNBits xCalC and yCalC has 20- and I don't understand that (it is part of the calibration value). Where do you get the 20 from? Why is that due to the size of the square? I hope that helps you understand my question more, sorry for being confusing at first.

    • @BytesNBits
      @BytesNBits  ปีที่แล้ว +1

      @@ThePrintHouse Hi. I see which bit you mean. The 20 is just that the calibration crosses are drawn 20 pixels in from the edge of the screen. So when we substitute the values into the equation pixelPosition = m(TouchValue) + c we use 20 for the pixelPosition. so c = 20 - m(touchValue).

    • @ThePrintHouse
      @ThePrintHouse ปีที่แล้ว

      @@BytesNBits ok great. That is what I thought, but I just wanted to make sure. I'm modifying the code to use more equations based on variables (so everything can be easily modified) and just needed to make sure I used the right math.

  • @DanialADHOfficial
    @DanialADHOfficial ปีที่แล้ว

    sometimes im not sure why mine.. need to do calibration evertime i reconnect/power on my device

    • @BytesNBits
      @BytesNBits  ปีที่แล้ว

      If you're using my code it's programmed to go through the setup process each time. You'd need to modify the code to save the setup info to a file or something so the values are preserved between boots.

  • @April2023-fb6pf
    @April2023-fb6pf 5 หลายเดือนก่อน

    Can we use for another shield tft?

    • @BytesNBits
      @BytesNBits  5 หลายเดือนก่อน

      Yes. You might need to check the driver chips and modify the code to suit your hardware, but the general process is the same.

    • @April2023-fb6pf
      @April2023-fb6pf 5 หลายเดือนก่อน

      My tft shield with arduino uno get a white screen. Where my problem

  • @atihrot755
    @atihrot755 ปีที่แล้ว

    Dear Mr. Those codes don't work for me at all. I can't run drawing on the LCD. Can you help me?

    • @BytesNBits
      @BytesNBits  ปีที่แล้ว

      Hi. Your best bet is to try each part of the project separately. Make sure you can get the LCD panel working. Then try the basic touch screen functions and then try putting it all together.

  • @user-vz6fq4sn4f
    @user-vz6fq4sn4f 2 ปีที่แล้ว

    Good morning. I have this screen "3.5inch TFT Touch Shield (320x480 Pixel / XPT2046 Touch controller)" and I want to connect it to Arduino uno R3… I want to connect the DHT11 & MQ-3 sensors and control them from the screen but see temperature / humidity / Gas. I tried according to the video but it only shows me a white screen. Please if you can help me. Thanks in advance!

    • @BytesNBits
      @BytesNBits  2 ปีที่แล้ว

      Can you get the screen working by itself without any other devices connected?

    • @user-vz6fq4sn4f
      @user-vz6fq4sn4f 2 ปีที่แล้ว

      @@BytesNBitsThank you very much for the answer. With the demo code I ran the screen works.

    • @BytesNBits
      @BytesNBits  2 ปีที่แล้ว

      Can you get the sensors working without the screen - just use the example sensor sketch. If everything works separately you'll need to look at your sketch that pulls it all together. Use the serial terminal to print debug messages as the code runs so you can see what it's trying to do and if it gets stuck somewhere. Try initialising the screen and displaying something, then pause for a few seconds so you can visually see if it worked before reading the sensors. It's probably something you've missed out on the code to get it all set up correctly.

    • @user-vz6fq4sn4f
      @user-vz6fq4sn4f 2 ปีที่แล้ว

      Good Evening . I have a problem with the initialization of this screen, the sensors work without the screen. The problem is that it is not the same, my screen, with yours and I do not know what to initialize and how to use it. Do I have to initialize all the pins?

    • @BytesNBits
      @BytesNBits  2 ปีที่แล้ว

      Hi. You're almost there! The screen works and the sensors work. The screen has a chip select pin that tells it to listen to the SPI channel. This needs to be initialised as an output and set to off (high) as soon as you power up the project. If you're using the touchscreen make sure you do the same for it's chip select pin. This stops the LCD receiving random signals that might upset it. You can then initialise your sensors and then the screen.
      If it doesn't work try initialising the screen but hold off doing anything with the sensors for a few seconds to see if the screen gets up and running before you access the sensors. If it then goes blank when you use the sensors you'll know there's something in the sensor code that's knocking out the screen.

  • @vivekrohella9400
    @vivekrohella9400 2 ปีที่แล้ว

    Thanks for the video on ILI9341 with XPT2046 touch screen. I am making a project with following details
    Arduino DUE
    TFT CS 52
    TFT DC 3
    TFT RST -1
    TFTbrightness DAC0
    T CS 36
    T IRQ 34
    MISO 62
    MOSI 63
    SCK 64
    I am also using SD card module. It's MISO, MOSI & SCK connection are connected to 62,63 & 64 respectively.
    Due to project limitations, I cannot change pin number. Everything things is working except Touch.
    I am using ILI9341_due_config.h, ILI9341_due.h, XPT2046_Touchscreen.h.
    Pls. help me to enable touch of the display.

    • @BytesNBits
      @BytesNBits  2 ปีที่แล้ว

      Hi. Have you tried running a sketch that just uses the touch function without even loading in the LCD driver? This should verify if the touch setup is working. Once you've verified that it's all OK you'll know that it's some sort of issue combining the software.
      I found that you need to get all the chip select signals and Reset on the LCD set up first before you try to initialise the SPI parts. There seems to be some crossover if you don't.
      Also check that the touch panel can run at the SPI baud rate you select. I think the LCD can run at a much higher frequency that the touch panel parts.
      I hope this helps.

    • @vivekrohella9400
      @vivekrohella9400 2 ปีที่แล้ว

      @@BytesNBits Thanks for details provided. I have tested with UNO. It is working properly. Then I tried it with Mega & Due. Everything is working except touch. Pin Details in last message. Kindly note that I have used SD Card module. Both ILI9341 & SD module MIOS, MOSI & SCK are connected parallel.

    • @BytesNBits
      @BytesNBits  2 ปีที่แล้ว

      @@vivekrohella9400 That seems strange. Have you tried with just the touch connected on the Mega and Due?

    • @vivekrohella9400
      @vivekrohella9400 2 ปีที่แล้ว

      @@BytesNBits Tried but it's not working. Then I tried example sketch of LCDWIKI. Everything is working ok.

    • @BytesNBits
      @BytesNBits  2 ปีที่แล้ว +1

      @@vivekrohella9400 Did the working example use the same touch screen library? If not I'd substitute that one into your project.

  • @azulfenix7
    @azulfenix7 8 หลายเดือนก่อน

    errors in the code

    • @BytesNBits
      @BytesNBits  8 หลายเดือนก่อน

      I'll have to have a look and see if this is getting out of date.

  • @stoptheirlies
    @stoptheirlies 7 หลายเดือนก่อน

    Bob, I don't know what is going on but the files you have put on your website for us to download are nothing like what you show us here, this file on your site has the setup in the wrong place half way through the script and the script does not match what you show on here, Also some of your other script files have C++ code in them which will not run in the Arduino IDE, Pretty abysmal really and I am thinking you don't care as I have messaged you twice and you have not bothered to respond. Bob. UK

    • @BytesNBits
      @BytesNBits  7 หลายเดือนก่อน

      Sorry you're having problems. I've had a look at the code. It's all OK apart from the website code renderer has replaced the < symbols with the html code < and > with >. I think this is on the older code listings. Do a find and replace and the code should compile, though do have a look in case some other characters have been replaced.
      I assure you I do care. This is why I post these videos. I try to answer as many comments as I can.

  • @atihrot755
    @atihrot755 ปีที่แล้ว

    Dear Mr. Those codes don't work for me at all. I can't run drawing on the LCD. Can you help me?

    • @BytesNBits
      @BytesNBits  ปีที่แล้ว

      Hi. Your best bet is to try each part of the project separately. Make sure you can get the LCD panel working. Then try the basic touch screen functions and then try putting it all together.