Module brickpi3 :: Class BrickPi3
[frames] | no frames]

Class BrickPi3

source code

object --+
         |
        BrickPi3

Instance Methods
 
__init__(self, addr=1, detect=True)
Do any necessary configuration, and optionally detect the BrickPi3
source code
 
spi_transfer_array(self, data_out)
Conduct a SPI transaction
source code
 
spi_write_8(self, MessageType, Value)
Send an 8-bit value over SPI
source code
 
spi_read_16(self, MessageType)
Read a 16-bit value over SPI
source code
 
spi_write_16(self, MessageType, Value)
Send a 16-bit value over SPI
source code
 
spi_write_24(self, MessageType, Value)
Send a 24-bit value over SPI
source code
 
spi_read_32(self, MessageType)
Read a 32-bit value over SPI
source code
 
spi_write_32(self, MessageType, Value)
Send a 32-bit value over SPI
source code
 
get_manufacturer(self)
Read the 20 charactor BrickPi3 manufacturer name
source code
 
get_board(self)
Read the 20 charactor BrickPi3 board name
source code
 
get_version_hardware(self)
Read the hardware version
source code
 
get_version_firmware(self)
Read the firmware version
source code
 
get_id(self)
Read the 128-bit BrickPi hardware serial number
source code
 
set_led(self, value)
Control the onboard LED
source code
 
get_voltage_3v3(self)
Get the 3.3v circuit voltage
source code
 
get_voltage_5v(self)
Get the 5v circuit voltage
source code
 
get_voltage_9v(self)
Get the 9v circuit voltage
source code
 
get_voltage_battery(self)
Get the battery voltage
source code
 
set_sensor_type(self, port, type, params=0)
Set the sensor type
source code
 
transact_i2c(self, port, Address, OutArray, InBytes)
Conduct an I2C transaction
source code
 
get_sensor(self, port)
Read a sensor value
source code
 
set_motor_power(self, port, power)
Set the motor power in percent
source code
 
set_motor_position(self, port, position)
Set the motor target position in degrees
source code
 
set_motor_dps(self, port, dps)
Set the motor target speed in degrees per second
source code
 
set_motor_limits(self, port, power=0, dps=0)
Set the motor speed limit
source code
 
get_motor_status(self, port)
Read a motor status
source code
 
offset_motor_encoder(self, port, position)
Offset a motor encoder
source code
 
get_motor_encoder(self, port)
Read a motor encoder in degrees
source code
 
reset_all(self)
Reset the BrickPi.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables
  PORT_1 = 0x01
  PORT_2 = 0x02
  PORT_3 = 0x04
  PORT_4 = 0x08
  PORT_A = 0x01
  PORT_B = 0x02
  PORT_C = 0x04
  PORT_D = 0x08
  MOTOR_FLOAT = -128
  SensorType = [0, 0, 0, 0]
  I2CInBytes = [0, 0, 0, 0]
  BPSPI_MESSAGE_TYPE = Enumeration(...
  SENSOR_TYPE = Enumeration(...
  SENSOR_STATE = Enumeration(...
  SENSOR_CUSTOM = Enumeration(...
Flags for use with SENSOR_TYPE.CUSTOM
  SENSOR_I2C_SETTINGS = Enumeration(...
  MOTOR_STATUS_FLAG = Enumeration(...
Properties

Inherited from object: __class__

Method Details

__init__(self, addr=1, detect=True)
(Constructor)

source code 

Do any necessary configuration, and optionally detect the BrickPi3

Optionally specify the SPI address as something other than 1 Optionally disable the detection of the BrickPi3 hardware. This can be used for debugging and testing when the BrickPi3 would otherwise not pass the detection tests.

Overrides: object.__init__

spi_transfer_array(self, data_out)

source code 

Conduct a SPI transaction

Keyword arguments: data_out -- a list of bytes to send. The length of the list will determine how many bytes are transferred.

Returns a list of the bytes read.

spi_write_8(self, MessageType, Value)

source code 

Send an 8-bit value over SPI

Keyword arguments: MessageType -- the SPI message type Value -- the value to be sent

spi_read_16(self, MessageType)

source code 

Read a 16-bit value over SPI

Keyword arguments: MessageType -- the SPI message type

Returns: value

spi_write_16(self, MessageType, Value)

source code 

Send a 16-bit value over SPI

Keyword arguments: MessageType -- the SPI message type Value -- the value to be sent

spi_write_24(self, MessageType, Value)

source code 

Send a 24-bit value over SPI

Keyword arguments: MessageType -- the SPI message type Value -- the value to be sent

spi_read_32(self, MessageType)

source code 

Read a 32-bit value over SPI

Keyword arguments: MessageType -- the SPI message type

Returns : value

spi_write_32(self, MessageType, Value)

source code 

Send a 32-bit value over SPI

Keyword arguments: MessageType -- the SPI message type Value -- the value to be sent

get_manufacturer(self)

source code 

Read the 20 charactor BrickPi3 manufacturer name

Returns: BrickPi3 manufacturer name string

get_board(self)

source code 

Read the 20 charactor BrickPi3 board name

Returns: BrickPi3 board name string

get_version_hardware(self)

source code 

Read the hardware version

Returns: hardware version

get_version_firmware(self)

source code 

Read the firmware version

Returns: firmware version

get_id(self)

source code 

Read the 128-bit BrickPi hardware serial number

Returns: serial number as 32 char HEX formatted string

set_led(self, value)

source code 

Control the onboard LED

Keyword arguments: value -- the value (in percent) to set the LED brightness to. -1 returns control of the LED to the firmware.

get_voltage_3v3(self)

source code 

Get the 3.3v circuit voltage

Returns: 3.3v circuit voltage

get_voltage_5v(self)

source code 

Get the 5v circuit voltage

Returns: 5v circuit voltage

get_voltage_9v(self)

source code 

Get the 9v circuit voltage

Returns: 9v circuit voltage

get_voltage_battery(self)

source code 

Get the battery voltage

Returns: battery voltage

set_sensor_type(self, port, type, params=0)

source code 

Set the sensor type

Keyword arguments:
port -- The sensor port(s). PORT_1, PORT_2, PORT_3, and/or PORT_4.
type -- The sensor type
params = 0 -- the parameters needed for some sensor types.

params is used for the following sensor types:
    CUSTOM -- a 16-bit integer used to configure the hardware.
    I2C -- a list of settings:
        params[0] -- Settings/flags
        params[1] -- target Speed in microseconds (0-255). Realistically the speed will vary.
        if SENSOR_I2C_SETTINGS_SAME flag set in I2C Settings:
            params[2] -- Delay in microseconds between transactions.
            params[3] -- Address
            params[4] -- List of bytes to write
            params[5] -- Number of bytes to read

transact_i2c(self, port, Address, OutArray, InBytes)

source code 

Conduct an I2C transaction

Keyword arguments: port -- The sensor port (one at a time). PORT_1, PORT_2, PORT_3, or PORT_4. Address -- The I2C address for the device. Bits 1-7, not 0-6. OutArray -- A list of bytes to write to the device InBytes -- The number of bytes to read from the device

get_sensor(self, port)

source code 

Read a sensor value

Keyword arguments:
port -- The sensor port (one at a time). PORT_1, PORT_2, PORT_3, or PORT_4.

Returns the value(s) for the specified sensor.
    The following sensor types each return a single value:
        NONE ----------------------- 0
        TOUCH ---------------------- 0 or 1 (released or pressed)
        NXT_TOUCH ------------------ 0 or 1 (released or pressed)
        EV3_TOUCH ------------------ 0 or 1 (released or pressed)
        NXT_ULTRASONIC ------------- distance in CM
        NXT_LIGHT_ON  -------------- reflected light
        NXT_LIGHT_OFF -------------- ambient light
        NXT_COLOR_RED -------------- red reflected light
        NXT_COLOR_GREEN ------------ green reflected light
        NXT_COLOR_BLUE ------------- blue reflected light
        NXT_COLOR_OFF -------------- ambient light
        EV3_GYRO_ABS --------------- absolute rotation position in degrees
        EV3_GYRO_DPS --------------- rotation rate in degrees per second
        EV3_COLOR_REFLECTED -------- red reflected light
        EV3_COLOR_AMBIENT ---------- ambient light
        EV3_COLOR_COLOR ------------ detected color
        EV3_ULTRASONIC_CM ---------- distance in CM
        EV3_ULTRASONIC_INCHES ------ distance in inches
        EV3_ULTRASONIC_LISTEN ------ 0 or 1 (no other ultrasonic sensors or another ultrasonic sensor detected)
        EV3_INFRARED_PROXIMITY ----- distance 0-100%
    
    The following sensor types each return a list of values
        CUSTOM --------------------- Pin 1 ADC (5v scale from 0 to 4095), Pin 6 ADC (3.3v scale from 0 to 4095), Pin 5 digital, Pin 6 digital
        I2C ------------------------ the I2C bytes read
        NXT_COLOR_FULL ------------- detected color, red light reflected, green light reflected, blue light reflected, ambient light
        EV3_GYRO_ABS_DPS ----------- absolute rotation position in degrees, rotation rate in degrees per second
        EV3_COLOR_RAW_REFLECTED ---- red reflected light, unknown value (maybe a raw ambient value?)
        EV3_COLOR_COLOR_COMPONENTS - red reflected light, green reflected light, blue reflected light, unknown value (maybe a raw value?)
        EV3_INFRARED_SEEK ---------- a list for each of the four channels. For each channel heading (-25 to 25), distance (-128 or 0 to 100)
        EV3_INFRARED_REMOTE -------- a list for each of the four channels. For each channel red up, red down, blue up, blue down, boadcast
        

set_motor_power(self, port, power)

source code 

Set the motor power in percent

Keyword arguments: port -- The Motor port(s). PORT_A, PORT_B, PORT_C, and/or PORT_D. power -- The power from -100 to 100, or -128 for float

set_motor_position(self, port, position)

source code 

Set the motor target position in degrees

Keyword arguments: port -- The motor port(s). PORT_A, PORT_B, PORT_C, and/or PORT_D. position -- The target position

set_motor_dps(self, port, dps)

source code 

Set the motor target speed in degrees per second

Keyword arguments: port -- The motor port(s). PORT_A, PORT_B, PORT_C, and/or PORT_D. dps -- The target speed in degrees per second

set_motor_limits(self, port, power=0, dps=0)

source code 

Set the motor speed limit

Keyword arguments: port -- The motor port(s). PORT_A, PORT_B, PORT_C, and/or PORT_D. power -- The power limit in percent (0 to 100), with 0 being no limit (100) dps -- The speed limit in degrees per second, with 0 being no limit

get_motor_status(self, port)

source code 

Read a motor status

Keyword arguments:
port -- The motor port (one at a time). PORT_A, PORT_B, PORT_C, or PORT_D.

Returns a list:
    flags -- 8-bits of bit-flags that indicate motor status:
        bit 0 -- LOW_VOLTAGE_FLOAT - The motors are automatically disabled because the battery voltage is too low
        bit 1 -- OVERLOADED - The motors aren't close to the target (applies to position control and dps speed control).
    power -- the raw PWM power in percent (-100 to 100)
    encoder -- The encoder position
    dps -- The current speed in Degrees Per Second

offset_motor_encoder(self, port, position)

source code 

Offset a motor encoder

Keyword arguments: port -- The motor port(s). PORT_A, PORT_B, PORT_C, and/or PORT_D. offset -- The encoder offset

Zero the encoder by offsetting it by the current position

get_motor_encoder(self, port)

source code 

Read a motor encoder in degrees

Keyword arguments: port -- The motor port (one at a time). PORT_A, PORT_B, PORT_C, or PORT_D.

Returns the encoder position in degrees

reset_all(self)

source code 

Reset the BrickPi. Set all the sensors' type to NONE, set the motors' speed to 0, and return control of the LED to the firmware.


Class Variable Details

BPSPI_MESSAGE_TYPE

Value:
Enumeration("""
        NONE,
        
        GET_MANUFACTURER,
        GET_NAME,
        GET_HARDWARE_VERSION,
        GET_FIRMWARE_VERSION,
        GET_ID,
...

SENSOR_TYPE

Value:
Enumeration("""
        NONE = 1,
        I2C,
        CUSTOM,
        
        TOUCH,
        NXT_TOUCH,
        EV3_TOUCH,
...

SENSOR_STATE

Value:
Enumeration("""
        VALID_DATA,
        NOT_CONFIGURED,
        CONFIGURING,
        NO_DATA,
        I2C_ERROR,
    """)

SENSOR_CUSTOM


Flags for use with SENSOR_TYPE.CUSTOM

PIN1_9V
    Enable 9V out on pin 1 (for LEGO NXT Ultrasonic sensor).

PIN5_OUT
    Set pin 5 state to output. Pin 5 will be set to input if this flag is not set.

PIN5_STATE
    If PIN5_OUT is set, this will set the state to output high, otherwise the state will
    be output low. If PIN5_OUT is not set, this flag has no effect.

PIN6_OUT
    Set pin 6 state to output. Pin 6 will be set to input if this flag is not set.

PIN6_STATE
    If PIN6_OUT is set, this will set the state to output high, otherwise the state will
    be output low. If PIN6_OUT is not set, this flag has no effect.

PIN1_ADC
    Enable the analog/digital converter on pin 1 (e.g. for NXT analog sensors).

PIN6_ADC
    Enable the analog/digital converter on pin 6.

Value:
Enumeration("""
        PIN1_9V,
        PIN5_OUT,
        PIN5_STATE,
        PIN6_OUT,
        PIN6_STATE,
        PIN1_ADC,
        PIN6_ADC,
...

SENSOR_I2C_SETTINGS

Value:
Enumeration("""
        MID_CLOCK,
        PIN1_9V,
        SAME,
        ALLOW_STRETCH_ACK,
        ALLOW_STRETCH_ANY,
    """)

MOTOR_STATUS_FLAG

Value:
Enumeration("""
        LOW_VOLTAGE_FLOAT,
    """)