Distance Sensor not found

Hello!

I recently bought a GoPiGo3, and I have been trying to program my GoPiGo so that it can autonomously move without colliding with any obstacles.

I installed the GoPiGo3 libraries on my micro SD card since I did not buy my micro SD card from Dexter Industries - I have the Raspbian Jessie operating system on my Raspberry Pi 3B. I am able to use basic commands to control my GoPiGo3 like forward() and backward() after importing * from easygopigo3 and declaring an EasyGoPiGo3 object, but I have been having trouble with the distance sensor.

When I try to run my collision avoidance program, the line

distance_sensor = robot.init_distance_sensor()

causes

[Errno 2] No such file or directory
Traceback (most recent call last):
File “distance.py”, line 7, in
distance_sensor = robot.init_distance_sensor()
File “build/bdist.linux-armv7l/egg/easygopigo3.py”, line 811, in init_distance_sensor
File “build/bdist.linux-armv7l/egg/easygopigo3.py”, line 2428, in init
IOError: Distance Sensor not found

Also, when I try to run the easy_Distance_Sensor.py example in the /Dexter/GoPiGo3/Software/Python/Examples directory, I get

Traceback (most recent call last):
File “easy_Distance_Sensor.py”, line 36, in
my_distance_sensor = DistanceSensor(easy) # Distance_Sensor will be the Line Follower object.
NameError: name ‘DistanceSensor’ is not defined

I am new to the GoPiGo3, so any help would be much appreciated.

Thanks!

Hello @typhoonrg and welcome to GoPiGo3!
As you installed the libraries on your own Raspbian, you are simply missing these files too:

We just reorganised this part of our software and it’s entirely possible that our instructions don’t reflect the changes yet. I apologize for the lack of relevant instructions regarding the distance sensor.

Hello!

Thanks for the quick reply! I actually got those files as well earlier today. I went ahead and reinstalled it, and I am still getting the same errors.

In addition, when I try to run the DistanceSensorContinuous.py example from ~/Dexter/DI_Sensors/Python/Examples, I get

Example program for reading a Dexter Industries Distance Sensor on an I2C port.
Traceback (most recent call last):
File “DistanceSensorContinuous.py”, line 19, in
ds = distance_sensor.DistanceSensor()
File “build/bdist.linux-armv7l/egg/di_sensors/distance_sensor.py”, line 24, in init
File “build/bdist.linux-armv7l/egg/di_sensors/VL53L0X.py”, line 116, in init
File “build/bdist.linux-armv7l/egg/di_sensors/dexter_i2c.py”, line 35, in init
IOError: [Errno 2] No such file or directory

Thanks for your help.

Good sleuthing for alreayd having those files!

Before we go any further, can you confirm that this is the distance sensor that you’re using ? And on which port are you connecting it?

Also, from your last post, it indicates that the distance sensor library is not installed. Did you get the files by using the following command:
curl --silent https://raw.githubusercontent.com/DexterInd/Raspbian_For_Robots/master/upd_script/fetch_sensors.sh | bash

Yup, that is the distance sensor I am using. I am connecting the distance sensor to one of the two I2C ports. And yes, I used that command to get the files.

Thanks!

Hmm. It should have worked but obviously there’s a case we’re not catching.
Can you run the install manually?
cd ~/Dexter/DI_Sensors/Python
sudo rm -r build/
sudo python setup.py install

Oh, are you running python3 or 2 ?

Hello,

I am running Python 3. I ran the install manually (with sudo python3 instead), but I am still getting the errors.

Thanks.

Are you getting the error with python2?

It looks like smbus is only installed for Python2, at least on my development robot. Let me investigate this.

sudo apt-get install python-smbus python3-smbus

After running that command, it said

python-smbus is already the newest version.
python3-smbus is already the newest version.

Thanks.

So that’s good news at least. It comes with Raspbian, that explains why we don’t install it in our scripts.

With the distance sensor connected, what do you see if you type sudo i2cdetect -y 1 ?

I am getting

Error: Could not open file /dev/i2c-1' or/dev/i2c/1’: No such file or directory

Thanks for your help.

Hmm (again). Is I2C enabled?
sudo raspi-config
Advanced Options
I2C

Oh, it looks like I forgot to enable I2C under interfacing options!

The example under DI_Sensors seems to be working now. I’ll let you know if the distance sensor is not working in my other programs, but I think that fixed it! :grinning:

Thank you so much for your help! I really appreciate it.

1 Like

Yeah!
Our scripts should have done it for you so I’ll make a note that I2C is not automatically enabled. Sorry we gave you so much trouble but it looks like you’re on your way to success now :slight_smile:

Cleo

1 Like

I am running into the issue where the DistanceSensor is not working.
I am using Python 3.

import easygopigo3 as easy

gpg = easy.EasyGoPiGo3()
ds = easy.init_distance_sensor()
ds.read() —> This call just hangs in python3, in python2 it throws an error.

I tried enabling i2c and that did not work…
Also the Servo does not seem to work

Any help pointing me in the right direction would be appreciated.

Hello @mukundan.agaram,

Could you try with sudo? We’re running into an issue that requires sudo, and will be adressed pretty soon.
Please let me know if using sudo helps you.

Cleo

I did try it with sudo. I did
sudo i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: – -- – -- – 08 – -- – -- – -- –
10: – -- – -- – -- – -- – -- – -- – -- – --
20: – -- – -- – -- – -- – 29 – -- – -- – --
30: – -- – -- – -- – -- – -- – -- – -- – --
40: – -- – -- – -- – -- – -- – -- – -- – --
50: – -- – -- – -- – -- – -- – -- – -- – --
60: – -- – -- – -- – -- – -- – -- – -- – --
70: – -- – -- – -- – --

Then I did
sudo raspi-config
and enabled I2C as described above

after that I sudo python3

import easygopigo3 as easy
Loading library without distance sensor

gpg = easy.EasyGoPiGo3()
ds = gpg.init_distance_sensor()
ds.read()
^C^C0

read() above hangs and I have to kill it with ^C

Hello @mukundan.agaram

I’m sorry for the delay. I had to check a couple of things.
Can you try the following code:

from di_sensors import distance_sensor
d = distance_sensor.DistanceSensor()
d.read_range_single()

This should let us know if the issue is with the distance sensor, or with easygopigo3

Thank you,
Cleo

I tried it. It cannot find a module named di_sensors

ah, now we’re getting somewhere :slight_smile: Also, let me apologize. I missed that you were using your own SD card, even though you said it right away in the first post. That should have been my first clue.

You need to install DI_Sensors (which our scripts should do in theory but I don’t think it does right now - thanks for the reminder)

sudo curl https://raw.githubusercontent.com/DexterInd/Raspbian_For_Robots/master/upd_script/fetch_sensors.sh | bash 

will install the DI_Sensors library for you.