GrovePi+ ports giving nonzero input spontaneously

Hi there, I managed to get GrovePi+ connected to RPi 400. However, I can’t get the input sensors to work correctly as they are providing non-zero inputs (in between correct input values) - either 255 or 65535 depednding on the type of sensor selected. Moreover, it seems as if the ports are giving this input even if nothing is connected.

By running this code without anything connected I can see that the signal happens once every 10 loop runs but if my sleep is shorter this is much more frequent.

buzzer_pin = 2		#Port for buzzer
button = 4		#Port for Button
pinMode(buzzer_pin,"OUTPUT")	# Assign mode for buzzer as output
pinMode(button,"INPUT")		# Assign mode for Button as input

pressed_counter=0
idle_counter=0
while True:
    try:
        button_status=digitalRead(button)	#Read the Button status
        if button_status:
            #print(button_status)
            pressed_counter+=1
            print("idle: " + str(idle_counter)+"\npressed: " + str(pressed_counter))
            time.sleep(0.1)
        else:
            #print(button_status)
            idle_counter+=1
            print("idle: " + str(idle_counter)+"\npressed: " + str(pressed_counter))
            time.sleep(0.1)

Outputs (LED, buzzer) seem to work fine as far as I can tell. Sensors are mostly giving right inputs in between spontaneous max inputs. Am I doing anything obviously wrong?

1 Like

A Pi 400?

Are you sure?  If I remember correctly, that’s the “keyboard based” Raspberry Pi implementation, right?

Noisy sensors that seem to randomly do whatever they darn well please is often due to grounding issues.  If you don’t have a rock-solid ground connection between the two, signals can, and will, do screwy things.

Under normal conditions, the Grove board is mounted directly on the Pi’s pin headers.  Using a Pi-400, it would have to be at the end of a relatively long ribbon cable - an untested configuration.

I am not sure what you can do to improve that - maybe by connecting a relatively large wire between a grounded mounting pad on the Grove board and a grounded mounting pad on the Raspberry Pi itself.

“Grounded” = A mounting hole surrounded by a metal pad.

1 Like

Fill in the blanks for each sensor you tried:

Port ______ Sensor _______ Program ____________
Port ______ Sensor _______ Program ____________
Port ______ Sensor _______ Program ____________

$ ls /home/pi/Dexter/GrovePi/Software/Python/
build                                    grove_infrared_distance_interrupt.py
dist                                     grove_infrared_reflective_sensor.py
firmware_tests                           grove_ir_receiver
grove_2_coil_latching_relay.py           grove_ir_receiver.py
grove_4_digit_display.py                 grove_ledbar.py
grove_6axis_acc_compass                  grove_led_blink.py
grove_80cm_infrared_proximity_sensor.py  grove_led_fade.py
grove_accelerometer_16g                  grove_light_sensor.py
grove_air_quality_sensor.py              grove_line_finder.py
grove_analog_read.py                     grove_loudness_sensor.py
grove_barometer_sensors                  grove_magnetic_switch.py
grove_button.py                          grove_mini_motor_driver
grove_buzzer.py                          grove_moisture_sensor.py
grove_chainable_rgb_led                  grove_mosfet.py
grove_co2_sensor                         grove_nfc_tag.py
grove_collision_sensor.py                grove_oled
grove_compass_example.py                 grove_ph_sensor.py
grove_compass_lib.py                     grove_piezo_vibration_sensor.py
grove_dht_pro_filter                     GrovePi_Hardware_Test.py
grove_dht_pro.py                         grovepi.py
grove_dry_reed_relay.py                  grove_pir_motion_sensor.py
grove_dust_sensor.py                     grove_relay.py
grove_earclipheartrate                   grove_rflink433mhz_oneway_kit
grove_electricity_sensor.py              grove_rgb_lcd
grove_electromagnet.py                   grove_rotary_angle_sensor.py
grove_encoder_read.py                    grove_single_axis_analog_gyro.py
grove_fingerclip_heart_sensor            grove_slide_potentiometer.py
grove_firmware_version_check.py          grove_solid_state_relay.py
grove_flame_sensor.py                    grove_sound_sensor.py
grove_flow_read.py                       grove_spdt_relay.py
grove_gas_sensor.py                      grove_switch.py
grove_gesture_sensor                     grove_switch_relay.py
grove_gps                                grove_temperature_sensor.py
grove_hcho_sensor.py                     grove_thumb_joystick.py
grove_hightemperature_sensor             grove_tilt_switch.py
grove_i2c_accelerometer.py               grove_touch_sensor.py
grove_i2c_adc                            grove_ultrasonic.py
grove_i2c_color_sensor                   grove_vibration_motor.py
grove_i2c_digital_light_sensor           grove_water_sensor.py
grove_i2c_motor_driver                   package_description.rst
grove_i2c_multichannel_gas_sensor        package_modules.txt
grove_i2c_oled_128_64                    README.md
grove_i2c_rtc.py                         requirements.txt
grove_i2c_sunlight_sensor                setup.cfg
grove_i2c_temp_hum_hdc1000               setup.py
grove_i2c_temp_hum_sensor_mini           temp.py
grove_i2c_touch                          test_script

This is correct. It is possible to plug GrovePi directly into the GPIO on the back of Pi400 (I tried with the ribbon as well but this is not necessary). Tbh I did not check the pin mapping assuming they are the same as Pi4 and GrovePi is compatible with 4. The blinking LED test passes and I see correct inputs from correct ports (among the spurious false-positive signals).

@cyclicalobsessive here are the configurations I tested:

| Project              | script                  | input               | output    | read_values_zero_input | read_values_nonzero_input | read_values_blank | output_behaviour |
|----------------------|-------------------------|---------------------|-----------|------------------------|---------------------------|-------------------|------------------|
| LED Fade             | led_fade.py             | A0-A2:Potentiometer | A5:LED    | 0,255,65535            | 0-1023                    | 240-260,65535     | correct          |
| Button and buzzer    | Button_And_Buzzer.py    | D2:Button           | D5:Buzzer | 0,255                  | 0,255                     | 0,255             | correct          |
| Ultrasonic And Relay | Ultrasonic_And_Relay.py | D4:Ultrasonic       | D2:Relay  | NA                     | correct distance,65535    | 0,255,65535       | correct          |

2 Likes

I still do not understand exactly what you are talking about.
Is this the script where you are seeing “false positives”/incorrect output?

more /home/pi/Dexter/GrovePi/Projects/Ultrasonic_And_Relay/Ultrasonic_And_Relay.py
# GrovePi + Grove Ultrasonic Ranger
# http://www.seeedstudio.com/wiki/Grove_-_Ultrasonic_Ranger

# This is an project using the Grove Ultrasonic Ranger and Relay from GrovePi start kit
# 
# In this project, the ultrasonic can figure out the distance of object in front, 
# when object close to it within 10cm, the relay will turn on

'''
## License

The MIT License (MIT)

GrovePi for the Raspberry Pi: an open source platform for connecting Grove Sensors to the Rasp
berry Pi.
Copyright (C) 2017  Dexter Industries

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
'''

from grovepi import *

# Connect the Grove Ultrasonic Ranger to digital port D4
# SIG,NC,VCC,GND

ultrasonic_ranger = 4
Relay_pin = 2

pinMode(Relay_pin,"OUTPUT")

while True:
    try:
        # Read distance value from Ultrasonic
        distant = ultrasonicRead(ultrasonic_ranger)
        print(distant,'cm')
        if distant <= 10:
            digitalWrite(Relay_pin,1)
        else:
            digitalWrite(Relay_pin,0)

    except TypeError:
        print("Error")
    except IOError:
        print("Error")

By “false positives” do you mean the relay is triggered when the distance reading is not less than 10cm or the distance readings are less than 10cm when the actual distance is not less than 10cm?

That script contains no sleep to limit driving the ultrasonic ranger too fast, (perhaps the print statement is supposed to be limiting the cycle - not a good strategy, IMO)

The example in the Grove Ultrasonic Ranger datasheet shows a 0.250 second delay between readings.

You could try your script adding:

from time import sleep

...

while True:
    sleep(0.250)     # limit loop to allow ultrasonic sensor recovery
    try:

In one of my Ultrasonic ranger test scripts (from two years ago), I see a sleep(0.100) statement, so it would appear I determined the sensor could be used to take 10 readings per second.

Personally, I think that any use of the ultrasonic ranger needs to take three readings and use the average.
The readings have a tendency to bounce around a bit, so an average over three readings, with a “sensor recovery time delay” in between each reading is a more reliable way to use a ranging sensor.

2 Likes

Another thought:

Where are you getting the actual sensors from?

We’ve had reports in the past saying that Seeed Studios sensors are junk and produce whatever readings they darn-well please.

If you are using Seeed Studios sensors, you might want to replace them with sensors from a more reputable vendor.

1 Like

Yes, more generally, I get “max input” values (255 or 65535) from all sensors at random. However, adding the sleep function at the beginning of the while loop made things much better, thanks! Previously, I tried sleep inside the Try loop and it didn’t help much. This, plus ignoring the max inputs should do the job.

If you are using Seeed Studios sensors, you might want to replace them with sensors from a more reputable vendor.

Which sensors would you recommend @jimrh ?

1 Like

I really don’t have a specific recommendation, just the generalized observation that, as a general rule, Seeed Studios sensors tend to be less capable than a similar sensor from a different source, like SparkFun or Adafruit.

If you do a forum search for Seeed and sensor, you should get a lot of excellent reading!

This topic was an especially interesting study: