API Reference

cameraManager

class pympcam.cameraManager.CameraManager

Controls the MPCam camerta.

Note: other controls are available from OpenCV.

flip_horizontal(enable: bool)

Flips the image around the horizontal.

Args:

enable: True if image should be flipped.

flip_vertical(enable: bool)

Flips the image around the vertical.

Args:

enable: True if image should be flipped.

get_autoExposure() pympcam.cameraManager.ExposureMode

Returns the camera auto-exposure setting.

Returns: MANUAL or AUTO.

get_autoGain() bool

Returns the camera auto-gain setting.

Returns: True if auto-gain is set, or False if not.

get_autoWhiteBalance() bool

Returns the camera auto-white-balance setting.

Returns: True if auto-white-balance is set, or False if not.

get_blueBalanceLevel() int

Returns the camera blue-balance level.

get_exposureLevel() int

Returns the camera exposure level.

get_gainLevel() int

Returns the camera gain level.

static get_param(param)
get_redBalanceLevel() int

Returns the camera red-balance level.

set_autoExposure(mode: pympcam.cameraManager.ExposureMode)

Sets the camera auto-exposure mode.

Args:

mode(ExposureMode): AUTO or MANUAL.

set_autoGain(enable: bool)

Enable/Disable the camera auto-gain.

Args:

enable: True to enable auto-gain. False to disable it.

set_autoWhiteBalance(enable: bool)

Enable/Disable the camera auto-white-balance.

Args:

enable: True to enable auto-wb. False to disable it.

set_blueBalanceLevel(level: int)

Sets the camera blue-balance level when auto-WB is disabled.

Args:

level: blue-balance value between 0..4095

set_exposureLevel(level: int)

Sets the camera exposure level when auto-exposure is set to MANUAL.

Args:

level: expsoure value between 0..65535

set_gainLevel(level: int)

Sets the camera gain level when auto-gain is disabled.

Args:

level: gain value between 0..1023

static set_param(param, val)
set_powerLineFreq(freq: pympcam.cameraManager.LineFreq)

Sets the camera power-line frequency.

Args:

freq(LineFreq): power-line frequency, either: DISABLED, F50Hz, F60Hz, AUTO

set_redBalanceLevel(level: int)

Sets the camera red-balance level when auto-WB is disabled.

Args:

level: red-balance value between 0..4095

set_testPattern(pattern: pympcam.cameraManager.TestPattern)

Sets the camera output test patterns.

Args:

pattern(TestPattern): the selected test pattern.

class pympcam.cameraManager.ExposureMode(value)

Supported camera auto-exposure modes.

AUTO = 0
MANUAL = 1
class pympcam.cameraManager.LineFreq(value)

Supported camera filters for power-line frequency.

AUTO = 3
DISABLED = 0
F50Hz = 1
F60Hz = 2
class pympcam.cameraManager.TestPattern(value)

Supported camera test patterns.

COLOR_BARS = 1
COLOR_BARS_WITH_ROLLING_BARS = 2
COLOR_SQUARES = 3
COLOR_SQUARES_WITH_ROLLING_BARS = 4
DISABLED = 0

commons

class pympcam.commons.MpcamGpio(chip: int, pin: int, direction: str = 'out')

Data class for MPCam GPIO.

Todo

Verify which periphery version has inverted gpio

Parameters
  • chip – Chip number for the GPIO.

  • pin – Pin number for the GPIO chip.

  • direction – Pin direction. Valid values are ‘in’ and ‘out’.

init() pympcam.fakePeriphery.GPIO

Initializes periphery’s GPIO.

Returns

GPIO type from periphery.

pympcam.commons.isMPCamBoard() bool

Detects if library is running on MPCam board.

Returns

True if Running on MPCam board.

coralManager

class pympcam.coralManager.CoralManager

Controls Coral (TPU) power state on MPCam board.

Sequences for the power up (USB) procedure are extracted from Coral Accelerator Module Datasheet

TIMEOUT_PGOOD_SEC = 0.002

Timeout for PGOOD4: Power OK signal, in seconds

TIMEOUT_PWR_EN_SEC = 0.01

Timeout for PWR_EN: Power enable input, in seconds

TIMEOUT_RST_SEC = 0.01

Timeout for RST_L: System reset, in seconds

turnOff()

Turns off internal Coral device in MPCam.

turnOn() bool

Turns on internal Coral device in MPCam.

Returns

PGOOD4 state, should be True to indicate proper turn on.

headerIo

class pympcam.headerIo.HeadersIo

Controls Headers Input/Output on MPCam board.

get(label: str) int

Gets GPIO current state.

Parameters

label – Header DIO to get (do0, do1, do2, do3).

Returns

DIO current state: 1 if active, 0 if not.

set(label: str, value: Optional[bool] = None) int

Sets (or toggles) GPIO current state. If value is provided, is set as current.

Parameters
  • label – Header DIO to get (do0, do1, do2, do3).

  • value – Forces a state to selected DIO.

Returns

DIO current state: 1 if active, 0 if not.

headerPwm

class pympcam.headerPwm.HeaderPwm

Controls Headers PWM on MPCam board.

Available PWM:

  • PWM1

  • PWM2

disable(label: str)

Disables (closes) a PWM device.

Parameters

label – PWM to be closed (pwm1, pwm2).

enable(label: str, duty_cycle=0.5, frequency=1)

Enables (opens) specified PWM.

Warning

Some combinations of duty_cycle and frequency may cause errors.

Parameters
  • label – PWM to be used (pwm1, pwm2).

  • duty_cycle – Duty cycle for the PWM, as % between 0 and 1.

  • frequency – Frequency for the PWM, as Hz.

get(label: str)

Gets PWM parameters.

Parameters

label – PWM to be get (pwm1, pwm2).

Returns

Tuple with duty cycle and frequency.

irLed

class pympcam.irLed.IrLed

Controls Infrared (IR) LEDs on MPCam board.

turnOff() None

Turns off IR LEDs

turnOn() None

Turns on IR LEDs

userButtons

class pympcam.userButtons.UserButtons

Controls User buttons on MPCam board.

Available buttons are:

  • SW1

  • SW2

getState(button: Optional[str] = None)

Gets current button state.

Parameters

button – button to get state.

Returns

True if button was pressed.

pollState(button: pympcam.fakePeriphery.GPIO, timeoutSeconds=10) bool

Polls button state during a period of time (timeout). Button change is detected either by faling or raising edge.

Parameters
  • button – button to get state.

  • timeoutSeconds – time to wait for button state change, in seconds.

Returns

True if button was pressed.

userLed

class pympcam.userLed.UserLed

Controls User LEDs on MPCam board.

Avaible LEDs:

  • LED1: Blue

  • LED2: Red

LED1

GPIO instance of LED1, Blue.

LED2

GPIO instance of LED2, Red.

disableHeartbeat() bool

Disable heartbeat trigger for user LED1.

Returns

True if disabled.

enableHeartbeat() bool

Enable heartbeat trigger for user LED1.

Returns

True if enabled.

getState(label: Optional[str] = None) bool

Gets current state of a user LED.

Parameters

label – LED to get state (LED1, LED2).

Returns

True if LED is on.

turnOff(label: Optional[str] = None) None

Turns off user LEDs.

Parameters

label – LED to be turn off (LED1, LED2) or empty for all.

turnOn(label: Optional[str] = None) None

Turns on user LEDs.

Parameters

label – LED to be turn on (LED1, LED2) or empty for all.