Teensy 4.1 simple button interference

Baptistou

Member
Hello,
For the past two hours I've been getting mad with a very basic stuff which behaves oddly, I hope somebody here would be able to help me :
I'm using a Teensy 4.1 and I have weird interferences while trying to use a simple button on an input pin. The pushbutton is connected to pin 34 on one side and to ground on the other side.
Pin 34 is configured as INPUT_PULLUP. However, when the button is not pressed (= pin 34 left in air), I get random HIGH and LOW readings in the sketch.
If I remove the wires going off the Teensy to the button, it is stable HIGH, but it seems that as soon as I put a wire about 5cm long connected to pin 34 and leave open the other side, I get random readings specially when my hand comes close to the wire as if the system was extra sensitive to magnetic fields. But I guess the internal PULLUP resistor should be far stronger than this and keep the pin HIGH.
I tried to use a different power supply to make sure it was not causing parasites, no success. I tried other input pins, no success. I tried also with another Teensy 4.1, no success either.
Software is teensyduino 1.53 with arduino 1.8.13
I don't have this issue with other boards (Mega, Teensy LC...).
Anyone has a clue ?
Below is my test sketch :

Code:
int state = 0;

void setup() {
  // put your setup code here, to run once:
  pinMode(34, INPUT_PULLUP);
  Serial.begin(9600);
  delay(1000); // let the serial stuff to boot, useful on Teensy
  Serial.println("--- Hello ---"); // just to see that the sketch boots

}

void loop() {

  if (digitalRead(34) != state){
    state = digitalRead(34);
    Serial.print("new state : ");
    Serial.println(state);
  }
}

when I have interferences, a lot of lines flow in the serial monitor.
 
I'm running it here on a Teensy 4.1 with a wire approx 11 cm long on pin 34.

wire.jpg

It's not printing anything other than the initial 2 lines, even if I touch the wire, move my hand nearby, etc.

screenshot.jpg
 
Hello Paul,

I did exactly as you did.
I eventually found out that the issue might be coming from the house ground. I ran the sketch on batteries only and the issue went away. It seems that as soon as my board is connected to ground by any way (computer USB + computer power cable, computer USB + house speakers etc.) I get the problem. I tried also on a Teensy 3.6, with the same results.

I'm a bit worried, as I'm supposed to build two systems which will play with RS232 data onboard a ship. Hopefully the ground won't be as bad as at home, but if that happens then I don't know how I can get rid off this as I won't be able to make sure the ground on the RS232 line is separated from the ship's ground.

Oddly the problem went away completely in the middle of the morning. I tried to know which stuff in the house causing interferences could have been turned off but could not find. Now it is pretty hard to make the problem happen again. That's even more worrying !!! Damned electric stuff........
 
You might want to try bypassing pin 34 with a .01 or .1 uf capacitor (10 or 100 nf). It may be RF interference riding in on your ground line.
 
Yep, I'll try this. I just found also a schematic for an encoder, which might be useful so I post it below :
filtre pour encodeur.png
=> Yes, with 100nF capacitors (that's what I had in stock) in parallel with the buttons that seems to work OK, even for the encoder.
Thanks :D
 
Last edited:
Hi,

i've just experienced this exact same interference-problem, for this exact same pin-34 configured as input_pullup, and used with a push button.
Thanks Google while searching "teensy 4.1 pin 34 interference".

This happens for all my x10 Teensy 4.1 boards.
the circuit around the board is complex, with a lot of button, LEDs, and so more.
everything is enclosed in a grounded metal case.
The length of the wire is about 20 cm, but it doesnt really matter.
There is no problem with all other buttons/pins. It only happens with that pin-34.

i went deep into this, using my oscilloscope on this pin-34:
i can see noise that is related to the PWM frequency of other pins (there is LEDs, and a TFT screen that uses PWM for intensity/brightness).
(that pin-34 is not PWM compatible)
the noise of pin-34 is much stronger for higher PWM frequency of all other pins. For example, it is quasi-immediate to perform a fake push-button for PWM frequency ~500khz (very worst case). It's almost ok for freq < 100 hz.
when i put the oscilloscope probe on the pin-34, it doesnt trig the button, as that contact probably "stabilize" the pin. But i can see the effect of the PWM freq on the noise.
Also, if i change the duty-cycle of the PWM, the noise has some better/worst spot, probably interference between frequency and duty-cycle/harmonics.
So, there is noise, and sometime the mean voltage of the pin-34 (while pullup) goes bellow 2.8V, depending of the freq + duty-cycle of others pins. At this point, the pin-34 button goes LOW (= fake pressed).

i didnt try the capacitor/filter trick, but i solved the problem by applying a real pull-up to the pin-34, e.g. wiring a (38k) resistor to +3.3V power supply, from the pin-34.
now the voltage is always 3.3V, no more noise, even at high PWM freq > 500khz.

.Croc.
 
i didnt try the capacitor/filter trick, but i solved the problem by applying a real pull-up to the pin-34


Yes that makes perfect sense, internal pullups are often too weak for off-board signals (or even on-board signals
if the layout is unfavorable) - use 10k physical pullup in the first instance, strengthening to 4k7, 2k2 or even 1k if required
(longer cable runs will usually be more noise-prone, but it depends a lot on the local environment).

Internal pullups/pulldowns have to be a compromize design - too strong and the power consumption becomes an
issue for micropower applications, too high and noise-rejection is ineffective. The lower the supply voltage and the
faster the chip the more sensitive it is likely to be to noise coupling, all else being equal.
 
Back
Top