Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sensitivity not changed if updateConfig called after carrier.begin() #21

Open
jeniara opened this issue Jan 31, 2021 · 9 comments
Open
Assignees
Labels
type: imperfection Perceived defect in any part of project

Comments

@jeniara
Copy link

jeniara commented Jan 31, 2021

If I modify the example "Custom_Sensitivity" and move the carrier.begin() on line 22 and put it BEFORE line 20:

carrier.Button0.updateConfig(threshold);

it no longer respond to touch. However, if I uncomment line 16:

// CARRIER_CASE = false;

then it works again, even with carrier.begin(); before the setting.

I can not verify if the updateConfig actually change the values (yet) but I think the code should be robust to allow definition of button sensitivity before or after the begin.carrier() call.

@marqdevx
Copy link
Member

Hey @jeniara could you please send me the sketch? Thanks

@jeniara
Copy link
Author

jeniara commented Jan 31, 2021 via email

@marqdevx
Copy link
Member

marqdevx commented Jan 31, 2021

So, hmm it doesnt matter if you change the threshold after the carrier.begin() (theorically)

Im going to debug it tomorrow and let you know if I find something.

Thanks for the feedback.

@marqdevx marqdevx self-assigned this Jan 31, 2021
@marqdevx marqdevx added conclusion: invalid Issue/PR not valid type: imperfection Perceived defect in any part of project and removed conclusion: invalid Issue/PR not valid labels Jan 31, 2021
@jeniara
Copy link
Author

jeniara commented Feb 1, 2021

Now I was able to check again:

This is working

#include "Arduino_MKRIoTCarrier.h"
MKRIoTCarrier carrier;

// When CARRIER_CASE is false it's set to 100 (closer)
// When CARRIER_CASE is true it's set to 4  (further)
// But if you use Buttons.updateConfig(value) It will not set the above values

unsigned int threshold = 4;
unsigned int threshold_btn_0 = 4;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  while (!Serial);

  // CARRIER_CASE = true;
  //Now we can set our custom touch threshold
  // First we update all the buttons with the new threshold
  // Then we overwrite individually one of them (they can be all set individually too)


  carrier.Buttons.updateConfig(threshold);
  carrier.Button0.updateConfig(threshold_btn_0);
  Serial.println("Updated Config");
  carrier.begin();
  Serial.println("carrier begin");
}

void loop() {
  // put your main code here, to run repeatedly:
  carrier.Buttons.update();
  
  // Verify your thresholds
  if (carrier.Button0.getTouch()) {
    Serial.println("touching 0");
  }
  
  if (carrier.Button1.getTouch()) {
    Serial.println("touching 1");
  }
  
  if (carrier.Button2.getTouch()) {
    Serial.println("touching 2");
  }
  
  if (carrier.Button3.getTouch()) {
    Serial.println("touching 3");
  }
  
  if (carrier.Button4.getTouch()) {
    Serial.println("touching 4");
  }
}

This is not working

#include "Arduino_MKRIoTCarrier.h"
MKRIoTCarrier carrier;

// When CARRIER_CASE is false it's set to 100 (closer)
// When CARRIER_CASE is true it's set to 4  (further)
// But if you use Buttons.updateConfig(value) It will not set the above values

unsigned int threshold = 4;
unsigned int threshold_btn_0 = 4;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  while (!Serial);

  // CARRIER_CASE = true;
  //Now we can set our custom touch threshold
  // First we update all the buttons with the new threshold
  // Then we overwrite individually one of them (they can be all set individually too)
  carrier.begin();
  Serial.println("carrier begin");
  carrier.Buttons.updateConfig(threshold);
  carrier.Button0.updateConfig(threshold_btn_0);
  Serial.println("Updated Config");
}

