GrovePi - noise / EMs on input ports

I noticed an occasional random button press with the grove_switch_relay.py example.
The relay would click (as if the button was pressed) randomly a few times a minute.
I then simply unplugged the switch from the 20 cm cable. The problem got much worse.
I then swapped out the relay for a LED, and this showed similar problems. The push button switch, LED and relay are the standard starter kit components.

It appears that all it takes is a 20 cm cable to act as a very effective antenna that then randomly takes a digital input high or low.

I do have a number of other WiFi devices on my test bench.

Are there any design principles for reducing the GrovePi’s sensitivity to noise?

Hi @mikeseiler,

Have you also plugged a Grove Button into the designated port?

I have tried your example too and I haven’t seen any fluctuations whatsoever.

When an output port is dependent on an input value, and no sensor is connected to the input port, then the output port's state can fluctuate - this is caused by the fact that the input port's wire is left in the air, with no definite state set.

So, to answer to your questions :

  1. There are no design principles for reducing the GrovePi's sensitivity to noise - at least not in this case.

  2. The number of WiFi devices is not going to influence the GrovePi through any means. The WiFi devices operate at such great frequencies that you don’t need to worry. On the other hand, magnets can cause harm by inducing currents when they’re moved around.

I’d also suggest you to post some pictures of your setup, maybe even a video showing us how it does fluctuate.

I think that’s all for now.

Thank you!

Thanks for the response @RobertLucian,

I’ve boiled down the code to:

#!/usr/bin/env python
# GrovePi Example of noisy input
import time
import grovepi

# Connect the Grove Switch to digital port D3
# SIG,NC,VCC,GND
switch = 3
count = 0 # count the number of times through the loop
grovepi.pinMode(switch,"INPUT")

while True:
    try:
        if grovepi.digitalRead(switch):
            print(count)  #print loop count
        time.sleep(.1)
        count +=1  # increment loop count

    except KeyboardInterrupt:
        grovepi.digitalWrite(relay,0)
        break
    except IOError:
        print ("Error")

When I run this code without a wire plugged into D3, I don’t get any output. But, when I plug in a 20 cm grove connector wire, I get a occasional high reading. So the output is pretty random.

12
19
27
45
91
103
144
262
335
342
384
396
438
453

and it keeps going.

My python code got messed up in the previous post.
Here it is - correctly formatted:

!/usr/bin/env python

# GrovePi Example of noisy input

import time
import grovepi

#Connect the Grove Switch (or just a wire) to digital port D3
switch = 3
count = 0 # count the number of times through the loop
grovepi.pinMode(switch,"INPUT")

while True:
    try:
        if grovepi.digitalRead(switch):
            print(count)  
        time.sleep(.1)
        count +=1

Hi @mikeseiler,

It’s normal to see those voltage spikes when the input line is left in the air.
That’s caused by the current that’s flowing through the wire.
And the current is actually induced by nearby electromagnetic waves.

As you have said, the Grove cable acts as an antenna and is going to pick up every electromagnetic wave.


In order to get rid of this, you need to have the port connected to a sensor before reading its digital state.

Also, I’m not sure what you’re trying to achieve by solving this “issue” - the way I’m seeing it, it’s something perfectly normal. Could you describe more on this matter?


Thank you!