Can't access M5 Paper touch screen in Arduino IDE.
-
Hello,
I'm trying to access the M5Paper touch screen though the arduino IDE, but it does not seem to be working.
I've modified the example code:#include <M5EPD.h> M5EPD_Canvas canvas(&M5.EPD); int point[2][2]; void setup() { M5.begin(); M5.EPD.SetRotation(90); M5.TP.SetRotation(90); M5.EPD.Clear(true); canvas.createCanvas(540, 960); canvas.setTextSize(5); canvas.drawString("Touch The Screen!", 20, 400); canvas.pushCanvas(0,0,UPDATE_MODE_DU4); Serial.begin(115200); } void loop() { Serial.println(M5.TP.avaliable()); if(M5.TP.avaliable()){ if(!M5.TP.isFingerUp()){ M5.TP.update(); canvas.fillCanvas(0); bool is_update = false; for(int i=0;i<2; i++){ tp_finger_t FingerItem = M5.TP.readFinger(i); if((point[i][0]!=FingerItem.x)||(point[i][1]!=FingerItem.y)){ is_update = true; point[i][0] = FingerItem.x; point[i][1] = FingerItem.y; canvas.fillRect(FingerItem.x-50, FingerItem.y-50, 100, 100, 15); Serial.printf("Finger ID:%d-->X: %d*C Y: %d Size: %d\r\n", FingerItem.id, FingerItem.x, FingerItem.y , FingerItem.size); } } if(is_update) { canvas.pushCanvas(0,0,UPDATE_MODE_DU4); } } } }
TP.available() seems to always return zero so none of the other code runs. Am I missing something?
-
Hello @tamoorh
The initialization of serial debug is already taken care of in
M5.begin()
- there is no need to add anotherSerial.begin()
. I just mention that because I've seen cases where callingSerial.begin()
twice caused some trouble.If you look into the function
M5.TP.available()
you'll see that there is a flaggt911_irq_trigger
which is cleared every time the function is called. So if you call it twice in a row the second call will always return false.If you want to observe the available value you'll need to modify the code to only call the function once:
bool t = M5.TP.avaliable(); Serial.println(t); if(t){
That said, there seems to be an issue when compiling for arduino-esp32 2.0.X - I2C seems to have trouble to initialize. I was able to fix it by changing a few lines in the library function
GT911:begin()
// Wire.setClock(400000); // Wire.begin(pin_sda, pin_scl); Wire.begin((int) pin_sda, (int) pin_scl, 400000U);
With the above change the touch example should run w/o any modifications.
Thanks
Felix -
@felmue Thank you so much for the response! This fixed it!
Is this an error with only the Arduino IDE? Or are there other edits that have to be made if I used platformIO? -
-
Hi
I am also having the same issue that I can't get the touch example to work. On the factory test it needed to reboot a few times before the touch screen initialised.
I tried changing the code as above in the gt911 but now my M5Paper keeps rebooting.
Any advice?
Regards
David
-
Hello @kazooz-igloos
above modifications should no longer be required as the necessary changes have been added into the current version found on github.
About 5 month ago a fix was committed for an issue which caused the M5Paper to crash - so make sure you have the latest version from github.
Using the latest M5EPD source from github (w/o modifications) I was able to compile an run the TOUCH.ino example just fine.
Thanks
Felix -
@felmue
HiThanks for the reply.
i have made sure I updated everything so have M5EPD 0.1.4 and Arduino version 2.1.1 on Mac.
When I compile and download the programme touch screen still doesn't work.
The serial output is as follows:
18:05:56.314 -> M5EPD initializing...OK
18:06:00.418 -> M5EPD initializing...OK
18:06:04.542 -> M5EPD initializing...OK
18:06:08.651 -> M5EPD initializing...OK
18:06:12.847 -> M5EPD initializing...OK
18:06:16.893 -> M5EPD initializing...OKAny idea if the issue is with my setup or with my M5Paper.
Thanks
David
-
Hello @kazooz-igloos
it looks like the fix for the constant crash/reboot has been committed into gitub after v0.1.4. Sorry for not catching that. I normally download the latest from main (ignoring tagged versions), extract the zip file manually and use that.
That said, the relevant change to fix the crash should be this one.
Thanks
Felix -
Hi @felmue
Followed your advice and got it to work. Thanks very much!