MRAA

MRAA is a low level skeleton library for communication on GNU/Linux platforms. See examples here.

common Class

Module: mraa

Methods

init

() Enum Result

Initialise MRAA
Detects running platform and attempts to use included pinmap, this is run on module/library init/load but is handy to rerun to check board initialised correctly. mraa::SUCCESS inidicates correct initialisation.

Returns:

Enum Result:

Result of operation

getVersion

() String

Get libmraa version.

Returns:

String:

libmraa version (e.g. v0.4.0-20-gb408207)

setPriority

(
  • priority
)
Number

This function attempts to set the mraa process to a given priority and the scheduler to SCHED_RR. Highest * priority is typically 99 and minimum is 0. This function * will set to MAX if * priority is > MAX. Function will return -1 on failure.

Parameters:

  • priority Number

    Value from typically 0 to 99

Returns:

Number:

The priority value set

getPlatformType

() Enum Platform

Get platform type, board must be initialised.

Returns:

Enum Platform:

mraa::platform Platform type enum

printError

(
  • result
)

Print a textual representation of the mraa::Result

Parameters:

  • result Enum Result

    the Result to print

pinModeTest

(
  • pin
  • mode
)
Boolean

Checks if a pin is able to use the passed in mode.

Parameters:

  • pin Number

    Physical Pin to be checked.

  • mode Enum Pinmodes

    the mode to be tested.

Returns:

Boolean:

boolean if the mode is supported, 0=false.

adcRawBits

() Number

Check the board's bit size when reading the value

Returns:

Number:

raw bits being read from kernel module. Zero if no ADC

adcSupportedBits

() Number

Return value that the raw value should be shifted to. Zero if no ADC

Returns:

Number:

return actual bit size the adc value should be understood as.

getPlatformName

() String

Return platform name.

Returns:

String:

platform name or empty string if not initialised

getPlatformVersion

(
  • platform_offset
)
String

Return platform versioning info.

Parameters:

  • platform_offset Number

    optional subplatform identifier

Returns:

String:

platform versioning info or empty string if no info is present

getPinCount

() Number

Return count of physical pins on the running platform

Returns:

Number:

uint of physical pins.

getUartCount

() Number

Get platform usable UART count, board must be initialised.

Returns:

Number:

number of usable UARTs on the current platform. Function will return -1 on failure

getI2cBusCount

() Number

Get platform usable I2C bus count, board must be initialised.

Returns:

Number:

number f usable I2C bus count on the current platform. Function will return -1 on failure

getI2cBusId

(
  • i2c_bus
)
Number

Get I2C adapter number in sysfs.

Parameters:

  • i2c_bus Number

    the logical I2C bus number

Returns:

Number:

I2C adapter number in sysfs. Function will return -1 on failure

getPinName

(
  • pin
)
String

Get name of pin, board must be initialised.

Parameters:

  • pin Number

    number

Returns:

String:

Pin name or empty string on failure

getGpioLookup

(
  • pin_name
)
Number

Get GPIO index by pin name, board must be initialised.

Parameters:

  • pin_name String

    GPIO pin name. Eg: IO0

Returns:

Number:

int of MRAA index for GPIO

getI2cLookup

(
  • i2c_name
)
Number

Get I2C bus index by bus name, board must be initialised.

Parameters:

  • i2c_name String

    I2C bus name. Eg: I2C6

Returns:

Number:

int of MRAA index for I2C bus

getSpiLookup

(
  • spi_name
)
Number

Get SPI bus index by bus name, board must be initialised.

Parameters:

  • spi_name String

    Name of SPI bus. Eg: SPI2

Returns:

Number:

int of MRAA index for SPI bus

getPwmLookup

(
  • pwm_name
)
Number

Get PWM index by PWM name, board must be initialised.

Parameters:

  • pwm_name String

    Name of PWM. Eg:PWM0

Returns:

Number:

int of MRAA index for PWM

getUartLookup

(
  • uart_name
)
Number

Get UART index by UART name, board must be initialised.

Parameters:

  • uart_name String

    Name of the UART. Eg: UART2

Returns:

Number:

MRAA index for the UART

setLogLevel

(
  • level
)
Enum Result

Sets the log level to use from 0-7 where 7 is very verbose. These are the syslog log levels, see syslog(3) for more information on the levels.