void loop() {
  // put your main code here, to run repeatedly:
  carrier.Buttons.update();
  
  // Verify your thresholds
  if (carrier.Button0.getTouch()) {
    Serial.println("touching 0");
  }
  
  if (carrier.Button1.getTouch()) {
    Serial.println("touching 1");
  }
  
  if (carrier.Button2.getTouch()) {
    Serial.println("touching 2");
  }
  
  if (carrier.Button3.getTouch()) {
    Serial.println("touching 3");
  }
  
  if (carrier.Button4.getTouch()) {
    Serial.println("touching 4");
  }
}

@mhavill
Copy link

mhavill commented Aug 7, 2021

@jeniara - I have to agree with you - I have spent a day trying to resolve Button0 not responding when in the case. The instructions in Calibrating-the-MKR-IoT-Carrier-capacitive-buttons just don't work for 2 reasons.

  • Firstly, as you have pointed out the once you run carrier.begin(); you can no longer update the threshold of any button. @marqdevx, it would be great if threshold could be modified after begin(). I set up a widget on a dashboard to be able to tune the threshold on the fly but because it was fixed after begin () it was ineffective. I have got all buttons working in the case with
    CARRIER_CASE = true;
    carrier.Buttons.updateConfig(50, TOUCH0);
    carrier.begin();
  • Secondly, the code in the calibration article was incorrect in the implementation of the intention to set Button0 independently in the Calibration example:
unsigned int threshold = 98;
unsigned int threshold_btn_0 = 95;
...
  carrier.begin();
  //CARRIER_CASE = false;
  //Now we can set our custom touch threshold
  // First we update all the buttons with the new threshold
  // Then we overwrite individually one of them (they can be all set individually too)
  carrier.Buttons.updateConfig(threshold);
  **carrier.Buttons.updateConfig(threshold_btn_0);** 

//this would have updated all buttons!  Should have been
carrier.Button0.updateConfig(threshold_btn_0); //or
carrier.Buttons.updateConfig(threshold_btn_0, Touch0);

@marqdevx
Copy link
Member

marqdevx commented Aug 9, 2021

Hello @mhavill @jeniara !
Could you pleasee check if you have the latest version of the Arduino_MCHPTouch (v1.2.1) and the version of the Arduino_MKRIoTCarrier is v1.0.2

Thanks

@mhavill
Copy link

mhavill commented Aug 10, 2021

Hi @marqdevx,
I can confirm that on my IDE I have the latest versions installed.
From Cloud Editor I presume it will pick the latest version unless I specifically include an earlier version, as we don't get to 'install' the libraries?

Thanks

@marqdevx
Copy link
Member

Thanks @mhavill , yes the Online Editor uses the latest version by default, I'll try the sketch and contact you with more info.
Have a nice one!

@lukekarrys
Copy link

I think I ran into the same issue as this. What I found is that the default value of CARRIER_CASE is false and begin() always calls Buttons.updateConfig() in that case. And since you updateConfig() wont have any effect after calling begin(), in the default case, you cant change button sensitivity.

Here are the two references to the code I could find:

bool CARRIER_CASE = false;

if (!CARRIER_CASE) {
Buttons.updateConfig(200);
}

This is the same thing found in #21 (comment), I'm just reiterating the behavior for the latest version, and a workaround below.

As of v2.0.4 if you want to update the button sensitivity, you need to do it like this.

#include "Arduino_MKRIoTCarrier.h"
MKRIoTCarrier carrier;

void setup() {
  Serial.begin(9600);
  while (!Serial);

  // make sure withCase() is called so begin() does not reset
  // the button sensitivities
  carrier.withCase();

  // then set all the button sensitivities individually
  carrier.Buttons.updateConfig(4, TOUCH0);
  carrier.Buttons.updateConfig(30, TOUCH1);
  carrier.Buttons.updateConfig(60, TOUCH2);
  carrier.Buttons.updateConfig(100, TOUCH3);
  carrier.Buttons.updateConfig(200, TOUCH4);

  // or set them all at once
  // carrier.Buttons.updateConfig(200);

  // finally call begin
  carrier.begin();
}

@per1234 per1234 changed the title UpdateConfig after of before carrier.begin() Sensitivity not changed if updateConfig called after carrier.begin() Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

4 participants