Distance sensor not working, I2C port

@fzahmed81, can you tell us what exactly do you want to do?

If you want to initialize an object of a device we already have in Python (the distance sensor, color sensor, etc and I presume it must be the distance sensor) you can then just instantiate the appropriate objects by reading the documentation (like check the above posts about it).

But if you want to support a different I2C device that we haven’t provided support for, then I highly recommend you to use our I2C implementation. It can be found here: https://github.com/DexterInd/RFR_Tools/blob/master/miscellaneous/di_i2c.py

Anyhow, I’m going to assume you’re strictly referring to the distance sensor, in which case, if you want to use it on the I2C bus, then you’d have to instantiate this way:

from di_sensors.easy_distance_sensor import EasyDistanceSensor

ds = EasyDistanceSensor()
# or
ds = EasyDistanceSensor(port = "I2C")

The 2nd way of instantiating the distance sensor object is pointless, but it shows you how you can change the bus for the distance sensor. In this case, it resorts, by default, to using the I2C bus.

Hope this makes sense to you.

Thank you!

I am still not able to get distance sensor working. Enabled the I2C port but no data is transfered.

On DexterOS 2 and up, you shouldn’t have to enable the port.
Can you share the code you’re using?

You can also consider moving to DexterOS 2.3.0 : https://www.dexterindustries.com/dexteros/update-dexteros/

updated Dexter OS to 2.3 but distance sensor not working57%20PM

In your scenario, the distance sensor has to be connected to the GoPiGo’s I2C port. You can check the markings on the board itself. And the code you’re showing us is looking good - it’s just that error looks as if the sensor is not connected.

Maybe you can show us a photo of how the distance sensor is connected to the GoPiGo. Could you do that?

Thank you!

rob1
servo, button and camera works. i have changed cables on the sensor too.