| Electronics > Projects, Designs, and Technical Stuff |
| I need a bit of help with touchscreen coordinates on mcufriend display |
| (1/1) |
| muscleleaf:
Hello EEVlog community. I am sorry if this is not the right location to post. I am working with an mcufriend 3.5" TFT Touchscreen display on an Arduino Mega using the mcufriend_kbv library. I got everything working fine, things draw properly, all that crap but I cannot for the life of me get the touchscreen to work as intended. The X and Y are mirrored as hell. I press left it goes right and vice versa. In my project I have: #define XM A1 // must be an analog pin, use "An" notation! #define YP A2 // must be an analog pin, use "An" notation! #define XP 7 // can be a digital pin #define YM 6 // can be a digital pin and in the loop() xpos = map(tp.y, 210, 902, 0, tft.width()); ypos = map(tp.x, 859, 213, 0, tft.height()); I have gotten these values by running the mcufriend_kbv calibration thing. The calibration worked fine, I was able to press the crosshairs correctly and it printed this to serial: TouchScreen.h GFX Calibration Making all control and bus pins INPUT_PULLUP Typical 30k Analog pullup with corresponding pin would read low when digital is written LOW e.g. reads ~25 for 300R X direction e.g. reads ~30 for 500R Y direction Testing : (A1, D7) = 21 Testing : (A2, D6) = 31 Diagnosing as:- XM,XP: (A1, D7) = 21 YP,YM: (A2, D6) = 31 ID = 0x6814 cx=286 cy=363 cz=139 LEFT, TOP, Pressure cx=247 cy=565 cz=138 LEFT, MIDH, Pressure cx=170 cy=918 cz=238 LEFT, BOT, Pressure cx=523 cy=157 cz=630 MIDW, TOP, Pressure cx=529 cy=917 cz=342 MIDW, BOT, Pressure cx=882 cy=156 cz=702 RT, TOP, Pressure cx=887 cy=533 cz=570 RT, MIDH, Pressure cx=748 cy=830 cz=437 RT, BOT, Pressure MCUFRIEND_kbv ID=0x6814 320 x 480 const int XP=7,XM=A1,YP=A2,YM=6; //320x480 ID=0x6814 const int TS_LEFT=213,TS_RT=859,TS_TOP=210,TS_BOT=902; PORTRAIT CALIBRATION 320 x 480 x = map(p.x, LEFT=213, RT=859, 0, 320) y = map(p.y, TOP=210, BOT=902, 0, 480) Touch Pin Wiring XP=7 XM=A1 YP=A2 YM=6 LANDSCAPE CALIBRATION 480 x 320 x = map(p.y, LEFT=210, RT=902, 0, 480) y = map(p.x, TOP=859, BOT=213, 0, 320) I am using the display in the landscape orientation number 1. I have tried swapping around the defined pins and it changes stuff but still not what I need, it makes it believe up is left and down is right and stuff like that. I think I've rotated those values in all possible ways. Any ideas why it flips right and left? I am using the standard drawing sketch by mcufriend_kbv and when I draw in the left corner it draws in the right one. Thanks a lot for your help, this has been driving me mad for the past week |
| Navigation |
| Message Index |