Phantom Clicks

Status
Not open for further replies.

mpsernie

New member
I have created a really basic projects, 2 buttons (using industrial type), metal box (again, industrial). On the 2 buttons, each will move to 3 different locations, each time clicking. This is used for printing labels based on a different system.

The issue that I am having, I am getting phantom clicks. No one will be near the button, but it will move using the sequencing above. After rewriting the project, using a different Teensy board, replacing all wiring, the issue still happens. The latest fix (and so far it seems to be holding up), is that I wrapped the Teensy in a static bag. No issue yet, but the users might not be telling me now.

The only thing I can think of is if there is EMI or static getting in? The location is not exactly static free, and there are several radio devices in the area. Could this be an issue? And would it make sense to ground the Teensy to the box?

If anyone has any ideas, let me know. This is not an every day issue, however it is often enough to frustrate me.
 
Do you debounce the inputs? And do you use pull-up (or pull-down) resistors on the inputs?
 
Are you using pullups/pulldowns on the input pins? Failing that, I'd suggest posting a schematic. If an anti-stat bag is curing the issue, it sounds like a hardware issue, and a lack of/insufficient pullups/pulldowns could certainly cause the problem, particularly in a noisy (electrically) environment.

Edit: Epyon posted faster than me. Debounce is a good suggestion too.
 
Like I said, it is basic. But I will take a look at the Bounce.

I have also attached my code as well.

teensy-basic-buttons.png

Code:
void setup(){
Serial.begin(9600);
pinMode(5, INPUT_PULLUP);
delay(500);
}

void loop(){
  
// Button 1
if (digitalRead(5) ==LOW)
{
  delay(500);
  Mouse.move(-127,-127);
  Mouse.move(-127,-127);
  Mouse.move(-127,-127);
  Mouse.move(-127,-127);
  delay(500);
  Mouse.move(127,127);
  Mouse.move(127,120);
  Mouse.move(127,0);
  Mouse.move(40,0);
  Mouse.click();
  delay(500);
}

}
 
Definitely use the Bounce library!

I'm not recommending you try to fix this code. Use Bounce. But for academic sake, consider your code doesn't wait for the pin to be high again. It could easily run twice if the button is held for 1.5 seconds!

But do not bother fixing this. More problems await. Use Bounce instead. It's very well tested and very easy to use. It's also easy to add more buttons, without worrying about delays from one impacting the responsiveness of the others.

For an example, check out the audio lib tutorial. File > Examples > Audio > Tutorial > Part_1_05_Do_More_While_Playing.
 
Debounce will probably help, though it's normal feature of avoiding multiple presses isn't needed with the three delay steps in there. I believe it does also check that the input really has been pressed, rather than responding to a very short transient press

Coding to do the some could be like
Code:
int counter=0;
void setup(){
Serial.begin(9600);
pinMode(5, INPUT_PULLUP);
delay(500);
}

void loop(){
  
// Button 1
if (digitalRead(5) ==LOW) {counter++;}
if (counter>10)
{
  counter=0;
  delay(500);
  Mouse.move(-127,-127);
  Mouse.move(-127,-127);
  Mouse.move(-127,-127);
  Mouse.move(-127,-127);
  delay(500);
  Mouse.move(127,127);
  Mouse.move(127,120);
  Mouse.move(127,0);
  Mouse.move(40,0);
  Mouse.click();
  delay(500);
}
delay(5);
}
Which should require a press of at least 50 ms long before the mouse driving routine fires.
 
Status
Not open for further replies.
Back
Top