j5.backends.console.sb.arduino module¶
Console Backend for the SourceBots Arduino.
-
class
j5.backends.console.sb.arduino.
SBArduinoConsoleBackend
(serial: str, console_class: Type[j5.backends.console.console.Console] = <class 'j5.backends.console.console.Console'>)[source]¶ Bases:
j5.components.servo.ServoInterface
,j5.components.derived.ultrasound.UltrasoundInterface
,j5.backends.console.j5.arduino.ArduinoConsoleBackend
Console Backend for the SourceBots Arduino.
-
board
¶ alias of
j5.boards.sb.arduino.SBArduinoBoard
-
classmethod
discover
() → Set[j5.boards.board.Board][source]¶ Discover boards that this backend can control.
Returns: set of boards that this backend can control.
-
get_gpio_pin_digital_state
(identifier: int) → bool¶ Get the last written state of a given GPIO pin.
Parameters: identifier – pin number Returns: Last known digital state of the pin. Raises: ValueError – pin is not in correct mode.
-
get_gpio_pin_mode
(identifier: int) → j5.components.gpio_pin.GPIOPinMode¶ Get the hardware mode of a GPIO pin.
Parameters: identifier – pin number. Returns: mode of the pin.
-
get_led_state
(identifier: int) → bool¶ Get the state of an LED.
Parameters: identifier – LED identifier. Returns: current state of the LED. Raises: ValueError – invalid LED identifier.
-
get_servo_position
(identifier: int) → Optional[float][source]¶ Get the position of a servo.
Parameters: identifier – Port of servo to check. Returns: Position of servo.
-
get_ultrasound_distance
(trigger_pin_identifier: int, echo_pin_identifier: int) → Optional[float][source]¶ Get a distance in metres.
Parameters: - trigger_pin_identifier – pin number of the trigger pin.
- echo_pin_identifier – pin number of the echo pin.
Returns: Distance measured in metres, or None if it timed out.
-
get_ultrasound_pulse
(trigger_pin_identifier: int, echo_pin_identifier: int) → Optional[datetime.timedelta][source]¶ Get a timedelta for the ultrasound time.
Parameters: - trigger_pin_identifier – pin number of the trigger pin.
- echo_pin_identifier – pin number of the echo pin.
Returns: Time taken for the pulse, or None if it timed out.
-
read_gpio_pin_analogue_value
(identifier: int) → float¶ Read the scaled analogue value of a given GPIO pin.
Parameters: identifier – pin number Returns: scaled analogue value of the pin. Raises: ValueError – pin is not in correct mode.
-
read_gpio_pin_digital_state
(identifier: int) → bool¶ Read the digital state of a given GPIO pin.
Parameters: identifier – pin number Returns: digital state of the pin. Raises: ValueError – pin is not in correct mode.
-
set_gpio_pin_mode
(identifier: int, pin_mode: j5.components.gpio_pin.GPIOPinMode) → None¶ Set the hardware mode of a GPIO pin.
Parameters: - identifier – pin number to set.
- pin_mode – mode to set the pin to.
-
set_led_state
(identifier: int, state: bool) → None¶ Set the state of an LED.
Parameters: - identifier – LED identifier.
- state – desired state of the LED.
Raises: ValueError – invalid LED identifier.
-
set_servo_position
(identifier: int, position: Optional[float]) → None[source]¶ Set the position of a servo.
Parameters: - identifier – Port of servo to set position.
- position – Position to set the servo to.
-
write_gpio_pin_dac_value
(identifier: int, scaled_value: float) → None¶ Write a scaled analogue value to the DAC on a given GPIO pin.
Parameters: - identifier – pin number
- scaled_value – scaled analogue value to write
Raises: NotImplementedError – Arduino Uno does not have a DAC.
-
write_gpio_pin_digital_state
(identifier: int, state: bool) → None¶ Write to the digital state of a GPIO pin.
Parameters: - identifier – pin number
- state – desired digital state.
Raises: ValueError – pin is not in correct mode.
-
write_gpio_pin_pwm_value
(identifier: int, duty_cycle: float) → None¶ Write a scaled analogue value to the PWM on a given GPIO pin.
Parameters: - identifier – pin number
- duty_cycle – duty cycle to write
Raises: NotImplementedError – Not implemented in any supported firmware yet.
-