digitalRead oszillates: GND-problem?

Status
Not open for further replies.

jpk

Well-known member
Hi!

Some pins of my Teensy3.5 give random output even with internal pullups enabled. Here is a diagram of my project:

diagram.jpg

There are 2 metal enclosures (relatively big), one of them contains the PSU. Plus and minus of the PSU go to both teensies (minus goes to GND), so the Teensies GNDs are not connected to mains earth. One enclosure is connected to mains earth, the other enclosure is connected to the first enclosure. The USB cable shields are only connect at one side, so no connection of the shield to GND (but all 4 USB lines are connected, and the VUSB pad is disconnected).

Now, if I connect the Teensy3.5 via USB to my PC some pins (not all) start to flip randomly. It seems I can stop this by connecting GND to mains earth (marked in red), but I am not sure if it's OK to do so...

Please let me know how to best layout the GND and earth connections!
 
To update this topic: I have a bunch of sensors, PSUs, drives, buttons, encoders, displays, LEDs etc. connected to the Teensies and could not totally solve the problem by working with the GND connections. Instead it turned out that I had I2C wires too close to those randomly flipping pins. I changed to a lower I2C speed and moved the pins from the wires away (as I could not move the I2C wires already soldered I just used different pins which are farer away from where the I2C wires run). The situation seems stable so far.

I am surprised to learn that relatively short wires from the I2C pins could disturb input_pullup pins such that the readings flip randomly.

The question remains which layout of grounding should be used in projects like shown in my diagram...
 
Apart from re-thinking the earth/gnd concept I found a solution to emi-protect pins, i.e. for reading buttons over long and noisy lines, see here.
 
Internal pullups are quite weak (in Teensy 3.2 they are about 33K if I remember well; Teensy 4.0 should be around 100K. Don't know the specific value for 3.5, but you get the idea).
They may be too weak for your purposes.
 
Status
Not open for further replies.
Back
Top