ROCK PI X 在Linux 下的GIPO访问例子
https://wiki.radxa.com/RockpiX/dev/libmraaLibmraa-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:PIN7ISH_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, I2C1PIN3 I2C2_SDA
PIN5 I2C2_SCL
PIN19 ISH_I2C1_DATA
PIN23 ISH_I2C1_CLKSPI: x1, SPI0(Pin#11/13/15/27)PIN11 SPI2_CLK
PIN13 SPI2_MISO
PIN15 SPI2_CS0
PIN16 SPI2_MOSIUART: x1, UART1 and UART2PIN8 UART2_TX
PIN10UART2_RX
PIN18UART2_RTS
PIN22UART2_CTSPWM: x2, PWM0 and PWM1PIN32 PWM0
PIN33 PWM1测试test gpioUse mraa-gpio to testvms@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: SPIUART
12 GPIO_DFX3: GPIO
13 SPI2_MISO: SPIUART
14 GND:
15 SPI2_CS0: SPI
16 SPI2_MOSI: GPIO SPI
17 +3.3V:
18 UART2_RTS: UART
19 SPI_MOSI: I2CSPI
20 GND:
21 SPI_MISO: GPIO SPI
22 UART2_CTS: UART
23 SPI_CLK: I2CSPI
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 PWMUART
34 GND:
35 I2S1_FRM:
36 I2S1_CLK:
37ISH_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=linuxdefault
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 Xvms@vms-ROCK-Pi-X:~$ sudo mraa-uart dev 0 baud 1500000 senddataIn minicom of PCWelcome 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
Linking CXX executable i2c_cpp
Built target i2c_cpp
vms@vms-ROCK-Pi-X:~/mraa/examples/build# ls
CMakeCache.txtCMakeFilesMakefilecc++cmake_install.cmakejava编译后,您可以看到生成了C,C ++和Java。 让我们看一下使用Java的示例。Example of running JavaGo 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 CMakeFilesGpioMmappedIsr UartExample
BlinkIO CyclePwm3 GpioRead6 Makefile cmake_install.cmake
BlinkOnboardExample HelloEdisonSpiMAX7219
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.hpptypes.h uart_ow.hpp
aio.hpp gpio.hppiio_kernel_headers.hpwm.h types.hpp
common.h i2c.h initio.h pwm.hppuart.h
common.hppi2c.hpp initio.hpp spi.h uart.hpp
firmata.h iio.h led.h spi.hppuart_ow.h
vms@vms-ROCK-Pi-X:/usr/local/include/mraa#更多例子可以在以下位置找到更多示例(包括用python和c ++编写的示例):/usr/local/share/mraa/examples/
python下,测试I2C正常,
Traceback (most recent call last):
File "test.py", line 1, in <module>
import mraa
ModuleNotFoundError: No module named 'mraa'
没mraa模块,这个是libmraa带的吗
页:
[1]