[solved] Distance Sensor not working for me

Hi
Looked thru the other thread and made sure I’d installed the sensors package - rebooted - I2c is showing the 08 and 29 in the table
trying

import time
import easygopigo3 as easy

# Create an instance of the Distance Sensor class.
my_distance_sensor = easy.DistanceSensor()     # Distance_Sensor will be the Line Follower object.

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

getting

pi@gopigo3:~/GoPiGo3-master/Software/Python $ python sw.py 
Traceback (most recent call last):
  File "sw.py", line 5, in <module>
    my_distance_sensor = easy.DistanceSensor()     # Distance_Sensor will be the Line Follower object.
  File "/home/pi/GoPiGo3-master/Software/Python/easygopigo3.py", line 2609, in __init__
    Sensor.__init__(self, port, "OUTPUT", gpg)
  File "/home/pi/GoPiGo3-master/Software/Python/easygopigo3.py", line 965, in __init__
    raise TypeError("Use an EasyGoPiGo3 object for the gpg parameter.")
TypeError: Use an EasyGoPiGo3 object for the gpg parameter.

I went down this trobleshooting path as it was not showing up in Scratch sensors

Simon

This is plain Raspbian without any install - just running the sw.py in the main folder

More info
Ran

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

got this

pi@gopigo3:~/GoPiGo3-master/Software/Python $ python cy.py 
pi@gopigo3:~/GoPiGo3-master/Software/Python $ python cy.py 
8190
pi@gopigo3:~/GoPiGo3-master/Software/Python $ python cy.py 
790
pi@gopigo3:~/GoPiGo3-master/Software/Python $ python cy.py 
269
pi@gopigo3:~/GoPiGo3-master/Software/Python $ python cy.py 
203
pi@gopigo3:~/GoPiGo3-master/Software/Python $ python cy.py 
995

so its physically working - just something not linking right inside of easypigo3 methinks
Simon

There are two approaches to instantiating a distance sensor. I showed both in the code below.
You can also go “hard code” and use gopigo3 and di_sensors directly

I’m seeing there seems to be an issue with readthedocs. Will take a closer look

Ok…

I’m just wanting it to work in Scratch (which is using the easypigo3 module methinks???)

So - should I just try and hack into my copy to get it going or is there something coming from you?

Simon

Nothing coming from us. You need to do a slight modification to your program (and we will fix our ReadTheDocs.

Also, the distance sensor is already supported in Scratch.

Are you seeing an issue with Scratch that we don’t know about?

PS. looks like the forum is pulling the whole file from Github and not even respect the indentation. Sigh…

Yes :slight_smile:

The distance sensor is not returning any values in Scratch - I only went down plain Python route to help troubleshoot :slight_smile:

running your hander direct in terminal is giving a big clue to us :slight_smile:

pi@gopigo3:~/GoPiGo3/Software/Scratch $ sudo python GoPiGo3Scratch.py
GoPiGo3 Detected and Connected
No distance sensor detected
Starting GoPiGo3 Scratch Controller

ok that’s indeed a clue. And as it’s your own install, I have to conclude that the distance sensor library has not been installed system-wide

You can go into the DI_sensors/python folder and run
sudo python setup.py install

and where would that folder be inside?

I did the curl install referenced by the other thread BTW - shouldn’t that have installed it system wide?

It should be in /home/pi/Dexter/DI_Sensors/Python

and yes the curl program is supposed to install it system-wide.

So it looks like something else then. How did you install the GoPiGo3 libraries?

I didn’t I just copied the .py files into same folder as GoPiGo3Scratch.py

pi@gopigo3:~/GoPiGo3/Software/Scratch $ ls
DI_piGPIOExtension.js  GoPiGo3Scratch2.desktop  scratch.pyc
easygopigo3.py         gopigo3scratch2.sh       websocket_server.py
easygopigo3.pyc        GoPiGo3Scratch.py        websocket_server.pyc
Examples               GoPiGo3Scratch.pyc       wstosgh.py
gopigo3.py             GoPiGo3Scratch.py.save
gopigo3.pyc            scratch.py

IAs this is working

https://forum.dexterindustries.com/t/distance-sensor-not-working-for-me/3603/3?u=simplecy

works doesn’t that mean the sensor is installed OK?

Can I remove some try/excepts somewhere and see if we can see any raw errors?

how long ago did you get that easygopigo3 file?
We changed DI_Sensors at one point not that too long ago. If your easygopigo3 is not in sync, it would give us this current issue.

Please compare to

Will try with updated code

Fix in Scratch is upcoming.

Thank you for bringing it up!
Cleo

This topic was automatically closed after 26 hours. New replies are no longer allowed.