Trying to get a distance sensor working on a gopigo2 via i2c

There doesn’t seem to be much information about connecting a distance sensor to a gopigo2 via the i2c.

Can someone tell me the easiest way to do this? I did run an i2cdetect -y 1 and it appears on 0x29. But what is the easiest way to read data from the sensor using Python? Is there a version a easygopigo3 somewhere for the gopigo2?

Hello @slaats

The distance sensor is indeed supported on the GoPiGo2. You have two choices:

  1. There’s easygopigo (although it’s not as well documented as easygopigo3, it does exist)
    Easygopigo and easygopigo3 offer similar APIs with a couple of differences. Mostly they are the same.
import easygopigo as easy
gpg = easy.EasyGoPiGo()
distance_sensor = easy.DistanceSensor(port="I2C",gpg=gpg)

  1. You can use the distance sensor code itself and use a lower level library with more functionality.

In either case you need to install the DI_Sensor library first. This is done for you if you have Raspbian for Robots and do a DI Software Update

Thanks for the information - very useful. I’ll do some more investigation and let you know if I have more questions. Thanks again.

Be aware that the init_“sensor” methods have not been ported to easygopigo.

If you look at ReadTheDocs you will not be able to just copy/paste the code. You will need to instantiate the distanceSensor class directly.

I need more explanation to how to use the distance sensor please.
I have been trying for two days and i just keep getting errors. Even when I try to run one of the examples in the DI_sensor directory, I get an error.
IOError: [Errno} Input/Output error

Hi @mamdou7.1,

I suppose that’s the same question as in this topic, so we’ll continue the discussion over there.

Thank you!