Problems with multiple distance sensors

Hi,
I have been using GoPiGo3 for 1 year and recently wanted to add another distance sensor to it. I have tried to use it with the existing sensor by doing
sensor1 = gpg.init_distance_sensor(‘I2C1’)
sensor2 =gpg.init_distance_sensor(‘AD1’)

However, only the sensor connected to ‘I2C1’ gets enabled and can be read. The sensor connected to any of the other ports does not get read (AD1, AD2, I2C2)

Can you please help
Thanks
Sandeep

Actually, the problem is going to be that both distance sensors have the same I2C address encoded into the sensor. The two I2C ports are actually in parallel, and rely on the sensors having a different I2C address.

(Matt’s reply tells how to run distance sensor on the AD1, AD2 ports - really cool.)

It looks like you are trying to use the sensor drivers through the easygopigo3 drivers. I would recommend using the distance sensor drivers directly. See example 1 and 2. If you initialize the sensor with ds = DistanceSensor(), it will default to the RPi HW I2C bus (the parameter defaults using bus = "RPI_1"). If you want to use GPG3 port AD1, set the bus name to GPG3_AD1 like this: ds = DistanceSensor(bus = "GPG3_AD1")

As cyclicalobsessive alluded to, you can’t use two of the same sensor (same I2C address) on the same I2C bus. However, GPG3 AD1 and AD2 ports can be used as I2C buses (bit-bang i.e. software controlled buses), so you can easily use two distance sensors at once.

If you are going to use two distance sensors on the same robot, I recommend using single-shot mode rather than continuous mode. It seems unlikely that they would conflict, but in continuous mode there’s a chance that the laser from one distance sensor will interfere with the other distance sensor. In the examples linked to above, follow example 1 for single shot, not example 2 for continuous. The only down-side to single shot mode is that it takes a little longer to poll the sensor. If you need ultimate polling speeds, you might want to use continuous mode, as the risk of laser conflicts is minimal.

1 Like

Thanks, Matt! Your suggestion makes sense, since I did notice that ‘I2C’ was hardcoded in the ‘easy…’ statement.
I did try di_sensors, but for some reason I could not get it to run, It kept complaining di_sensors.distance_sensor did not exist. Is there a way to reinstall the library?

Hi @bhutanister,

You can update it by running this:

curl -kL dexterindustries.com/update_sensors | bash -s -- --bypass-gui-installation

This should get it up and working for you!

Thank you!

Hi Matt, Robert,

Thanks! While I haven’t been able to update DI sensors yet, I have managed to get to the point where it accesses the DistanceSensor correctly. However it errors out with the message

…/dexter_i2c.py", line 35, in init

IOError: [Error 13] Permission denied

Thanks very much for your help

Sandeep

Please ignore the last email. I am able to get it working with your instructions but without any updates. Thanks very much for your help