[AIOT] Mraa Library androids for Tinker Board 3N
- androids Archive file for the IO interface of 14 pins on ASUS Tinker Board 3N
- The apk of Mraa API for Tinker Board 3N
- 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 | 0 | I2c5 |
-- SPI
TinkerBoard3NSPI | Field | Index Value | The Uart Interface |
TinkerBoard3NSPI | TINKERBOARD_3N_SPI3 | 0 | Spi3 |
-- Uart
TinkerBoard3NUART | Field | Index Value | The Uart Interface |
TinkerBoard3NUART | TINKERBOARD_3N_UART4 | 0 | Uart4 |
TinkerBoard3NUART | TINKERBOARD_3N_UART9 | 1 | Uart9 |
-- ADC
TinkerBoard3NADC | Field | Index Value | The Uart Interface |
TinkerBoard3NADC | TINKERBOARD_3N_ADC6 | 0 | Adc6 |
TinkerBoard3NADC | TINKERBOARD_3N_ADC7 | 1 | Adc7 |
- The mraa API Class for androids
-- GPIO
Methods | Parameter | Description | Return |
dir(Dir dir) | Dir | Set input/output | Result |
readDir() | void | Read input/output dir | Dir |
read() | void | Set input and read gpio value | 0/1 |
write(int v) | 0/1 | Set output value | Result |
-- I2C
Methods | Parameter | Description | Return |
address(short a) | 0x00-0xFF | Set i2c address | Result |
readByte() | void | Read a byte data form i2c | short |
writeByte(short b) | Mode | Write a byte data to i2c | Result |
read(byte[] buf) | byte[] | Read a byte[] data form i2c | read size |
write(byte[] buf) | byte[] | Write a byte[] data to i2c | Result |
readReg(short a) | 0x00-0xFF | Read a byte data form i2c addr | short |
writeReg(short a, short d) | 0x00-0xFF, 0x00-0xFF | Write a byte data to i2c addr | Result |
readWordReg(short a) | 0x00-0xFF | Read a byte[2] data form i2c addr | int |
writeWordReg(short a, int d) | 0x00-0xFF, 0x0000-0xFFFF | Write a byte[2] data to i2c addr | Result |
readBytesReg(short a, byte[] b) | 0x00-0xFF, byte[] | Read a byte[] data form i2c addr | int |
-- PWM
Methods | Parameter | Description | Return |
period(float s) | 0.0001 - 2.147483 | Set pwm period | Result |
period_ms(int m) | 1 - 2147 | Set pwm period | Result |
period_us(int u) | 1 - 2147483 | Set pwm period | Result |
pulsewidth(float s) | 0.0001 - 2.147483 | Set pwm duty | Result |
pulsewidth_ms(int m) | 1 - 2147 | Set pwm duty | Result |
pulsewidth_us(int u) | 1 - 2147483 | Set pwm duty | Result |
max_period() | void | Get pwm max period | int(us) |
min_period() | void | Get pwm min period | int(us) |
read() | void | Get pwm period/duty | 0.0 - 1.0 |
write(float p) | 0.0 - 1.0 | Set pwm period/duty percentage | Result |
enable(boolean e) | true/false | dis/enable pwm | Result |
-- SPI
Methods | Parameter | Description | Return |
defaultConfig() | void | Set mraa default config (mode0,lsb=0,bits=8) | Result |
mode(Spi_Mode m) | void | Set spi mode | Result |
frequency(int f) | int | Set spi frequency max=48000000 | Result |
lsbmode(boolean l) | true/false | Set spi lsmode | Result |
bitPerWord(long b) | 8/16 | Set spi bit_pre_word | Result |
writeByte(short a) | 0x00-0xFF | Write a byte data to spi | int(recv data) |
writeWord(int a) | 0x0000-0xFFFF | Write a byte[2] data to spi | int(recv data) |
write(byte[] b) | byte[] | Write a byte[] data to spi | byte[](recv data) |
-- UART
Methods | Parameter | Description | Return |
defaultConfig() | void | Set mraa default config (9600 8N1, no echo or special character) | Result |
setBaudRate(long b) | long | Set uart baudrate max=150000000 | Result |
setMode(int bytesize, UartParity parity, int stopbits) | int | Set the transfer mode | Result |
setFlowcontrol(boolean xonxoff, boolean rtscts) | true/false | Set the flowcontrol | Result |
setTimeout(int read, int write, int interchar) | -1 - int_max | Set the timeout for read and write operations | Result |
setNonBlocking(boolean b) | true/false | Set the blocking state for write operations | Result |
sendBreak(int b) | 0 - max_int | Send a break to the device | Result |
flush() | void | Flush the outbound data | Result |
dataAvailable() | void | Check to see if data is available on the device for reading, return immediately | boolean |
dataAvailable(long timeout) | 1 - int_max | Check to see if data is available on the device for reading and time out | boolean |
readStr(int length) | 1 - int_max | Read bytes from the device into a String object | String |
writeStr(String s) | String | rite bytes in String object to a device | int |
read(byte[] data) | byte[] | Check to see if data is available on the device for reading and time out | int(read size) |
wrtie(byte[] data) | byte[] | Check to see if data is available on the device for reading and time out | int(write size) |
-- AIO
Methods | Parameter | Description | Return |
getBit() | int | Gets the bit value mraa is shifting the analog read to | int |
read() | void | Read a value from the AIO pin | long |
readFloat() | void | Read a value from the AIO pin and return it as a normalized float | float |
setBit(int bits) | int | Set the bit value which mraa will shift the raw reading from the ADC to | Result |
- 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));