GPIO communication with Raspberry Pi - possible grounding issue?

Hello forum,

I created an account here to possibly get some help on this specific issue that has been driving me mad for days. Firt of all an overview over the setup:

The OpenMV H7 Plus is mounted on a Sphero RVR robot, by whose 5V line it is powered and controls it via UART (P4, P5). The WiFi Shield is also connected to the camera, which left me with only P9 to use as a GPIO pin.
Also mounted on the robot is a Raspberry Pi 4, powered by the RVRs USB port. This Pi has a sensor hub mounted on top of if and has an ultrasonic ranging sensor attached. All of this works so far.
Now the issue is that when the Pi detects an obstacle via the ultrasonic sensor it will set a GPIO pin to high, that pin is connected to P9 of the Camera, which has it configured as an input and stops any forward movement. I have therefore connected a GPIO pin of the Pi with P9 and connected the ground by conencting the line between the Cam GND rail and the RVR GND with a GND pin on the Pi as well. between the Pi GPIO and P9 there is a 1k series resistor for safety.
I have written these two scripts to test this:
On the camera (shortened it a lot for this post) this should check the value on the GPIO pin and set the LEDs on the robot accordingly (which was tested independently and is not the issue):

# set GPIO pin as input for collision interrupt
p_collision = pyb.Pin("P9", pyb.Pin.IN)
print('gpio value %d' % p_collision.value())

current_color = 2
set_leds()
new_color = 2


def mainRun():
    global current_color
    global new_color

    while (True):
        print(p_collision.value())

        if p_collision.value() == 1:
            print('collision')
            new_color = 3
        else:
            print('ok')
            new_color = 2

        if new_color != current_color:
            current_color = new_color
            set_leds()

On the Pi is this simple script which just alternates the signal on the GPIO pin:

import sys
import os
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../')))

import RPi.GPIO as GPIO
import asyncio

import time

GPIO.setmode(GPIO.BCM)


o_collision = 26

GPIO.setup(o_collision, GPIO.OUT)



def main():
    while True:
        time.sleep(5)
        print('0')
        GPIO.output(o_collision, False)
        time.sleep(5)
        print('1')
        GPIO.output(o_collision, True)

try:
    main()
except KeyboardInterrupt:
    print('Program ended by KeyboardInterrupt')
    GPIO.cleanup()

With a multimeter I have confirmed that the voltage between the desired GPIO pin on the Pi and a GND pin next to it alternates between (roughly) 0V and 3V3. Now here is the strange issue: So far I have only been able to get the Cam to correctly read the input on the pin when it was connected via USB and I ran the script through the OpenMV IDE. Furthermore, I had to fumble together my own pulldown resistor in front of it (tried 56k and smaller down to 15k with varying success), to ever get the voltage low enough to not be read as high. I tried adding “pyb.Pin.PULL_DOWN” to the pin setup in the script as well. Whatever I do, the voltage measured between the camera P9 and its GND pin never drops to 0, the lowest was around 1.3V if I recall.

Does anyone have any clue as to what I could be doing wrong? Could there be an issue with a ground loop? If so I’d be unsure as how to resolve it, I have no other means of powering the components if the whole thing is supposed to drive around without a cable connected to it. I’ll provide some links below to give a better overvierw over the setup. Oh and I should mention, this is a group university project of computer scientists, not electronic engineers. Furthermore you might wonder if it wouldn’t be easier to to everything with the Pi, and yes it would be, this is just what we were provided with. Our plan is that everything will eventually communicate via ROS and MQTT, which partly works already (controlling laptop, WiFi shield on cam, Pi).

Sphero RVR: Phone Controlled & Programmable Robot Car | RVR from Sphero
Ultrasonic sensorsetup looks somewhat like this (except only one sensor and the Pi isn’t connected to the RVR, the camera is): Ultrasonic RVR · Sphero Public SDK
Sensor hub (Don’t believe / hope it is a factor here): DockerPi Sensor Hub Development Board SKU: EP-0106 - 52Pi Wiki

Any help/clue would be greatly appreciated! :slight_smile:

Hi, you mentioned you have a series resistor between the OpenMV Cam and the Pi. This creates a voltage divider which will prevent the pin from going to low when the pi pulls it down.

You should just directly connect the GPIO pin between the Pi and the OpenMV Cam with no series resistor. As long as the OpenMV Cam doesn’t make the pin an output then there will be no issue.

Thank you for your reply, I’ll try that. I was just a bit worried about the GPIO of both devices as this project has already claimed a Pi 3B (the GPIO doesn’t work anymore). I’ve already configured the Pi so that it configures the pin in question as output on boot. Is there a defined state the pin on the OpenMV cam will have on boot? Also, with your mentioned solution, should I keep my added pulldown resistor or is there an internal one on the cam that will do the trick and I can remove that as well?

Thanks again :slight_smile:

The GPIO pins are all inputs on boot. You can add a pulldown on the camera GPIO pin during the pyb.Pin() constructor. See the API.

Thank you for the help, it’s working now and the circuitry is simpler than before. :slight_smile: