5.3. API - Library - Sensors

5.3.1. LightSensor

class easysensors.LightSensor(port='AD1', gpg=None, use_mutex=False)[source]

Bases: easysensors.AnalogSensor

Class for the old Grove Light Sensor.

This class derives from AnalogSensor class, so all of its attributes and methods are inherited. For creating a LightSensor object we need to call init_light_sensor() method like in the following examples.

# create an EasyGoPiGo3 object
gpg3_obj = EasyGoPiGo3()

# and now instantiate a LightSensor object through the gpg3_obj object
light_sensor = gpg3_obj.init_light_sensor()

# do the usual stuff, like read the data of the sensor
value = light_sensor.read()
value_percentage = light_sensor.percent_read()

# take a look at AnalogSensor class for more methods and attributes

Or if we need to specify the port we want to use, we might do it like in the following example.

# create an EasyGoPiGo3 object
gpg3_obj = EasyGoPiGo3()

# variable for holding the port to which we have the Light Sensor connected to
port = "AD2"

light_sensor = gpg3_obj.init_light_sensor(port)

# read the sensor the same way as in the previous example

See also

For more sensors, please see our Dexter Industries shop.

__init__(port='AD1', gpg=None, use_mutex=False)[source]

Constructor for initializing a LightSensor object for the Grove Light Sensor.

Parameters
  • "AD1" (str port =) – Port to which we have the Grove Light Sensor connected to.

  • None (easygopigo3.EasyGoPiGo3 gpg =) – EasyGoPiGo3 object used for instantiating a LightSensor object.

  • False (bool use_mutex =) – When using multiple threads/processes that access the same resource/device, mutexes should be enabled.

Raises

TypeError – If the gpg parameter is not a EasyGoPiGo3 object.

The port parameter can take the following values:

  • "AD1" - general purpose input/output port.

  • "AD2" - general purpose input/output port.

The ports’ locations can be seen in the following graphical representation: Hardware Ports.

5.3.2. SoundSensor

class easysensors.SoundSensor(port='AD1', gpg=None, use_mutex=False)[source]

Bases: easysensors.AnalogSensor

Class for the Grove Sound Sensor.

This class derives from AnalogSensor class, so all of its attributes and methods are inherited. For creating a SoundSensor object we need to call init_sound_sensor() method like in the following examples.

# create an EasyGoPiGo3 object
gpg3_obj = EasyGoPiGo3()

# and now instantiate a SoundSensor object through the gpg3_obj object
sound_sensor = gpg3_obj.init_sound_sensor()

# do the usual stuff, like read the data of the sensor
value = sound_sensor.read()
value_percentage = sound_sensor.percent_read()

# take a look at AnalogSensor class for more methods and attributes
Or if we need to specify the port we want to use, we might do it like in the following example.
# create an EasyGoPiGo3 object
gpg3_obj = EasyGoPiGo3()

# variable for holding the port to which we have the sound sensor connected to
port = "AD1"

sound_sensor = gpg3_obj.init_sound_sensor(port)

# read the sensor the same way as in the previous example

See also

For more sensors, please see our Dexter Industries shop.

__init__(port='AD1', gpg=None, use_mutex=False)[source]

Constructor for initializing a SoundSensor object for the Grove Sound Sensor.

Parameters
  • "AD1" (str port =) – Port to which we have the Grove Sound Sensor connected to.

  • None (easygopigo3.EasyGoPiGo3 gpg =) – EasyGoPiGo3 object used for instantiating a SoundSensor object.

  • False (bool use_mutex =) – When using multiple threads/processes that access the same resource/device, mutexes should be enabled.

Raises

TypeError – If the gpg parameter is not a EasyGoPiGo3 object.

The port parameter can take the following values:

  • "AD1" - general purpose input/output port.

  • "AD2" - general purpose input/output port.

The ports’ locations can be seen in the following graphical representation: Hardware Ports.

5.3.3. LoudnessSensor

class easysensors.LoudnessSensor(port='AD1', gpg=None, use_mutex=False)[source]

Bases: easysensors.AnalogSensor

Class for the Grove Loudness Sensor.

This class derives from AnalogSensor class, so all of their attributes and methods are inherited. For creating a LoudnessSensor object we need to call init_loudness_sensor() method like in the following examples.

# create an EasyGoPiGo3 object
gpg3_obj = EasyGoPiGo3()

# and now instantiate a LoudnessSensor object through the gpg3_obj object
loudness_sensor = gpg3_obj.init_loudness_sensor()

# do the usual stuff, like read the data of the sensor
value = loudness_sensor.read()
value_percentage = loudness_sensor.percent_read()

# take a look at AnalogSensor class and Sensor class for more methods and attributes

Or if we need to specify the port we want to use, we might do it like in the following example.

# create an EasyGoPiGo3 object
gpg3_obj = EasyGoPiGo3()

# variable for holding the port to which we have the sound sensor connected to
port = "AD1"

loudness_sensor = gpg3_obj.init_loudness_sensor(port)

# read the sensor the same way as in the previous example

See also

For more sensors, please see our Dexter Industries shop.

__init__(port='AD1', gpg=None, use_mutex=False)[source]

Constructor for initializing a LoudnessSensor object for the Grove Loudness Sensor.

Parameters
  • "AD1" (str port =) – Port to which we have the Grove Loudness Sensor connected to.

  • None (easygopigo3.EasyGoPiGo3 gpg =) – EasyGoPiGo3 object used for instantiating a LoudnessSensor object.

  • False (bool use_mutex =) – When using multiple threads/processes that access the same resource/device, mutexes should be enabled.

Raises

TypeError – If the gpg parameter is not a EasyGoPiGo3 object.

The port parameter can take the following values:

  • "AD1" - general purpose input/output port.

  • "AD2" - general purpose input/output port.

The ports’ locations can be seen in the following graphical representation: Hardware Ports.

5.3.4. UltrasonicSensor

class easysensors.UltraSonicSensor(port='AD1', gpg=None, use_mutex=False)[source]

Bases: easysensors.AnalogSensor

Class for the Grove Ultrasonic Sensor.

This class derives from AnalogSensor class, so all of its attributes and methods are inherited. For creating a UltraSonicSensor object we need to call init_ultrasonic_sensor() method like in the following examples.

# create an EasyGoPiGo3 object
gpg3_obj = EasyGoPiGo3()

# and now instantiate a UltraSonicSensor object through the gpg3_obj object
ultrasonic_sensor = gpg3_obj.init_ultrasonic_sensor()

# do the usual stuff, like read the distance the sensor is measuring
distance_cm = ultrasonic_sensor.read()
distance_inches = ultrasonic_sensor.read_inches()

# take a look at AnalogSensor class for more methods and attributes

Or if we need to specify the port we want to use, we might do it like in the following example.

# create an EasyGoPiGo3 object
gpg3_obj = EasyGoPiGo3()

# variable for holding the port to which we have the ultrasonic sensor connected to
port = "AD1"

ultrasonic_sensor = gpg3_obj.init_ultrasonic_sensor(port)

# read the sensor's measured distance as in the previous example

See also

For more sensors, please see our Dexter Industries shop.

__init__(port='AD1', gpg=None, use_mutex=False)[source]

Constructor for initializing a UltraSonicSensor object for the Grove Ultrasonic Sensor.

Parameters
  • "AD1" (str port =) – Port to which we have the Grove Ultrasonic Sensor connected to.

  • None (easygopigo3.EasyGoPiGo3 gpg =) – EasyGoPiGo3 object used for instantiating a UltraSonicSensor object.

  • False (bool use_mutex =) – When using multiple threads/processes that access the same resource/device, mutexes should be enabled.

Raises

TypeError – If the gpg parameter is not a EasyGoPiGo3 object.

The port parameter can take the following values:

  • "AD1" - general purpose input/output port.

  • "AD2" - general purpose input/output port.

The ports’ locations can be seen in the following graphical representation: Hardware Ports.

is_too_close()[source]

Checks whether the Grove Ultrasonic Sensor measures a distance that’s too close to a target than what we consider a safe distance.

Returns

Whether the Grove Ultrasonic Sensor is too close from a target.

Return type

bool

Raises

gopigo3.SensorError – If a sensor is not yet configured when trying to read it.

A safe distance can be set with the set_safe_distance() method.

Note

The default safe distance is set at 50 cm.

set_safe_distance(dist)[source]

Sets a safe distance for the Grove Ultrasonic Sensor.

Parameters

dist (int) – Minimum distance from a target that we can call a safe distance.

To check whether the robot is too close from a target, please check the is_too_close() method.

Note

The default safe distance is set at 50 cm.

get_safe_distance()[source]

Gets what we call the safe distance for the Grove Ultrasonic Sensor.

Returns

The minimum distance from a target that can be considered a safe distance.

Return type

int

Note

The default safe distance is set at 50 cm.

read_mm()[source]

Measures the distance from a target in millimeters.

Returns

The distance from a target in millimeters.

Return type

int

Raises
  • gopigo3.ValueError – If trying to read an invalid value.

  • Exception – If any other error occurs.

Important

  • This method can read distances between 15-4300 millimeters.

  • This method will read the data for 3 times and it’ll discard anything that’s smaller than 15 millimeters and bigger than 4300 millimeters.

  • If data is discarded 5 times (due to a communication error with the sensor), then the method returns 5010.

read()[source]

Measures the distance from a target in centimeters.

Returns

The distance from a target in centimeters.

Return type

int

Important

  • This method can read distances between 2-430 centimeters.

  • If data is discarded 5 times (due to a communication error with the sensor), then the method returns 501.

read_inches()[source]

Measures the distance from a target in inches.

Returns

The distance from a target in inches.

Return type

float (one decimal)

Important

  • This method can read distances of up to 169 inches.

  • If data is discarded 5 times (due to a communication error with the sensor), then the method returns 501.

5.3.5. Buzzer

class easysensors.Buzzer(port='AD1', gpg=None, use_mutex=False)[source]

Bases: easysensors.AnalogSensor

Class for the Grove Buzzer.

This class derives from AnalogSensor class, so all of its attributes and methods are inherited. For creating a Buzzer object we need to call init_buzzer() method like in the following examples.

# create an EasyGoPiGo3 object
gpg3_obj = EasyGoPiGo3()

# and now instantiate a UltraSonicSensor object through the gpg3_obj object
buzzer = gpg3_obj.init_buzzer()

# turn on and off the buzzer
buzzer.sound_on()
sleep(1)
buzzer.sound_off()

# take a look at AnalogSensor class for more methods and attributes

If we need to specify the port we want to use, we might do it like in the following example.

# create an EasyGoPiGo3 object
gpg3_obj = EasyGoPiGo3()

# variable for holding the port to which we have the ultrasonic sensor connected to
port = "AD1"

buzzer = gpg3_obj.init_buzzer(port)

See also

For more sensors, please see our Dexter Industries shop.

scale = {'A3': 220, 'A3#': 233, 'A4': 440, 'A4#': 466, 'B3': 247, 'B4': 494, 'C4': 261, 'C4#': 277, 'C5': 523, 'C5#': 554, 'D4': 293, 'D4#': 311, 'D5': 587, 'D5#': 622, 'E4': 329, 'E5': 659, 'F4': 349, 'F4#': 370, 'F5': 698, 'F5#': 740, 'G4': 392, 'G4#': 415, 'G5': 784, 'G5#': 831}

Dictionary of frequencies for each musical note. For instance, scale["A3"] instruction is equal to 220 Hz (that’s the A3 musical note’s frequency). This dictionary is useful when we want to make the buzzer ring at certain frequencies (aka musical notes).

__init__(port='AD1', gpg=None, use_mutex=False)[source]

Constructor for initializing a Buzzer object for the Grove Buzzer.

Parameters
  • "AD1" (str port =) – Port to which we have the Grove Buzzer connected to.

  • None (easygopigo3.EasyGoPiGo3 gpg =) – EasyGoPiGo3 object used for instantiating a Buzzer object.

  • False (bool use_mutex =) – When using multiple threads/processes that access the same resource/device, mutexes should be enabled.

Variables
  • 50 (int power =) – Duty cycle of the signal that’s put on the buzzer.

  • 329 (int freq =) – Frequency of the signal that’s put on the buzzer. 329Hz is synonymous to E4 musical note. See scale for more musical notes.

Raises

TypeError – If the gpg parameter is not a EasyGoPiGo3 object.

The port parameter can take the following values:

  • "AD1" - general purpose input/output port.

  • "AD2" - general purpose input/output port.

The ports’ locations can be seen in the following graphical representation: Hardware Ports.

sound(freq)[source]

Sets a musical note for the Grove Buzzer.

Parameters

freq (int) – The frequency of the signal that’s put on the Grove Buzzer.

For a list of musical notes, please see scale. See this example script on how to play musical notes.

# initialize all the required objects and connect the sensor to the GoPiGo3

musical_notes = buzzer.scale
notes_i_want_to_play = {"F4#", "F4#", "C5#", "B3", "B3", "B3"}
wait_time = 1.0

for note in notes_i_want_to_play:
   buzzer.sound(musical_notes[note])
   sleep(wait_time)

   # enjoy the musical notes
sound_off()[source]

Turns off the Grove Buzzer.

sound_on()[source]

Turns on the Grove Buzzer at the set frequency.

For changing the frequency, please check the sound() method.

5.3.6. Led

class easysensors.Led(port='AD1', gpg=None, use_mutex=False)[source]

Bases: easysensors.AnalogSensor

Class for the Grove LED.

With this class the following things can be done:

  • Turn ON/OFF an LED.

  • Set a level of brightness for the LED.

  • Check if an LED is turned ON or OFF.

This class derives from AnalogSensor class, so all of its attributes and methods are inherited. For creating a Led object we need to call init_led() method like in the following examples.

# create an EasyGoPiGo3 object
gpg3_obj = EasyGoPiGo3()

# and now instantiate a Led object through the gpg3_obj object
led = gpg3_obj.init_led()

# turn on and off the buzzer
led.light_max()
sleep(1)
led.light_off()

# take a look at AnalogSensor class for more methods and attributes

If we need to specify the port we want to use, we might do it like in the following example.

# create an EasyGoPiGo3 object
gpg3_obj = EasyGoPiGo3()

# variable for holding the port to which we have the led connected to
port = "AD1"

led = gpg3_obj.init_led(port)

# call some Led-specific methods

See also

For more sensors, please see our Dexter Industries shop.

__init__(port='AD1', gpg=None, use_mutex=False)[source]

Constructor for initializing a Led object for the Grove LED.

Parameters
  • "AD1" (str port =) – Port to which we have the Grove LED connected to.

  • None (easygopigo3.EasyGoPiGo3 gpg =) – EasyGoPiGo3 object used for instantiating a Led object.

  • False (bool use_mutex =) – When using multiple threads/processes that access the same resource/device, mutexes should be enabled.

Raises

TypeError – If the gpg parameter is not a EasyGoPiGo3 object.

The port parameter can take the following values:

  • "AD1" - general purpose input/output port.

  • "AD2" - general purpose input/output port.

The ports’ locations can be seen in the following graphical representation: Hardware Ports.

light_on(power)[source]

Sets the duty cycle for the Grove LED.

Parameters

power (int) – Number between 0 and 100 that represents the duty cycle of PWM signal.

light_max()[source]

Turns on the Grove LED at full power.

light_off()[source]

Turns off the Grove LED.

is_on()[source]

Checks if the Grove LED is turned on.

Returns

If the Grove LED is on.

Return type

bool

is_off()[source]

Checks if the Grove LED is turned off.

Returns

If the Grove LED is off.

Return type

bool

5.3.7. MotionSensor

class easysensors.MotionSensor(port='AD1', gpg=None, use_mutex=False)[source]

Bases: easysensors.DigitalSensor

Class for the Grove Motion Sensor.

This class derives from Sensor (check for throwable exceptions) and DigitalSensor classes, so all attributes and methods are inherited. For creating a MotionSensor object we need to call init_motion_sensor() method like in the following examples.

# create an EasyGoPiGo3 object
gpg3_obj = EasyGoPiGo3()

# and now instantiate a Motion Sensor object through the gpg3_obj object on default port AD1
motion_sensor = gpg3_obj.init_motion_sensor()

while True:
    if motion_sensor.motion_detected():
        print("motion detected")
    else:
        print("no motion")

# take a look at DigitalSensor & Sensor class for more methods and attributes

If we need to specify the port we want to use, we might do it like in the following example.

# create an EasyGoPiGo3 object
gpg3_obj = EasyGoPiGo3()

# variable for holding the port to which we have the motion sensor connected to
port = "AD2"

motion_sensor = gpg3_obj.init_motion_sensor(port)

See also

For more sensors, please see our Dexter Industries shop.

__init__(port='AD1', gpg=None, use_mutex=False)[source]

Constructor for initializing a MotionSensor object for the Grove Motion Sensor.

Parameters
  • "AD1" (str port =) – Port to which we have the Grove Motion Sensor connected to.

  • None (easygopigo3.EasyGoPiGo3 gpg =) – EasyGoPiGo3 object used for instantiating a MotionSensor object.

  • False (bool use_mutex =) – When using multiple threads/processes that access the same resource/device, mutexes should be enabled.

Raises

TypeError – If the gpg parameter is not a EasyGoPiGo3 object.

The port parameter can take the following values:

  • "AD1" - general purpose input/output port.

  • "AD2" - general purpose input/output port.

The ports’ locations can be seen in the following graphical representation: Hardware Ports.

motion_detected(port='AD1')[source]

Checks if the Grove Motion Sensor detects a motion.

Returns

True or False, if the Grove Motion Sensor detects a motion or not.

Return type

bool

5.3.8. ButtonSensor

class easysensors.ButtonSensor(port='AD1', gpg=None, use_mutex=False)[source]

Bases: easysensors.DigitalSensor

Class for the Grove Button.

This class derives from Sensor (check for throwable exceptions) and DigitalSensor classes, so all attributes and methods are inherited. For creating a ButtonSensor object we need to call init_button_sensor() method like in the following examples.

# create an EasyGoPiGo3 object
gpg3_obj = EasyGoPiGo3()

# and now instantiate a Button object through the gpg3_obj object
button = gpg3_obj.init_button_sensor()

while True:
    if button.is_button_pressed():
        print("button pressed")
    else:
        print("button released")

# take a look at DigitalSensor & Sensor class for more methods and attributes

If we need to specify the port we want to use, we might do it like in the following example.

# create an EasyGoPiGo3 object
gpg3_obj = EasyGoPiGo3()

# variable for holding the port to which we have the button connected to
port = "AD1"

button = gpg3_obj.init_button_sensor(port)

# call some button-specific methods

See also

For more sensors, please see our Dexter Industries shop.

__init__(port='AD1', gpg=None, use_mutex=False)[source]

Constructor for initializing a ButtonSensor object for the Grove Button.

Parameters
  • "AD1" (str port =) – Port to which we have the Grove Button connected to.

  • None (easygopigo3.EasyGoPiGo3 gpg =) – EasyGoPiGo3 object used for instantiating a Button object.

  • False (bool use_mutex =) – When using multiple threads/processes that access the same resource/device, mutexes should be enabled.

Raises

TypeError – If the gpg parameter is not a EasyGoPiGo3 object.

The port parameter can take the following values:

  • "AD1" - general purpose input/output port.

  • "AD2" - general purpose input/output port.

The ports’ locations can be seen in the following graphical representation: Hardware Ports.

is_button_pressed()[source]

Checks if the Grove Button is pressed.

Returns

True or False, if the Grove Button is pressed.

Return type

bool

5.3.9. Servo

class easysensors.Servo(port='SERVO1', gpg=None, use_mutex=False)[source]

Bases: easysensors.Sensor

Class for controlling servo motors with the GoPiGo3 robot. Allows you to rotate the servo by serving the angle of rotation.

This class is derived from Sensor class and because of this, it inherits all the attributes and methods.

For creating a Servo object we need to call init_servo() method like in the following examples.

# create an EasyGoPiGo3 object
gpg3_obj = EasyGoPiGo3()

# and now let's instantiate a Servo object through the gpg3_obj object
# this will bind a servo to port "SERVO1"
servo = gpg3_obj.init_servo()

# rotate the servo at 160 degrees
servo.rotate_servo(160)

Or if we want to specify the port to which we connect the servo, we need to call init_servo() the following way.

servo = gpg3_obj.init_servo("SERVO2")

See also

For more sensors, please see our Dexter Industries shop.

__init__(port='SERVO1', gpg=None, use_mutex=False)[source]

Constructor for instantiating a Servo object for a (or multiple) servo (servos).

Parameters
  • "SERVO1" (str port =) – The port to which we have connected the servo.

  • None (easygopigo3.EasyGoPiGo3 gpg =) – EasyGoPiGo3 object that we need for instantiation.

  • False (bool use_mutex =) – When using multiple threads/processes that access the same resource/device, mutexes should be enabled.

Raises

TypeError – If the gpg parameter is not a EasyGoPiGo3 object.

The available ports that can be used for a servo are:

  • "SERVO1" - servo controller port.

  • "SERVO2" - servo controller port.

To see where these 2 ports are located, please take a look at the following graphical representation: Hardware Ports.

rotate_servo(servo_position)[source]

Rotates the servo at a specific angle.

Parameters

servo_position (int) – Angle at which the servo has to rotate. The values can be anywhere from 0 to 180 degrees.

The pulse width varies the following way:

  • 575 uS for 0 degrees - the servo’s default position.

  • 24250 uS for 180 degrees - where the servo is rotated at its maximum position.

Each rotation of 1 degree requires an increase of the pulse width by 10.27 uS.

Warning

We use PWM signals (Pulse Width Modulation), so the angle at which a servo will rotate will be case-dependent.
This means a servo’s 180 degrees position won’t be the same as with another servo.
reset_servo()[source]

Resets the servo straight ahead, in the middle position.

Tip

Same as calling rotate_servo(90).
Read more about rotate_servo() method.
disable_servo()[source]

Disable (or “float”) the servo.

The effect of this command is that if you then try to rotate the servo manually, it won’t resist you, thus meaning that it’s not trying to hold a target position.

5.3.10. DHTSensor

class easysensors.DHTSensor(gpg=None, sensor_type=0, use_mutex=False)[source]

Bases: easysensors.Sensor

Class for interfacing with the Grove DHT Sensor. This class derives from Sensor class, so all of its attributes and methods are inherited.

We can create a DHTSensor object similar to how we create it in the following template.

# create an EasyGoPiGo3 object
gpg3_obj = EasyGoPiGo3()

# and now let's instantiate a DHTSensor object through the gpg3_obj object
dht_sensor = gpg3_obj.init_dht_sensor()

# read values continuously and print them in the terminal
while True:
    temp, hum = dht_sensor.read()

    print("temp = {:.1f} hum = {:.1f}".format(temp, hum))
__init__(gpg=None, sensor_type=0, use_mutex=False)[source]

Constructor for creating a DHTSensor object which can be used for interfacing with the Grove DHT Sensor.

Parameters
  • None (easygopigo3.EasyGoPiGo3 gpg =) – Object that’s required for instantianting a DHTSensor object.

  • 0 (int sensor_type =) – Choose sensor_type = 0 when you have the blue-coloured DHT sensor or sensor_type = 1 when it’s white.

  • False (bool use_mutex =) – When using multiple threads/processes that access the same resource/device, mutexes have to be used.

Raises

Any of the Sensor constructor’s exceptions in case of error.

read_temperature()[source]

Return the temperature in Celsius degrees.

Returns

The temperature in Celsius degrees.

Return type

float

If the sensor isn’t plugged in, a "Bad reading, try again" message is returned. If there is a runtime error, then a "Runtime error" message is returned.

read_humidity()[source]

Return the humidity as a percentage.

Returns

Return the humidity as a percentage number from 0% to 100%.

Return type

float

If the sensor isn’t plugged in, a "Bad reading, try again" message is returned. If there is a runtime error, then a "Runtime error" message is returned.

read()[source]

Return the temperature and humidity.

Returns

The temperature and humidity as a tuple, where the temperature is the 1st element of the tuple and the humidity the 2nd.

Return type

(float, float)

If the sensor isn’t plugged in, a "Bad reading, try again" message is returned. If there is a runtime error, then a "Runtime error" message is returned.

5.3.11. Remote

class easysensors.Remote(port='AD1', gpg=None, use_mutex=False)[source]

Bases: easysensors.Sensor

Class for interfacing with the Infrared Receiver.

With this sensor, you can command your GoPiGo3 with an Infrared Remote.

In order to create an object of this class, we would do it like in the following example.

# initialize an EasyGoPiGo3 object
gpg3_obj = EasyGoPiGo3()

# now initialize a Remote object
remote_control = gpg3_obj.init_remote()

# read whatever command you want from the remote by using
# the [remote_control] object
keycodes = ['up', 'left', 'ok', 'right', 'down', '1', '2', '3', '4', '5', '6', '7', '8', '9', '*', '0', '#']

List for mapping the codes we get with the read() method to the actual symbols we see on the Infrared Remote.

__init__(port='AD1', gpg=None, use_mutex=False)[source]

Constructor for initializing a Remote object.

Parameters
  • "AD1" (str port =) – The port to which we connect the Infrared Receiver.

  • None (easygopigo3.EasyGoPiGo3 gpg =) – The EasyGoPiGo3 object that we need for instantiating this object.

  • False (bool use_mutex =) – When using multiple threads/processes that access the same resource/device, mutexes should be enabled.

Raises

TypeError – If the gpg parameter is not a EasyGoPiGo3 object.

The "AD1" and "AD2" ports’ location on the GoPiGo3 robot can be seen in the following graphical representation: Hardware Ports.

read()[source]

Reads the numeric code received by the Infrared Receiver.

Returns

The numeric code of the symbol that was pressed on the Infrared Remote.

Return type

int

The numeric code represents the index of the keycodes list. By accessing the keycodes elements with the numeric code, you get the symbol that was pressed on the Infrared Remote.

For only getting the symbol that was pressed on the Infrared Remote, please check the get_remote_code() method.

Warning

On SensorError exception:

  • "Invalid Reading" string is printed in the console.

  • The value of -1 is returned.

get_remote_code()[source]

Returns the symbol of the pressed key in a string format.

Returns

The symbol that was pressed on the Infrared Remote.

Return type

str

Check the keycodes list for seeing what strings this method can return. On error or when nothing is read, an empty string is returned.

5.3.12. LineFollower

easysensors.LineFollower(port='I2C', gpg=None, use_mutex=False)[source]

Returns an instantiated object of di_sensors.easy_line_follower.EasyLineFollower.

This is a replacement function for the line follower class that used to be found here - it has not moved to di_sensors library.

Parameters
  • "I2C" (str port =) – The port to which we have connected the line follower sensor. Can also be "AD1"/"AD2" for the black Line Follower sensor.

  • None (easygopigo3.EasyGoPiGo3 gpg =) – This is no longer required. Just skip this parameter.

  • False (bool use_mutex =) – When using multiple threads/processes that access the same resource/device, mutexes should be enabled.

Raises
  • ImportError – If the di_sensors library couldn’t be found.

  • IOError – If the line follower is not responding.