Parameters:

  • level Number

Returns:

Enum Result:

Result of operation

hasSubPlatform

() Boolean

Detect presence of sub platform.

Returns:

Boolean:

bool true if sub platform is present and initialized, false otherwise

isSubPlatformId

(
  • pin_or_bus_id
)
Boolean

Check if pin or bus id includes sub platform mask.

Parameters:

  • pin_or_bus_id Number

    pin or bus number

Returns:

Boolean:

mraa_boolean_t 1 if pin or bus is for sub platform, 0 otherwise

getSubPlatformId

(
  • pin_or_bus_index
)
Number

Convert pin or bus index to corresponding sub platform id.

Parameters:

  • pin_or_bus_index Number

    pin or bus index

Returns:

Number:

int sub platform pin or bus number

getSubPlatformIndex

(
  • pin_or_bus_id
)
Number

Convert pin or bus sub platform id to index.

Parameters:

  • pin_or_bus_id Number

    sub platform pin or bus id

Returns:

Number:

int pin or bus index

getDefaultI2cBus

(
  • platform_offset
)
Number

Get default i2c bus, board must be initialised.

Parameters:

  • platform_offset Number

    optional subplatform identifier

Returns:

Number:

default i2c bus for paltform

addSubplatform

(
  • subplatformtype
  • dev
)
Enum Result

Add mraa subplatform

Parameters:

  • subplatformtype Enum Platform

    the type of subplatform to add (e.g. MRAA_GENERIC_FIRMATA or MRAA_GROVEPI)

  • dev String

    subplatform uart device string or i2c bus number (e.g. "/dev/ttyACM0" or "0")

Returns:

Enum Result:

Result of operation

removeSubplatform

(
  • subplatformtype
)
Enum Result

Remove mraa subplatform

Parameters:

  • subplatformtype Enum Platform

    the type of subplatform to remove (e.g. MRAA_GENERIC_FIRMATA)

Returns:

Enum Result:

Result of operation

initJsonPlatform

(
  • path
)
Enum Result

Instantiate an unknown board using a json file

Parameters:

  • path String

    Path to the json file, relative to the folder the program was initially run in or a direct path

Returns:

Enum Result:

Result indicating success

Enums

Platform
Enum Description
INTEL_GALILEO_GEN1 The Generation 1 Galileo platform (RevD)
INTEL_GALILEO_GEN2 The Generation 2 Galileo platform (RevG/H)
INTEL_EDISON_FAB_C The Intel Edison (FAB C)
INTEL_DE3815 The Intel DE3815 Baytrail NUC
INTEL_MINNOWBOARD_MAX The Intel Minnow Board Max
RASPBERRY_PI The different Raspberry PI Models -like A,B,A+,B+
BEAGLEBONE The different BeagleBone Black Modes B/C
BANANA Allwinner A20 based Banana Pi and Banana Pro
INTEL_NUC5 The Intel 5th generations Broadwell NUCs
INTEL_SOFIA_3GR The Intel SoFIA 3GR
INTEL_CHERRYHILLS The Intel Braswell Cherryhills
INTEL_JOULE_EXPANSION The Intel Joule Expansion Board
PHYBOARD_WEGA The phyBOARD-Wega
DE_NANO_SOC Terasic DE-Nano-SoC Board
MTK_LINKIT Mediatek MT7688 based Linkit boards
MTK_OMEGA2 MT7688 based Onion Omega2 board
IEI_TANK IEI Tank System
FTDI_FT4222 FTDI FT4222 USB to i2c bridge
GROVEPI GrovePi shield i2c bridge
GENERIC_FIRMATA Firmata uart platform/bridge
ANDROID_PERIPHERALMANAGER Android Things peripheral manager platform
MOCK_PLATFORM Mock platform, which requires no real hardware
NULL_PLATFORM
UNKNOWN_PLATFORM An unknown platform type, typically will load INTEL_GALILEO_GEN1
A96BOARDS Linaro 96boards, A prefix for 'ARM' since not allowed numerical
INTEL_UP The UP Board
INTEL_UP2 The UP^2 Board
mraa_platform_t
Enum Description
96BOARDS Linaro 96boards
UP The UP Board
UP2 The UP^2 Board
JSON_PLATFORM User initialised platform from json
IntelEdisonMiniboard
Enum Description
INTEL_EDISON_MINIBOARD_J17_1
INTEL_EDISON_MINIBOARD_J17_5
INTEL_EDISON_MINIBOARD_J17_7
INTEL_EDISON_MINIBOARD_J17_8
INTEL_EDISON_MINIBOARD_J17_9
INTEL_EDISON_MINIBOARD_J17_10
INTEL_EDISON_MINIBOARD_J17_11
INTEL_EDISON_MINIBOARD_J17_12
INTEL_EDISON_MINIBOARD_J17_14
INTEL_EDISON_MINIBOARD_J18_1
INTEL_EDISON_MINIBOARD_J18_2
INTEL_EDISON_MINIBOARD_J18_6
INTEL_EDISON_MINIBOARD_J18_7
INTEL_EDISON_MINIBOARD_J18_8
INTEL_EDISON_MINIBOARD_J18_10
INTEL_EDISON_MINIBOARD_J18_11
INTEL_EDISON_MINIBOARD_J18_12
INTEL_EDISON_MINIBOARD_J18_13
INTEL_EDISON_MINIBOARD_J19_4
INTEL_EDISON_MINIBOARD_J19_5
INTEL_EDISON_MINIBOARD_J19_6
INTEL_EDISON_MINIBOARD_J19_8
INTEL_EDISON_MINIBOARD_J19_9
INTEL_EDISON_MINIBOARD_J19_10
INTEL_EDISON_MINIBOARD_J19_11
INTEL_EDISON_MINIBOARD_J19_12
INTEL_EDISON_MINIBOARD_J19_13
INTEL_EDISON_MINIBOARD_J19_14
INTEL_EDISON_MINIBOARD_J20_3
INTEL_EDISON_MINIBOARD_J20_4
INTEL_EDISON_MINIBOARD_J20_5
INTEL_EDISON_MINIBOARD_J20_6
INTEL_EDISON_MINIBOARD_J20_7
INTEL_EDISON_MINIBOARD_J20_8
INTEL_EDISON_MINIBOARD_J20_9
INTEL_EDISON_MINIBOARD_J20_10
INTEL_EDISON_MINIBOARD_J20_11
INTEL_EDISON_MINIBOARD_J20_12
INTEL_EDISON_MINIBOARD_J20_13
INTEL_EDISON_MINIBOARD_J20_14
IntelEdison
Enum Description
INTEL_EDISON_GP182
INTEL_EDISON_GP135
INTEL_EDISON_GP27
INTEL_EDISON_GP20
INTEL_EDISON_GP28
INTEL_EDISON_GP111
INTEL_EDISON_GP109
INTEL_EDISON_GP115
INTEL_EDISON_GP128
INTEL_EDISON_GP13
INTEL_EDISON_GP165
INTEL_EDISON_GP19
INTEL_EDISON_GP12
INTEL_EDISON_GP183
INTEL_EDISON_GP110
INTEL_EDISON_GP114
INTEL_EDISON_GP129
INTEL_EDISON_GP130
INTEL_EDISON_GP44
INTEL_EDISON_GP46
INTEL_EDISON_GP48
INTEL_EDISON_GP131
INTEL_EDISON_GP14
INTEL_EDISON_GP40
INTEL_EDISON_GP43
INTEL_EDISON_GP77
INTEL_EDISON_GP82
INTEL_EDISON_GP83
INTEL_EDISON_GP134
INTEL_EDISON_GP45
INTEL_EDISON_GP47
INTEL_EDISON_GP49
INTEL_EDISON_GP15
INTEL_EDISON_GP84
INTEL_EDISON_GP42
INTEL_EDISON_GP41
INTEL_EDISON_GP78
INTEL_EDISON_GP79
INTEL_EDISON_GP80
INTEL_EDISON_GP81
RaspberryWiring
Enum Description
RASPBERRY_WIRING_PIN8
RASPBERRY_WIRING_PIN9
RASPBERRY_WIRING_PIN7
RASPBERRY_WIRING_PIN15
RASPBERRY_WIRING_PIN16
RASPBERRY_WIRING_PIN0
RASPBERRY_WIRING_PIN1
RASPBERRY_WIRING_PIN2
RASPBERRY_WIRING_PIN3
RASPBERRY_WIRING_PIN4
RASPBERRY_WIRING_PIN5
RASPBERRY_WIRING_PIN12
RASPBERRY_WIRING_PIN13
RASPBERRY_WIRING_PIN6
RASPBERRY_WIRING_PIN14
RASPBERRY_WIRING_PIN10
RASPBERRY_WIRING_PIN11
RASPBERRY_WIRING_PIN17
RASPBERRY_WIRING_PIN21
RASPBERRY_WIRING_PIN18
RASPBERRY_WIRING_PIN19
RASPBERRY_WIRING_PIN22
RASPBERRY_WIRING_PIN20
RASPBERRY_WIRING_PIN26
RASPBERRY_WIRING_PIN23
RASPBERRY_WIRING_PIN24
RASPBERRY_WIRING_PIN27
RASPBERRY_WIRING_PIN25
RASPBERRY_WIRING_PIN28
RASPBERRY_WIRING_PIN29
Result
Enum Description
SUCCESS Expected response
ERROR_FEATURE_NOT_IMPLEMENTED Feature TODO
ERROR_FEATURE_NOT_SUPPORTED Feature not supported by HW
ERROR_INVALID_VERBOSITY_LEVEL Verbosity level wrong
ERROR_INVALID_PARAMETER Parameter invalid
ERROR_INVALID_HANDLE Handle invalid
ERROR_NO_RESOURCES No resource of that type avail
ERROR_INVALID_RESOURCE Resource invalid
ERROR_INVALID_QUEUE_TYPE Queue type incorrect
ERROR_NO_DATA_AVAILABLE No data available
ERROR_INVALID_PLATFORM Platform not recognised
ERROR_PLATFORM_NOT_INITIALISED Board information not initialised
ERROR_UART_OW_SHORTED UART OW Short Circuit Detected
ERROR_UART_OW_NO_DEVICES UART OW No devices detected
ERROR_UART_OW_DATA_ERROR UART OW Data/Bus error detected
ERROR_UNSPECIFIED Unknown Error
Pinmodes
Enum Description
PIN_VALID Pin Valid
PIN_GPIO General Purpose IO
PIN_PWM Pulse Width Modulation
PIN_FAST_GPIO Faster GPIO
PIN_SPI SPI
PIN_I2C I2C
PIN_AIO Analog in
PIN_UART UART
I2cMode
Enum Description
I2C_STD up to 100Khz
I2C_FAST up to 400Khz
I2C_HIGH up to 3.4Mhz
UartParity
Enum Description
UART_PARITY_NONE
UART_PARITY_EVEN
UART_PARITY_ODD
UART_PARITY_MARK
UART_PARITY_SPACE
Mode
Enum Description
MODE_STRONG Default. Strong High and Low
MODE_PULLUP Resistive High
MODE_PULLDOWN Resistive Low
MODE_HIZ High Z State
Dir
Enum Description
DIR_OUT Output. A Mode can also be set
DIR_IN Input
DIR_OUT_HIGH Output. Init High
DIR_OUT_LOW Output. Init Low
Edge
Enum Description
EDGE_NONE No interrupt on Gpio
EDGE_BOTH Interrupt on rising & falling
EDGE_RISING Interrupt on rising only
EDGE_FALLING Interrupt on falling only
InputMode
Enum Description
MODE_IN_ACTIVE_HIGH Resistive High
MODE_IN_ACTIVE_LOW Resistive Low
OutputMode
Enum Description
MODE_OUT_OPEN_DRAIN Open Drain Configuration
MODE_OUT_PUSH_PULL Push Pull Configuration
Spi_Mode
Enum Description
SPI_MODE0 CPOL = 0, CPHA = 0, Clock idle low, data is clocked in on rising edge, output data (change) on falling edge
SPI_MODE1 CPOL = 0, CPHA = 1, Clock idle low, data is clocked in on falling edge, output data (change) on rising edge
SPI_MODE2 CPOL = 1, CPHA = 0, Clock idle low, data is clocked in on falling edge, output data (change) on rising edge
SPI_MODE3 CPOL = 1, CPHA = 1, Clock idle low, data is clocked in on rising, edge output data (change) on falling edge