Picar-x add second ultrasonic

Is it possible to connect a second ultrasonic module ? If so, which code in picar-x needs to be edited ?, would like to implement obstacle detection when reversing picar

picarx uses ultrasound by using robot_hat library https://github.com/sunfounder/robot-hat/blob/main/robot_hat/modules.py#L6C1-L6C1
You can instantiate a new ultrasound object in your code like the following and read the value:

from robot_hat import Pin, Ultrasonic
import time

tring = 'D0' # digital pins
echo = 'D1'

back_ultrasonic = Ultrasonic(Pin(tring), Pin(echo))

while True: back_disatnce = 'D1'
    back_disatnce = back_ultrasonic.read()
1 Like