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

RockpiE/dev/libmraa

< RockpiE‎ | dev
Revision as of 10:10, 12 June 2020 by Shine (Talk | contribs)

    ROCK Pi E >  Development >  libmraa

Libmraa-rockpie

Install libmraa

Modify your /etc/apt/sources.list.d/apt-radxa-com.list as follow :

#deb http://apt.radxa.com/buster-stable/ buster main
deb http://apt.radxa.com/buster-testing/ buster main


Get the pub key :

wget -O -  apt.radxa.com/buster-testing/public.key | sudo apt-key add -


Update APT package information :

sudo apt-get update


Install libmraa :

sudo apt-get install libmraa-rockpie


Enable interface

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

Hardware V1.0/V1.1

25 GPIO:

PIN3   GPIO2_A4
PIN5   GPIO2_A5
PIN7   GPIO3_A4
PIN8   GPIO2_A0
PIN10 GPIO2_A1
PIN11 GPIO3_A0
PIN12 GPIO2_D2
PIN13 GPIO3_B0
PIN15 GPIO3_A2
PIN19 GPIO0_D3
PIN21 GPIO2_C3
PIN22 GPIO2_B4
PIN23 GPIO1_D4
PIN24 GPIO2_A3
PIN26 GPIO2_C7
PIN27 GPIO3_A1
PIN28 GPIO2_C1
PIN29 GPIO2_C0
PIN31 GPIO2_B7
PIN32 GPIO3_A6
PIN33 GPIO2_C2
PIN36 GPIO2_C5
PIN37 GPIO2_A2
PIN38 GPIO2_C4
PIN40 GPIO2_C6

I2C: x1, I2C1

PIN3 I2C1_SDA
PIN5 I2C1_SCL

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

PIN11 SPI_CLK_M2
PIN13 SPI_CSN0_M2
PIN15 SPI_RXD_M2
PIN27 SPI_TXD_M2

UART: x1, UART1 and UART2

PIN7    UART1_TX
PIN32  UART1_RX
PIN8    UART2_TX_M1
PIN10  UART2_RX_M1

ADC_IN1: x1, ADC_IN1

PIN35  ADC_IN1

Modify /boot/uEnv.txt to enable uart1 and spi0 for test,as follow :

verbosity=7
fdtfile=rockchip/rk3328-rock-pi-e.dtb
console=ttyS2,1500000n8
overlays=rk3328-uart2 rk3328-spi-spidev rk3328-uart1
param_spidev_spi_bus=0
param_spidev_spi_cs=0
param_spidev_max_freq=10000000
initrdsize=0x655f2d
kernelversion=4.4.194-12-rockchip-g615ae7431150
initrdimg=initrd.img-4.4.194-12-rockchip-g615ae7431150
kernelimg=vmlinuz-4.4.194-12-rockchip-g615ae7431150
rootuuid=6bdd02ee-ae60-404d-99c9-913f3f1bffb1

then reboot


Test

test gpio

Use mraa-gpio to test

rock@rockpie:~$ mraa-gpio list
01         3V3: 
02          5V: 
03        SDA1: GPIO I2C  
04          5V: 
05        SCL1: GPIO I2C  
06         GND: 
07        TXD1: GPIO SPI  
08        TXD2: GPIO UART 
09         GND: 
10        RXD2: GPIO UART 
11  SPI_CLK_M2: GPIO PWM  
12    GPIO2_D2: GPIO 
13 SPI_CSN0_M2: GPIO PWM  
14         GND: 
15  SPI_RXD_M2: GPIO 
16     USB20DM: GPIO 
17         3V3: 
18     USB20DP: GPIO 
19    GPIO0_D3: GPIO SPI  UART 
20         GND: 
21    GPIO2_C3: GPIO SPI  UART 
22 SPI_CSN1_M0: GPIO 
23    GPIO1_D4: GPIO SPI  
24    GPIO2_A3: GPIO SPI  
25         GND: 
26    GPIO2_C7: AIO  
27  SPI_TXD_M2: GPIO I2C  
28    GPIO2_C1: GPIO I2C  
29    GPIO2_C0: GPIO I2C  SPI  
30         GND: 
31    GPIO2_B7: GPIO I2C  SPI  
32    UART1_RX: GPIO 
33    GPIO2_C2: GPIO SPI  
34         GND: 
35     ADC_IN1: AIO  
36    GPIO2_C5: GPIO 
37    GPIO2_A2: GPIO 
38    GPIO2_C4: GPIO 
39         GND: 
40    GPIO2_C6: GPIO 
rock@rockpie:~$ 
rock@rockpie:~$ sudo mraa-gpio set 23 1   //pin40 pull high  
rock@rockpie:~$ sudo mraa-gpio set 23 0   //pin40 pull low

test i2c

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

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

test spi

fristly, modify /boot/uEnv.txt to enable the spi0, The changes are as follows :

rock@rockpie:~$ cat /boot/uEnv.txt 
verbosity=7
fdtfile=rockchip/rk3328-rock-pi-e.dtb
console=ttyS2,1500000n8
overlays=rk3328-uart2 rk3328-spi-spidev
param_spidev_spi_bus=0
param_spidev_spi_cs=0
param_spidev_max_freq=10000000
initrdsize=0x655f2d
kernelversion=4.4.194-12-rockchip-g615ae7431150
initrdimg=initrd.img-4.4.194-12-rockchip-g615ae7431150
kernelimg=vmlinuz-4.4.194-12-rockchip-g615ae7431150
rootuuid=6bdd02ee-ae60-404d-99c9-913f3f1bffb1
rock@rockpie:~$ 

After modification, you need to reboot

use c to test spi,compile spi.c.

  root@localhost:~# cat spi.c
  #include <signal.h>
  #include <stdlib.h>
  #include <unistd.h>
  
  /* mraa header */
  #include "mraa/spi.h"
  
  /* SPI declaration */
  #define SPI_BUS 0
  
  /* SPI frequency in Hz */
  #define SPI_FREQ 400000
  int
  main(int argc, char** argv)
  {
      mraa_result_t status = MRAA_SUCCESS;
      mraa_spi_context spi;
      int i, j;
  
      /* initialize mraa for the platform (not needed most of the times) */
      mraa_init();
  
      //! [Interesting]
      /* initialize SPI bus */
      spi = mraa_spi_init(SPI_BUS);
      if (spi == NULL) {
          fprintf(stderr, "Failed to initialize SPI\n");
          mraa_deinit();
          return EXIT_FAILURE;
      }
  
      /* set SPI frequency */
      status = mraa_spi_frequency(spi, SPI_FREQ);
      if (status != MRAA_SUCCESS)
          goto err_exit;
  
      /* set big endian mode */
      status = mraa_spi_lsbmode(spi, 0);
      if (status != MRAA_SUCCESS) {
          goto err_exit;
      }
      while(1) {
          printf("0x%x\n",mraa_spi_write(spi, 0xaa));
      }
  err_exit:
      mraa_result_print(status);
  
      /* stop spi */
      mraa_spi_stop(spi);
  
      /* deinitialize mraa for the platform (not needed most of the times) */
      mraa_deinit();
  
      return EXIT_FAILURE;
  }
  root@localhost:~# gcc spi.c -lmraa


then short pin15 and pin27 and run a.out

  root@localhost:~# ./a.out 
  0xaa
  0xaa
  ......

test Uart

Enable Uart1 for uart test, The changes are as follows :

rock@rockpie:~$ cat /boot/uEnv.txt 
verbosity=7
fdtfile=rockchip/rk3328-rock-pi-e.dtb
console=ttyS2,1500000n8
overlays=rk3328-uart2 rk3328-uart1
initrdsize=0x655f2d
kernelversion=4.4.194-12-rockchip-g615ae7431150
initrdimg=initrd.img-4.4.194-12-rockchip-g615ae7431150
kernelimg=vmlinuz-4.4.194-12-rockchip-g615ae7431150
rootuuid=6bdd02ee-ae60-404d-99c9-913f3f1bffb1
rock@rockpie:~$ 

then reboot and short pin7 and pin32. use ssh connect to rockpi4,we must have 2 windows,one is for send data,anothor is for receive.

send command follow:

sudo mraa-uart dev 0 baud 1500000 send  data

receive command follow:

 sudo mraa-uart dev 0 baud 1500000 recv  1000

the receive window will show the data

test adc

Firstly, short pin23 and pin35, Compile mraa example file to test, as follow:

rock@rockpie:~$ cp /usr/local/share/mraa . -r
rock@rockpie:~$ cd mraa/examples/
rock@rockpie:~/mraa/examples$ ls 
CMakeLists.txt  c  c++  python
rock@rockpie:~/mraa/examples$ mkdir build
rock@rockpie:~/mraa/examples$ cd build
rock@rockpie:~/mraa/examples/build$ sudo apt-get install cmake
rock@rockpie:~/mraa/examples/build$ sudo apt-get install g++
rock@rockpie:~/mraa/examples/build$ cmake ..
rock@rockpie:~/mraa/examples/build$ cd c; make
rock@rockpie:~/mraa/examples/build/c$ sudo su
[sudo] password for rock:							#password:rock
root@rockpie:/home/rock/mraa/examples/build/c# ./gpio &
[1] 1250
root@rockpie:/home/rock/mraa/examples/build/c# ./aio
ADC A0 read 3FF - 1023
ADC A0 read float - 1.00000
ADC A0 read 3FF - 1023
ADC A0 read float - 1.00000
...
ADC A0 read 0 - 0
ADC A0 read float - 0.00000
ADC A0 read 0 - 0
ADC A0 read float - 0.00000


More examples

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

/usr/local/share/mraa/examples/