Distance sensor not working, I2C port

I am getting an Remote I/O error for distance sensor. My sensor is attached to correct port, I2C and updated the DI software update on the Raspbian for Robots desktop. No luck. How do I check if the port is receiving/sending signal?

Can you show us the code you are trying to run and a photo of your setup?

Thank you!

robot

import time
import easygopigo3 as easy

gpg = easy.EasyGoPiGo3()

my_distance_sensor = gpg.init_distance_sensor()

while True:
    # Directly print the values of the sensor.
    print("Distance Sensor Reading (mm): " + str(my_distance_sensor.read_mm()))

i am getting a Remote I/O error 121

If you add

    time.sleep(1)

after your print in your while loop, does it still error?

(If you surround your code with a three backquotes ``` line before and after in future posts, the formatting will be preserved.)

added time.sleep(1), still same error

1 Like

Do you get the same error if you plug the distance sensor into the other I2C socket (far right)?

Have you tried unplug and re-plug the cable to the distance sensor?

Have you checked the battery voltage?

print("Batt:", gpg.volt() )

(I’m out of ideas, hopefully the Dexter Industries folks can help you more.)

So this method init_distance_sensor returns an object of EasyDistanceSensor class, which gets to be thread-safe by default. And this latter one inherits the DistanceSensor class, which isn’t thread safe and it’s also more complex to use (more bare-bones).

I’d suggest you initialize an EasyDistanceSensor object and try it out. If it doesn’t work, then initialize a DistanceSensor class and test it.

Here’s the class for the EasyDistanceSensor:
https://di-sensors.readthedocs.io/en/master/api-basic.html#di_sensors.easy_distance_sensor.EasyDistanceSensor

And here’s the one for the DistanceSensor:
https://di-sensors.readthedocs.io/en/master/api-advanced.html#di_sensors.distance_sensor.DistanceSensor

Lastly, here’s the tutorial on how to use the slightly more complex class for you:
https://di-sensors.readthedocs.io/en/master/examples/dist_sensor.html#single-mode

If you’re still in no luck, then give us an ls of /run/lock. This way:

ls -la /run/lock

Let me know how it goes.

Thank you!

I think i narrowed down the problem i2c port not working. tried sudo raspig-config advance settings but can’t find i2c initialization.33%20PM

I have updated my distance sensor using curl -kL dexterindustries.com/update_sensors | bash

sudo raspi-config
5. Interfacing options
P5. I2C

What does it say?

Also, you posted in the DexterOS forum, but this is in Raspbian, right?

enabled the I2C. still same error, Yes its on Raspbian

gopigo_error
How do i fix this error?
update my sensor using curl -kL dexterindustries.com/update_sensors | bash

What is returned when you run this command? ls /dev/i2c*

For debugging purposes, please use a different Grove cable (if you have a second one), and please connect it to the other I2C port of the GPG3. Then try again and see if there’s any difference.

If it’s still not working on the other I2C port with another cable (if you have one available), try connecting it to the Analog Digital 1 port of the GPG3, and running this test program:

#!/usr/bin/env python
#
# https://www.dexterindustries.com
#
# Copyright (c) 2017 Dexter Industries
# Released under the MIT license (http://choosealicense.com/licenses/mit/).
# For more information see https://github.com/DexterInd/DI_Sensors/blob/master/LICENSE.md
#
# Python example program for the Dexter Industries Distance Sensor

from __future__ import print_function
from __future__ import division

import time
from di_sensors.distance_sensor import DistanceSensor

print("Example program for reading a Dexter Industries Distance Sensor on the GPG3 AD1 port.")

# establish communication with the DistanceSensor
ds = DistanceSensor(bus = "GPG3_AD1")

# set the sensor in fast-polling-mode
ds.start_continuous()

while True:
    # read the distance in millimeters
    read_distance = ds.read_range_continuous()
    print("distance from object: {} mm".format(read_distance))

If the above test program fails, please share the Python errors as you did before.

ls /dev/i2c* gives error "no such directory
i dont have another groove cable, but when i connected to analog input , i got an errorgopigo_error-1

This indicates that I2C is not enabled. This would be the root cause of the sensor not working, for sure.

I did do raspi-config and enabled the i2C. is there’s something I am missing ?

If you are out of ideas, one thing to check is that your SD card has not gone read-only. There is a failure (“safety”) mode where the card will look fine during a session, but when you reboot, you discover that nothing was written to the card the prior session.

To test for this, touch a new file in your home folder -

  • e.g. > touch test_sd_card.txt
  • then reboot >sudo reboot

If the file is not there after the reboot, the card went into “safety” mode.

1 Like

How do i initialize I2C port on dexter 2.0 ?