Error in Ultrasonic Distance Sensor code – The UDS is Pimoroni 4TR-ULTRABKT
I have made a robot with a Raspberry Pi 3B, the Cam EduKit, a small I2C Breakout Garden and using gpiozero. I am now attaching the UDS mentioned above.
I am doing the FutureLearn course: Robotics with Raspberry Pi: build and program your first robot buggy.
I have an error which I don’t know how to solve. When I purchased my UDS, it said in the instructions that it used pin 04 for both the trig and the echo.
I only attached one jumper from pin 04 on the breakout garden, which my UDS sits on, to pin 04 on top of my motor controller board.
I put these statements in my program:
trig = OutputDevice(4)
echo = InputDevice(4)
but the code is not working. Here is the error message:
gpiozero.exc.GPIOPinInUse: pin 4 is already in use by <gpio.zero.OutputDevice object on GPIO4, active_high = True, is_active = False>
Not sure how I can remedy this. Here is a photo of my set-up.
The full code is in the file attached: Ruthy_uds-detect-1_script.py
Can’t see how to attach file so I’ll copy and paste into another post.