Problems when connecting 3 touch sensors.

EspProblems1996
Posts: 3
Joined: Wed Sep 23, 2020 11:27 pm

Problems when connecting 3 touch sensors.

Postby EspProblems1996 » Wed Sep 23, 2020 11:44 pm

I am trying to make a BLE mouse.
For this, i am connecting 3 buttons to the esp32 TOUCH pins.

Code: Select all

touchAttachInterrupt(T0, gotLeftClick, 15);
    touchAttachInterrupt(T5, gotMiddleClick, 25);
    touchAttachInterrupt(T3, gotRightClick, 15);
   
and these are the callbacks

Code: Select all

volatile bool midleClickDetected = false;
void gotLeftClick(){
 buttons |=  0x01 ;
}
void gotRightClick(){
 buttons |=  0x02 ;
}
void gotMiddleClick(){
   midleClickDetected = true ;  
}
this code works well with 2 buttons, but when I add the third ( the middle )
it all goes bad.
Firstly, no buttons work.
secondly, after some time, the program just crashes and stops working all together (nothing in the serial monitor).
Here is the function in which I send the clicks:

Code: Select all

void getDisplacement () {
timeInMillis = millis() - start  ; 

if (timeInMillis >= 35) {
    prevLcState = false ; 
mpu.dmpGetQuaternion(&q, fifoBuffer);
dmpGetYawPitchRoll(q_a , &q, &gravity);
   
   double x = cos(q_a[0]) * cos(q_a[2]);
    double y = sin(q_a[0]) * cos(q_a[2]);
    double z = sin(q_a[2]);
    double t = 2000/x;
        x = t*x;
        y = t*y;
        z = t*z;

       
        z+=2040;
        if (abs(z) > 4095)
            z = 4095; 
      y+=2040;
        if (abs(y) > 4095)
            y = 4095;  
    if (z < 0) z = 0 ; 
    if (y < 0) y = 0 ; 
     
     int16_t scroll = 0; 
    if (midleClickDetected) {
        scroll =  z-2040;
    }
    
        uint8_t val[] = {
         (uint8_t)buttons, 
         lowByte((uint16_t)y) , 
         highByte((uint16_t)y) , 
         lowByte((uint16_t)z) , 
         highByte((uint16_t)z), 
         highByte((uint16_t)z),
          highByte(scroll) <<3};
     input->setValue(val, 6);
    input->notify();
    buttons = 0 ; 
      midleClickDetected  = false ;
    // //mouse.move((char)y  , (char) z);
      start = millis() ; 
    // movement_end_check();
}


}

I thought it might be that there are too many interrupts and the program can't work well, but it does the same thing no matter if I touch one button or not.

rodmcm
Posts: 47
Joined: Sat Sep 02, 2017 3:31 am

Re: Problems when connecting 3 touch sensors.

Postby rodmcm » Mon Sep 28, 2020 1:17 am

Your touchInterrupt T0 and T3 are both assigned to 15
Touch 0 = IO 4
Touch 1 = IO 00 ( may not be available)
Touch 2 = IO 2
Touch 3 = IO 15
Touch 4 = IO 13
Touch 5 = IO 12
Touch 6 = IO 14
Touch 7 = IO 27
Touch 8 = IO 33
Touch 9 = IO 32

Who is online

Users browsing this forum: No registered users and 15 guests