No video

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

  Рет қаралды 27,451

Bytes N Bits

Bytes N Bits

Күн бұрын

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....

Пікірлер: 70
@danielewusi-essel219
@danielewusi-essel219 3 жыл бұрын
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!
@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 2 жыл бұрын
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 Жыл бұрын
@@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.
@jumbo999614
@jumbo999614 3 жыл бұрын
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 3 жыл бұрын
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 kzfaq.info/get/bejne/p7SXh810yNydpoE.html
@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.
@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.
@halalbach1855
@halalbach1855 2 жыл бұрын
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 &lt; 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 " &gt; ". 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 &lt; looks like an html thing.
@johnvine5731
@johnvine5731 2 жыл бұрын
It might be a browser problem. The browser cannot display the 'greater than' and 'less than symbols' . So, instead of < and >, the browser displays &lt and &gt. 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.
@coby1kenobii
@coby1kenobii 3 жыл бұрын
love the animations!
@BytesNBits
@BytesNBits 3 жыл бұрын
Thanks
@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.
@mevmevmev
@mevmevmev 2 жыл бұрын
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 2 жыл бұрын
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 8 ай бұрын
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 8 ай бұрын
@@larrybud I had to put the project aside. Hoping to get back to it at some point.
@pw3111
@pw3111 2 жыл бұрын
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 .
@paulunsinn6670
@paulunsinn6670 8 ай бұрын
THX
@BytesNBits
@BytesNBits 8 ай бұрын
No problem
@user-mg2gb3tl1g
@user-mg2gb3tl1g Жыл бұрын
Благодарим ви!
@BytesNBits
@BytesNBits Жыл бұрын
You're welcome
@rompipelotas
@rompipelotas Жыл бұрын
THANKS A LOT !!!!!!
@BytesNBits
@BytesNBits Жыл бұрын
no problem.
@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.
@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 :)
@April2023-fb6pf
@April2023-fb6pf 8 ай бұрын
Can we use for another shield tft?
@BytesNBits
@BytesNBits 8 ай бұрын
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 8 ай бұрын
My tft shield with arduino uno get a white screen. Where my problem
@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 &lt; and &gt; codes with < and > it should work. I'll try and update the code listing over the next few days.
@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.
@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 Жыл бұрын
@@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.
@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 жыл бұрын
@@vivekrohella9400 Did the working example use the same touch screen library? If not I'd substitute that one into your project.
@azulfenix7
@azulfenix7 11 ай бұрын
errors in the code
@BytesNBits
@BytesNBits 11 ай бұрын
I'll have to have a look and see if this is getting out of date.
@stoptheirlies
@stoptheirlies 10 ай бұрын
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 10 ай бұрын
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 &lt; and > with &gt;. 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.
Coding Games on an ILI9341 SPI LCD and Touchscreen - Arduino
1:05:46
Bytes N Bits
Рет қаралды 11 М.
Basic animation in your SPI LCD touchscreen
41:04
Bytes N Bits
Рет қаралды 22 М.
طردت النملة من المنزل😡 ماذا فعل؟🥲
00:25
Cool Tool SHORTS Arabic
Рет қаралды 19 МЛН
7 Days Stranded In A Cave
17:59
MrBeast
Рет қаралды 93 МЛН
Schoolboy Runaway в реальной жизни🤣@onLI_gAmeS
00:31
МишАня
Рет қаралды 3,7 МЛН
Incredible Dog Rescues Kittens from Bus - Inspiring Story #shorts
00:18
Fabiosa Best Lifehacks
Рет қаралды 23 МЛН
Arduino Touchscreen Display - Using a Resistive Touchscreen
38:51
DroneBot Workshop
Рет қаралды 406 М.
Simple ILI9341 LCD Display With ESP32 Dev Module Step By Step
10:11
Using a 2.8in SPI LCD Touchscreen ILI9341 with an ESP32 on the new Arduino IDE 2
10:34
ESP32 with SPI  480x320 Touch Screen, is it a ILI9481 or ILI9486?
16:51
Cheap and Easy to Use ESP32 Screen!
8:21
Brian Lough
Рет қаралды 133 М.
Arduino TFT LCD Touch Screen Tutorial 3.5 Inch 480x320
11:56
Gadget Reboot
Рет қаралды 41 М.
TFT Touch Display Tutorial | MCUFriend | SdevElectronics
7:57
SDev Electronics
Рет қаралды 14 М.
Getting Started with ESP32 and the ILI9341 TFT LCD Display
8:49
ShotokuTech
Рет қаралды 17 М.
طردت النملة من المنزل😡 ماذا فعل؟🥲
00:25
Cool Tool SHORTS Arabic
Рет қаралды 19 МЛН