https://wiki.radxa.com/RockpiX/dev/libmraa
Libmraa-rockpiX
安装 libmraaWe need to download the deb installation package first, and then install it: - vms@vms-ROCK-Pi-X:~$ wget https://dl.radxa.com/rockpix/packages/libmraa-rockpix.deb
- vms@vms-ROCK-Pi-X:~$ sudo dpkg -i libmraa-rockpix.deb
- vms@vms-ROCK-Pi-X:~$ sudo apt-get install -f -y
复制代码 启用接口
请参阅ROCK Pi X GPIO引脚分配。 ROCK Pi X具有一个40针扩展接头。 每个插针均按颜色区分。
Hardware V1.0/V1.110 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 测试 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
复制代码
测试I2CUse 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:~$
复制代码
测试UartConnect Rock Pi X to PC via serial cable, Open minicom in PC : - PC@MYPC:~$ sudo minicom /dev/ttyUSB0
复制代码使用mraa-uart工具在rockpix上发送信息,并在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
复制代码
编译例子 安装编译器和项目构建器 安装g ++编译器和cmake项目构建器 - vms@vms-ROCK-Pi-X:~$ sudo apt-get install cmake g++
复制代码配置Java环境变量: - 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
复制代码编译后,您可以看到生成了C,C ++和Java。 让我们看一下使用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
复制代码看,您已经成功运行了它。 接下来,您可以尝试自己编写Java演示。 查看这些.hpp文件可以帮助您编写自己的演示 - 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#
复制代码更多例子 可以在以下位置找到更多示例(包括用python和c ++编写的示例): - /usr/local/share/mraa/examples/
复制代码
|