Please enable javascript, or click here to visit my ecommerce web site powered by Shopify.
Jump to: navigation, search

Difference between revisions of "RockpiX/dev/libmraa"

< RockpiX‎ | dev
(Install libmraa)
(Install libmraa)
Line 12: Line 12:
  
 
  vms@vms-ROCK-Pi-X:~$ sudo apt update && sudo apt upgrade
 
  vms@vms-ROCK-Pi-X:~$ sudo apt update && sudo apt upgrade
  vms@vms-ROCK-Pi-X:~$ wget https://dl.radxa.com/rockpix/packages/libmraa-rockpix_0.3_amd64.deb
+
  vms@vms-ROCK-Pi-X:~$ wget https://dl.radxa.com/rockpix/packages/libmraa-rockpix_0.4_amd64.deb
 
  vms@vms-ROCK-Pi-X:~$ sudo apt install -f -y libc6 libjson-c4  libjson-c-dev libgtest-dev  libgcc1 libstdc++6 python2.7 libpython2.7 python3.8 libpython3.8
 
  vms@vms-ROCK-Pi-X:~$ sudo apt install -f -y libc6 libjson-c4  libjson-c-dev libgtest-dev  libgcc1 libstdc++6 python2.7 libpython2.7 python3.8 libpython3.8
 
  vms@vms-ROCK-Pi-X:~$ sudo dpkg -i libmraa-rockpix_0.3_amd64.deb
 
  vms@vms-ROCK-Pi-X:~$ sudo dpkg -i libmraa-rockpix_0.3_amd64.deb

Revision as of 07:35, 22 September 2021

    ROCK Pi X >  Libmraa


Libmraa-rockpiX

Install libmraa

We need to download the deb installation package first, and then install it:

vms@vms-ROCK-Pi-X:~$ sudo apt update && sudo apt upgrade
vms@vms-ROCK-Pi-X:~$ wget https://dl.radxa.com/rockpix/packages/libmraa-rockpix_0.4_amd64.deb
vms@vms-ROCK-Pi-X:~$ sudo apt install -f -y libc6 libjson-c4  libjson-c-dev libgtest-dev  libgcc1 libstdc++6 python2.7 libpython2.7 python3.8 libpython3.8
vms@vms-ROCK-Pi-X:~$ sudo dpkg -i libmraa-rockpix_0.3_amd64.deb
vms@vms-ROCK-Pi-X:~$ sudo apt-get install -f -y

Enable interface

See ROCK Pi X GPIO pintout. ROCK Pi X has one 40-pin expansion header. Each pin is distinguished by color.

Hardware V1.0/V1.1

10 GPIO:

PIN7  ISH_GPIO0
PIN12 GPIO_DFX3
PIN16 GPIO_DFX4
PIN21 ISH_GPIO9
PIN24 ISH_GPIO1
PIN26 ISH_GPIO4
PIN29 ISH_GPIO2
PIN31 ISH_GPIO3
PIN33 ISH_GPIO10
PIN37 ISH_GPIO13

I2C: x1, I2C1

PIN3 I2C2_SDA
PIN5 I2C2_SCL
PIN19 ISH_I2C1_DATA
PIN23 ISH_I2C1_CLK

SPI: x1, SPI0(Pin#11/13/15/27)

PIN11 SPI2_CLK
PIN13 SPI2_MISO
PIN15 SPI2_CS0
PIN16 SPI2_MOSI

UART: x1, UART1 and UART2

PIN8   UART2_TX
PIN10  UART2_RX
PIN18  UART2_RTS
PIN22  UART2_CTS

PWM: x2, PWM0 and PWM1

PIN32 PWM0
PIN33 PWM1

Test

test gpio

Use mraa-gpio to test

vms@vms-ROCK-Pi-X:~$ mraa-gpio list
01        3.3v: 
02          5v: 
03    I2C2_SDA: I2C  
05    I2C2_SCL: I2C  
06         GND: 
07   ISH_GPIO0: GPIO I2C  
08    UART2_TX: UART 
09         GND: 
10    UART2_RX: UART 
11    SPI2_CLK: SPI  UART 
12   GPIO_DFX3: GPIO 
13   SPI2_MISO: SPI  UART 
14         GND: 
15    SPI2_CS0: SPI  
16   SPI2_MOSI: GPIO SPI  
17       +3.3V: 
18   UART2_RTS: UART 
19    SPI_MOSI: I2C  SPI  
20         GND: 
21    SPI_MISO: GPIO SPI  
22   UART2_CTS: UART 
23     SPI_CLK: I2C  SPI  
24   ISH_GPIO1: GPIO 
25         GND: 
26   ISH_GPIO4: GPIO 
27   I2C5_DATA: I2C  
28    I2C5_CLK: I2C  
29   ISH_GPIO2: GPIO 
31   ISH_GPIO3: GPIO 
32        PWM0: PWM  
33        PWM1: GPIO PWM  UART 
34         GND: 
35    I2S1_FRM: 
36    I2S1_CLK: 
37  ISH_GPIO13: GPIO 
38     I2S1_RX: 
39         GND: 
40     I2S1_TX: 
vms@vms-ROCK-Pi-X:~$ 
vms@vms-ROCK-Pi-X:~$ sudo mraa-gpio set 7 1   //pin40 pull high
vms@vms-ROCK-Pi-X:~$ cat /sys/class/gpio/gpio335/value
1
vms@vms-ROCK-Pi-X:~$ sudo mraa-gpio set 7 0   //pin40 pull low
vms@vms-ROCK-Pi-X:~$ cat /sys/class/gpio/gpio335/value
0

test i2c

Use mraa-i2c to test, we must have a i2c slave device , for example, we use I2C EEPROM:

vms@vms-ROCK-Pi-X:~$ mraa-i2c list
Bus   0: id=02 type=linux  default
Bus   1: id=05 type=linux
vms@vms-ROCK-Pi-X:~$ sudo mraa-i2c detect 0                                                                        
00: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- 18 -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: 50 51 52 53 54 55 56 57 -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
vms@vms-ROCK-Pi-X:~$ sudo mraa-i2c set 0 0x50 0x10 0x55
Device 50, Register = 10, Value = 55
vms@vms-ROCK-Pi-X:~$ sudo mraa-i2c get 0 0x50 0x10
Register 0X10 = 0X55
vms@vms-ROCK-Pi-X:~$ 

test Uart

Connect Rock Pi X to PC via serial cable, Open minicom in PC :

PC@MYPC:~$ sudo minicom /dev/ttyUSB0

Use mraa-uart tool to send information on rockpix, and view the received information on pc :

  • On Rock Pi X
vms@vms-ROCK-Pi-X:~$ sudo mraa-uart dev 0 baud 1500000 send  data
  • In minicom of PC
Welcome to minicom 2.7.1

OPTIONS: I18n 
Compiled on Aug 13 2017, 15:25:34.
Port /dev/ttyUSB0, 10:22:25

Press CTRL-A Z for help on special keys

data

Compilation example

Install compiler and project builder

Install g++ compiler and cmake project builder

vms@vms-ROCK-Pi-X:~$ sudo apt-get install cmake g++

Configure Java environment variables :

vms@vms-ROCK-Pi-X:~$ sudo su     #password: rock
vms@vms-ROCK-Pi-X:~# vim ./.bashrc
  ...
  export JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-arm64
  export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
  export PATH=${JAVA_HOME}/bin:$PATH

  export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

vms@vms-ROCK-Pi-X:~# source ./.bashrc
vms@vms-ROCK-Pi-X:~# cp /usr/local/share/mraa . -r
vms@vms-ROCK-Pi-X:~# cd mraa/examples/
vms@vms-ROCK-Pi-X:~/mraa/examples# mkdir build 
vms@vms-ROCK-Pi-X:~/mraa/examples# cd build
vms@vms-ROCK-Pi-X:~/mraa/examples/build# cmake ..; make
...
[ 97%] Building CXX object c++/CMakeFiles/i2c_cpp.dir/i2c.o
[100%] Linking CXX executable i2c_cpp
[100%] Built target i2c_cpp
vms@vms-ROCK-Pi-X:~/mraa/examples/build# ls 
CMakeCache.txt  CMakeFiles  Makefile  c  c++  cmake_install.cmake  java

After compiling, you can see that C, C + + and Java are generated. Let's take a look at the example of using Java.

Example of running Java

Go to the Java example directory and use the Java command to run the .jar package.

vms@vms-ROCK-Pi-X:~/mraa/examples/build# cd java/
vms@vms-ROCK-Pi-X:~/mraa/examples/build/java# ls 
AioA0         CMakeFiles  GpioMmapped  Isr         UartExample
BlinkIO       CyclePwm3   GpioRead6    Makefile    cmake_install.cmake
BlinkOnboard  Example     HelloEdison  SpiMAX7219
Bmp85         FTDITest    I2cCompass   SpiMCP4261
vms@vms-ROCK-Pi-X:~/mraa/examples/build/java# java -jar GpioMmapped/GpioMmapped.jar
hello mraa
Version: v2.1.0-7-g9d7131e
Platform: ROCK PI X


Look, you have successfully run it. Next, you can try to write a Java demo yourself. Viewing these .hpp files can help you write your own demo

vms@vms-ROCK-Pi-X:/usr/local/include/mraa# ls 
aio.h       gpio.h    iio.hpp               led.hpp  types.h    uart_ow.hpp
aio.hpp     gpio.hpp  iio_kernel_headers.h  pwm.h    types.hpp
common.h    i2c.h     initio.h              pwm.hpp  uart.h
common.hpp  i2c.hpp   initio.hpp            spi.h    uart.hpp
firmata.h   iio.h     led.h                 spi.hpp  uart_ow.h
vms@vms-ROCK-Pi-X:/usr/local/include/mraa#

More examples

More examples (including examples written in python and c++) can be found at:

/usr/local/share/mraa/examples/