[AIOT] Mraa Library androids for Tinker Board 3N

  • androids Archive file for the IO interface of 14 pins on ASUS Tinker Board 3N

mraa-2.2.0.zip

  • The apk of Mraa API for Tinker Board 3N

Tinker3N_MRAA_Sample.zip

  • Class

class

constructor

class

constructor

Gpio

Gpio(int pin_index)

Pwm

Pwm (int pin_index)

I2c

I2c (int i2c_index)

Uart

Uart(int uart_index)

Spi

Spi (int spi_index)

Aio

Aio(int adc_index)

 

 

 

 

 

 

 

 

  • Index Class

-- GPIO

Tinker Board

Field

Index Value

Tinker Board

TINKERBOARD_PIN4

4

Tinker Board

TINKERBOARD_PIN5

5

Tinker Board

TINKERBOARD_PIN6

6

Tinker Board

TINKERBOARD_PIN7

7

Tinker Board

TINKERBOARD_PIN8

8

Tinker Board

TINKERBOARD_PIN9

9

Tinker Board

TINKERBOARD_PIN10

10

Tinker Board

TINKERBOARD_PIN11

11

Tinker Board

TINKERBOARD_PIN12

12

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

-- I2C

TinkerBoard3NI2C

Field

Index Value

The Uart Interface

TinkerBoard3NI2C

TINKERBOARD_3N_I2C5

0I2c5

 

 

 

 

 

-- SPI

TinkerBoard3NSPI

Field

Index Value

The Uart Interface

TinkerBoard3NSPITINKERBOARD_3N_SPI30Spi3

 

 

 

 

 

-- Uart

TinkerBoard3NUART

Field

Index Value

The Uart Interface

TinkerBoard3NUART

TINKERBOARD_3N_UART4

0Uart4

TinkerBoard3NUART

TINKERBOARD_3N_UART9

1Uart9

 

 

 

 

 

 

 

-- ADC

TinkerBoard3NADC

Field

Index Value

The Uart Interface

TinkerBoard3NADCTINKERBOARD_3N_ADC60Adc6
TinkerBoard3NADCTINKERBOARD_3N_ADC71Adc7

 

 

 

 

 

 

  • The mraa API Class for androids

-- GPIO

Methods

Parameter

Description

Return

dir(Dir dir)DirSet input/outputResult
readDir()voidRead input/output dirDir
read()voidSet input and read gpio value0/1
write(int v)0/1Set output valueResult

 

 

 

 

 

 

 

 

 

 

-- I2C

Methods

Parameter

Description

Return

address(short a)0x00-0xFFSet i2c addressResult
readByte()voidRead a byte data form i2cshort
writeByte(short b)ModeWrite a byte data to i2cResult
read(byte[] buf)byte[]Read a byte[] data form i2cread size
write(byte[] buf)byte[]Write a byte[] data to i2cResult
readReg(short a)0x00-0xFFRead a byte data form i2c addrshort
writeReg(short a, short d)0x00-0xFF, 0x00-0xFFWrite a byte data to i2c addrResult
readWordReg(short a)0x00-0xFFRead a byte[2] data form i2c addrint
writeWordReg(short a, int d)0x00-0xFF, 0x0000-0xFFFFWrite a byte[2] data to i2c addrResult
readBytesReg(short a, byte[] b)0x00-0xFF, byte[]Read a byte[] data form i2c addrint

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

-- PWM

Methods

Parameter

Description

Return

period(float s)0.0001 - 2.147483Set pwm periodResult
period_ms(int m)1 - 2147Set pwm periodResult
period_us(int u)1 - 2147483Set pwm periodResult
pulsewidth(float s)0.0001 - 2.147483Set pwm dutyResult
pulsewidth_ms(int m)1 - 2147Set pwm dutyResult
pulsewidth_us(int u)1 - 2147483Set pwm dutyResult
max_period()voidGet pwm max periodint(us)
min_period()voidGet pwm min periodint(us)
read()voidGet pwm period/duty0.0 - 1.0
write(float p)0.0 - 1.0Set pwm period/duty percentageResult
enable(boolean e)true/falsedis/enable pwmResult

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

-- SPI

Methods

Parameter

Description

Return

defaultConfig()voidSet mraa default config (mode0,lsb=0,bits=8)Result
mode(Spi_Mode m)voidSet spi modeResult
frequency(int f)intSet spi frequency max=48000000Result
lsbmode(boolean l)true/falseSet spi lsmodeResult
bitPerWord(long b)8/16Set spi bit_pre_wordResult
writeByte(short a)0x00-0xFFWrite a byte data to spiint(recv data)
writeWord(int a)0x0000-0xFFFFWrite a byte[2] data to spiint(recv data)
write(byte[] b)byte[]Write a byte[] data to spibyte[](recv data)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

-- UART

Methods

Parameter

Description

Return

defaultConfig()voidSet mraa default config (9600 8N1, no echo or special character)Result
setBaudRate(long b)longSet uart baudrate max=150000000Result
setMode(int bytesize, UartParity parity, int stopbits)intSet the transfer modeResult
setFlowcontrol(boolean xonxoff, boolean rtscts)true/falseSet the flowcontrolResult
setTimeout(int read, int write, int interchar)-1 - int_maxSet the timeout for read and write operationsResult
setNonBlocking(boolean b)true/falseSet the blocking state for write operationsResult
sendBreak(int b)0 - max_intSend a break to the deviceResult
flush()voidFlush the outbound dataResult
dataAvailable()voidCheck to see if data is available on the device for reading, return immediatelyboolean
dataAvailable(long timeout)1 - int_maxCheck to see if data is available on the device for reading and time outboolean
readStr(int length)1 - int_maxRead bytes from the device into a String objectString
writeStr(String s)Stringrite bytes in String object to a deviceint
read(byte[] data)byte[]Check to see if data is available on the device for reading and time outint(read size)
wrtie(byte[] data)byte[]Check to see if data is available on the device for reading and time outint(write size)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

-- AIO

Methods

Parameter

Description

Return

getBit()intGets the bit value mraa is shifting the analog read toint
read()voidRead a value from the AIO pinlong
readFloat()voidRead a value from the AIO pin and return it as a normalized floatfloat
setBit(int bits)intSet the bit value which mraa will shift the raw reading from the ADC toResult

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • Example for 14 pin hardware interface

-- GPIO

import mraa.*;

// Test GPIO 5 hardware interface
Gpio gpio5 = new Gpio(TinkerBoard.TINKERBOARD_PIN5.swigValue());
gpio5.dir(Dir.DIR_OUT);
gpio5.write(1);
 

-- I2C

Enable I2C function by modify /dtoverlay/config.txt. Then, reboot the device.

  • “#intf:i2c5=off” → “intf:i2c5=on”
import mraa.*;

// Test I2c5 interface
I2c i2c = new I2c(TinkerBoard3NI2C.TINKERBOARD_3N_I2C5.swigValue());
// Test by ADXL345 accelerometer I2c device
i2c.address((short) 0x53);
i2c.writeReg((short)0x01, (short) 0x57);
try {
    Thread.sleep(1000);
} catch (InterruptedException e) {
    e.printStackTrace();
}
i2c.address((short) 0x50);
Log.d(TAG, "i2c5 read: 0x" + Integer.toHexString(i2c.readReg((short)0x01)));
 

-- PWM

Enable PWMs function by modify /dtoverlay/config.txt. Then, reboot the device.

  • “#intf:pwm12=off” → “intf:pwm12=on”
  • “#intf:pwm13=off” → “intf:pwm13=on”
  • “#intf:pwm14=off” → “intf:pwm14=on”
  • “#intf:pwm15=off” → “intf:pwm15=on”
import mraa.*;

//enable the pwm15 signal
Pwm pwm = new Pwm(TinkerBoard.TINKERBOARD_PIN6.swigValue());
pwm.period_us(20000);
pwm.write((float) 0.5);
pwm.enable(true);

// release the pwm signal
pwm.enable(false);
pwm.unexport();
 

-- SPI

Enable SPI function by modify /dtoverlay/config.txt. Then, reboot the device.

  • “#intf:spi3=off” → “intf:spi3=on”
import mraa.*;

// Test Spi3 interface
Spi spi = new Spi(TinkerBoard3NSPI.TINKERBOARD_3N_SPI3.swigValue());
byte[] recv = spi.write(new byte[]{0x41, 0x61});
Log.d(TAG, String.format("onCreate: recv[0]=0x%x, recv[1]=0x%x", recv[0], recv[1]));
 

-- UART

Enable UARTs function by modify /dtoverlay/config.txt. Then, reboot the device.

  • “#intf:uart4=off” → “intf:uart4=on”
  • “#intf:uart9=off” → “intf:uart9=on”
import mraa.*;

// Test Uart4 interface
Uart uart = new Uart(TinkerBoard3NUART.TINKERBOARD_3N_UART4.swigValue());
uart.defaultConfig();
uart.setBaudRate(115200);
uart.writeStr("ASUS Tinker Board 3N");
String read = uart.readStr(6);
Log.d(TAG, "uart4 read: " + read);
 

-- ADC

import mraa.*;

Aio aio6 = new Aio(TinkerBoard3NADC.TINKERBOARD_3N_ADC6.swigValue());
float vin_6 = aio6.readFloat();
Log.d(TAG, "adc6 read: " + String.valueOf(vin_6));