Skip to content

New Install: Not able to initialize distance sensor #376

Description

@slowrunner

I have mr-gopigo3 1.0.3 installed, and I cannot initialize my DI distance_sensor, and don't know what to do to diagnose the problem.

If I am understanding the code correct, the default address in the software seems to be 0x2a but I see the device at 0x29
but I tried setting address to 0x29 - no change.

I tried setting /dev/i2c-1 to 666, and I tried adding ubuntu to group i2c.

(gopigo3) ubuntu@U26LDave:~/LyricalDave/systests/distance_sensor$ groups
ubuntu adm dialout cdrom sudo audio video plugdev games users netdev ollama render input gpio spi i2c

The sensor is showing up on the I2C bus:

(gopigo3) ubuntu@U26LDave:~/LyricalDave/systests/distance_sensor$ 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: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         

My program:

#!/usr/bin/env python3

# FILE: readDistOnce.py

# PURPOSE:  Read Distance Sensor Once to check I2C bus operation

import easygopigo3

def main():
	# Using plib version of easygopigo3 to get noinit feature
	egpg = easygopigo3.EasyGoPiGo3(use_mutex=True)
	# egpg.tp = tiltpan.TiltPan(egpg)
	# egpg.ds = egpg.init_distance_sensor("RPI_1")  # HW I2C
	egpg.ds = egpg.init_distance_sensor()  # HW I2C
	dist = egpg.ds.read_mm()
	print(f"Distance Sensor Returned: {dist} mm")


if __name__ == '__main__': main()

Execution:

(gopigo3) ubuntu@U26LDave:~/LyricalDave/systests/distance_sensor$ ./readDistOnce.py 
Traceback (most recent call last):
  File "/home/ubuntu/LyricalDave/systests/distance_sensor/./readDistOnce.py", line 19, in <module>
    if __name__ == '__main__': main()
                               ~~~~^^
  File "/home/ubuntu/LyricalDave/systests/distance_sensor/./readDistOnce.py", line 15, in main
    dist = egpg.ds.read_mm()
           ^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'read_mm'
(gopigo3) ubuntu@U26LDave:~/LyricalDave/systests/distance_sensor$ python3
Python 3.14.4 (main, Apr  8 2026, 04:02:31) [GCC 15.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from gopigo3 import EasyGoPiGo3
>>> egpg=EasyGoPiGo3()


The init_distance_sensor() method exists:

>>> print(dir(EasyGoPiGo3))
['ENCODER_TICKS_PER_ROTATION', 'GROVE_1', 'GROVE_1_1', 'GROVE_1_2', 'GROVE_2', 'GROVE_2_1', 'GROVE_2_2', 'GROVE_HIGH', 'GROVE_I2C_LENGTH_LIMIT', 'GROVE_INPUT_ANALOG', 'GROVE_INPUT_ANALOG_PULLDOWN', 'GROVE_INPUT_ANALOG_PULLUP', 'GROVE_INPUT_DIGITAL', 'GROVE_INPUT_DIGITAL_PULLDOWN', 'GROVE_INPUT_DIGITAL_PULLUP', 'GROVE_LOW', 'GROVE_OUTPUT_DIGITAL', 'GROVE_OUTPUT_PWM', 'GROVE_STATE', 'GROVE_TYPE', 'GroveI2CInBytes', 'GroveType', 'LED_BLINKER_LEFT', 'LED_BLINKER_RIGHT', 'LED_EYE_LEFT', 'LED_EYE_RIGHT', 'LED_LEFT_BLINKER', 'LED_LEFT_EYE', 'LED_RIGHT_BLINKER', 'LED_RIGHT_EYE', 'LED_WIFI', 'MOTOR_FLOAT', 'MOTOR_GEAR_RATIO', 'MOTOR_LEFT', 'MOTOR_RIGHT', 'MOTOR_TICKS_PER_DEGREE', 'SERVO_1', 'SERVO_2', 'SPI_MESSAGE_TYPE', 'WHEEL_BASE_CIRCUMFERENCE', 'WHEEL_BASE_WIDTH', 'WHEEL_CIRCUMFERENCE', 'WHEEL_DIAMETER', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__firstlineno__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__static_attributes__', '__str__', '__subclasshook__', '__weakref__', '_check_serial_number_for_16_ticks', 'backward', 'blinker_off', 'blinker_on', 'close_eyes', 'close_left_eye', 'close_right_eye', 'drive_cm', 'drive_degrees', 'drive_inches', 'forward', 'get_board', 'get_grove_analog', 'get_grove_state', 'get_grove_value', 'get_grove_voltage', 'get_id', 'get_manufacturer', 'get_motor_encoder', 'get_motor_status', 'get_speed', 'get_version_firmware', 'get_version_hardware', 'get_voltage_5v', 'get_voltage_battery', 'grove_i2c_start', 'grove_i2c_transfer', 'init_button_sensor', 'init_buzzer', 'init_dht_sensor', 'init_distance_sensor', 'init_imu_sensor', 'init_led', 'init_light_color_sensor', 'init_light_sensor', 'init_line_follower', 'init_loudness_sensor', 'init_motion_sensor', 'init_remote', 'init_servo', 'init_sound_sensor', 'init_ultrasonic_sensor', 'led_off', 'led_on', 'left', 'load_robot_constants', 'offset_motor_encoder', 'open_eyes', 'open_left_eye', 'open_right_eye', 'orbit', 'read_encoders', 'read_encoders_average', 'reset_all', 'reset_encoders', 'reset_motor_encoder', 'reset_speed', 'right', 'save_robot_constants', 'set_eye_color', 'set_grove_mode', 'set_grove_pwm_duty', 'set_grove_pwm_frequency', 'set_grove_state', 'set_grove_type', 'set_led', 'set_left_eye_color', 'set_motor_dps', 'set_motor_limits', 'set_motor_position', 'set_motor_power', 'set_right_eye_color', 'set_robot_constants', 'set_servo', 'set_speed', 'spi_read_16', 'spi_read_32', 'spi_read_8', 'spi_transfer_array', 'spi_write_32', 'spin_left', 'spin_right', 'steer', 'stop', 'target_reached', 'turn_degrees', 'volt']

The init_distance_sensor method does not report any error:
>>> ds=egpg.init_distance_sensor()

ds does not contain read_mm():

>>> print(dir(ds))
['__bool__', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
>>> 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions