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

Difference between revisions of "RockpiS/dev/libmraa"

< RockpiS‎ | dev
(Enable interface)
m
 
(83 intermediate revisions by 5 users not shown)
Line 3: Line 3:
 
{{Languages|rockpiS/dev/libmraa}}
 
{{Languages|rockpiS/dev/libmraa}}
  
      [[rockpiS | ROCK Pi S]] > [[rockpiS/dev | Development]] > [[rockpiS/dev/libmraa  | Install Libmraa ]]
+
    [[rockpiS | ROCK Pi S]] > [[rockpiS/dev | Development]] > [[rockpiS/dev/libmraa  | Install Libmraa ]]
  
 +
=== Libmraa on ROCK Pi S ===
  
= Libmraa on ROCK Pi S =
+
This guide describes how to use libmraa on ROCK Pi S.
  
Package libmraa-rockpis is in Radxa APT bionic-testing and stretch-testing repositories.
+
==== Install essential packages ====
  
Below is the instructions of how to install  '''libmraa''' and use it.
+
Package libmraa is in the Radxa APT bionic-stable and buster-stable repositories.
  
== Install essential packages ==
+
Execute the following commands to add Radxa APT
  
Edit file /etc/apt/sources.list.d/apt-radxa-com.list and add the following:
+
rock@rockpis:~$ export DISTRO=bionic-stable      # for Bionic
  
'''For Debian Stretch'''
+
or
  
    deb http://apt.radxa.com/stretch-testing/ stretch main
+
rock@rockpis:~$ export DISTRO=buster-stable      # for Buster
 +
rock@rockpis:~$ echo "deb http://apt.radxa.com/$DISTRO/ ${DISTRO%-*} main" | sudo tee -a /etc/apt/sources.list.d/apt-radxa-com.list
  
'''For Ubuntu bionic'''
+
Get the pub key
  
    deb http://apt.radxa.com/bionic-testing/ bionic main
+
rock@rockpis:~$ wget -O -  apt.radxa.com/buster-testing/public.key | sudo apt-key add -
 
+
Get the pub key  
+
    wget -O -  apt.radxa.com/stretch-testing/public.key | sudo apt-key add -
+
 
+
Update 
+
    sudo apt-get update && sudo apt-get upgrade
+
  
 
Install essential packages:
 
Install essential packages:
    sudo apt-get install -y rockchip-fstab && sudo apt-get install -y rockchip-overlay && sudo apt-get install -y rockpis-dtbo
 
  
Install the latest u-boot and kernel:
+
rock@rockpis:~$ sudo apt-get update
    apt-get install rockpis-rk-u-boot-latest
+
rock@rockpis:~$ sudo apt-get install -y rockchip-overlay libmraa # libmraa version: >=0.4
 +
rock@rockpis:~$ sudo apt-get install -y linux-4.4-rock-pi-s-latest # ROCK Pi S kernel version: >= 4.4.143-47
  
Manually run the u-boot flash script
+
Install compiler:
    /usr/local/sbin/rockpis_upgrade_bootloader.sh
+
rock@rockpis:~$ sudo apt install -y build-essential
  
Type '''YES''' to perform the uboot.img flashing.
+
==== Enable interface ====
  
Install kernel 
+
See ROCK Pi S [[rockpiS/hardware/gpio | GPIO pintout]]. ROCK Pi S has a 26-pin colorful expansion header. Each pin is distinguished by color. mraa define is shown below: 
    apt-get install linux-base
+
    apt-get install linux-4.4-rockpis-latest
+
  
After installation, check file '''/boot/extlinux/extlinux.conf'''. It lists all kernel version installed in ROCK Pi S. The kernel corresponding to the first label is the newest version and the first boot option.
+
===== Hardware V1.2 =====
 
+
Install libmraa-rockpis
+
    apt-get install libmraa-rockpis
+
 
+
== Enable interface ==  
+
See ROCK Pi S [[rockpiS/hardware/gpio | GPIO pintout]].
+
 
+
=== Hardware V10 ===
+
  
 
16 GPIO:
 
16 GPIO:
Line 73: Line 59:
 
     PIN26      GPIO1_B2
 
     PIN26      GPIO1_B2
  
4 I2C:
+
3 I2C:
 
     PIN23      I2C'''0'''_SDA
 
     PIN23      I2C'''0'''_SDA
 
     PIN24      I2C'''0'''_SCL
 
     PIN24      I2C'''0'''_SCL
 
     PIN3      I2C'''1'''_SCL
 
     PIN3      I2C'''1'''_SCL
 
     PIN5      I2C'''1'''_SDA
 
     PIN5      I2C'''1'''_SDA
     PIN13      I2C'''2'''_SDA
+
     PIN13      I2C'''3'''_SDA
     PIN15     I2C'''2'''_SCL
+
     PIN15      I2C'''3'''_SCL
    PIN12     I2C'''3'''_SCL
+
 
    PIN26      I2C'''3'''_SDA
+
1 SPI:
 
+
     PIN19      SPI'''2'''TX       //must disable i2c0
2 SPI:
+
     PIN21      SPI'''2'''RX       //must disable i2c0
    PIN9      SPI'''0'''RX
+
    PIN11      SPI'''0'''TX
+
    PIN13      SPI'''0'''CLK
+
    PIN15      SPI'''0'''CSN
+
     PIN19      SPI'''2'''TX
+
     PIN21      SPI'''2'''RX
+
 
     PIN23      SPI'''2'''CLK
 
     PIN23      SPI'''2'''CLK
 
     PIN24      SPI'''2'''CSN
 
     PIN24      SPI'''2'''CSN
  
 
3 UART:
 
3 UART:
     PIN9       UART'''0'''_TX
+
     PIN8       UART'''0'''_TX
     PIN11     UART'''0'''_RX
+
     PIN10     UART'''0'''_RX
 
     PIN23      UART'''1'''_TX
 
     PIN23      UART'''1'''_TX
 
     PIN24      UART'''1'''_RX
 
     PIN24      UART'''1'''_RX
Line 101: Line 81:
 
     PIN21      UART'''2'''_TX
 
     PIN21      UART'''2'''_TX
  
3 PWM:
+
2 PWM:
     PIN22     PWM'''1'''
+
     PIN11     PWM'''2'''
     PIN26      PWM'''2'''
+
    PIN13      PWM'''3'''
     PIN12     PWM'''3'''
+
 
 +
1 ADC:
 +
     PIN26     ADC_IN0          //the measure voltage must lower than 1.8v
 +
 
 +
For those ROCK Pi S system images released after March 1st, 2020, the configuration file is /boot/uEnv.txt. For more details, follow this guide, [https://wiki.radxa.com/Device-tree-overlays Device tree overlays].
 +
 
 +
For those ROCK Pi S system images released before March 1st, 2020, the configuration file is /boot/hw_intfc.conf.
 +
 
 +
===== Hardware V1.3=====
 +
 
 +
28 GPIO:
 +
    PIN03      GPIO2_A2
 +
    PIN05      GPIO2_B0
 +
    PIN07      GPIO2_B3
 +
    PIN08      GPIO2_A1
 +
    PIN09      GPIO4_C4
 +
    PIN11      GPIO4_C2
 +
    PIN12      GPIO4_A3
 +
    PIN13      GPIO4_C6
 +
    PIN15      GPIO4_C5
 +
    PIN16      GPIO4_D2
 +
    PIN18      GPIO4_D4
 +
    PIN19      GPIO1_B0
 +
    PIN21      GPIO1_A7
 +
    PIN22      GPIO4_D5
 +
    PIN23      GPIO1_B1
 +
    PIN24      GPIO1_D1
 +
    PIN28      GPIO2_B5
 +
    PIN30      GPIO2_B6
 +
    PIN32      GPIO2_B7
 +
    PIN34      GPIO2_C0
 +
    PIN39      GPIO3_B5
 +
    PIN40      GPIO3_B4
 +
    PIN41      GPIO3_B3
 +
    PIN42      GPIO3_B2
 +
    PIN43      GPIO2_B4
 +
    PIN44      GPIO2_B3
 +
    PIN45      GPIO2_B0
 +
    PIN46      GPIO2_A6
 +
 
 +
3 I2C:
 +
    PIN23      I2C'''0'''_SDA  //must disable SPI2 UART1
 +
    PIN24      I2C'''0'''_SCL  //must disable SPI2 UART1
 +
    PIN3      I2C'''1'''_SCL
 +
    PIN5      I2C'''1'''_SDA
 +
    PIN13      I2C'''3'''m0_SDA 
 +
    PIN15      I2C'''3'''m0_SCL
 +
    PIN40      I2C'''3'''m1_SDA    //must disable SPI1 UART3
 +
    PIN39      I2C'''3'''m1_SCL    //must disable SPI1 UART3
 +
 
 +
2 SPI:
 +
    PIN19      SPI'''2'''TX        //must disable i2c0 UART1
 +
    PIN21      SPI'''2'''RX      //must disable i2c0 UART1
 +
    PIN23      SPI'''2'''CLK
 +
    PIN24      SPI'''2'''CSN
 +
    PIN40      SPI'''1'''TX        //must disable i2c3  UART3
 +
    PIN42      SPI'''1'''RX        //must disable i2c3  UART3
 +
    PIN41      SPI'''1'''CLK
 +
    PIN39      SPI'''1'''CSN
 +
 
 +
4 UART:
 +
    PIN8      UART'''0'''_TX 
 +
    PIN10      UART'''0'''_RX
 +
    PIN23      UART'''1'''_TX
 +
    PIN24      UART'''1'''_RX
 +
    PIN19      UART'''2'''_RX  //must disable SPI2 i2c0
 +
    PIN21      UART'''2'''_TX  //must disable SPI2 i2c0
 +
    PIN40      UART'''3'''_RX  //must disable SPI1 i2c3
 +
    PIN39      UART'''3'''_TX  //must disable SPI1 i2c3
 +
 
 +
2 PWM:
 +
    PIN11     PWM'''2'''
 +
     PIN13     PWM'''3'''
 +
 
 +
1 ADC:
 +
    PIN26      ADC_IN0          //the measure voltage must lower than 1.8v
 +
 
 +
For those ROCK Pi S system images released after March 1st, 2020, the configuration file is /boot/uEnv.txt. For more details, follow this guide, [https://wiki.radxa.com/Device-tree-overlays Device tree overlays].
 +
 
 +
For those ROCK Pi S system images released before March 1st, 2020, the configuration file is /boot/hw_intfc.conf.
 +
 
 +
==== Test ====
 +
 
 +
Package libmraa provides some examples for testing spi, uart, i2c, gpio, etc. We way use the c files in /usr/local/share/mraa/examples/c.
 +
 
 +
And we copy them to home directory.
 +
 
 +
rock@rockpis:~/mraa-examples$ cp -av /usr/local/share/mraa/examples/c /home/rock/mraa-examples
 +
 
 +
You should pay more attention to the Black Bold words when modifying configuration file /boot/uEnv.txt.
 +
 
 +
===== GPIO test =====
 +
 
 +
Use '''mraa-gpio tool''' to test
 +
 
 +
root@rockpis:~# mraa-gpio list
 +
01        3V3:
 +
02          5V:
 +
03    I2C_SDA: GPIO I2C 
 +
04          5V:
 +
05    I2C_SCL: GPIO I2C 
 +
06        GND:
 +
07 I2S0_8CH_MC: GPIO
 +
08    UART0_TX: GPIO UART
 +
09        GND:
 +
10    UART0_RX: GPIO UART
 +
11 PWM2,I2C3_S: GPIO I2C  PWM 
 +
12 I2S0_8CH_SC: GPIO
 +
13 PWM3,I2C3_S: GPIO I2C  PWM 
 +
14        GND:
 +
15    SPDIF_TX: GPIO
 +
16 I2S0_8CH_SD: GPIO
 +
17        3V3:
 +
18 I2S0_8CH_SD: GPIO
 +
19 UART1_RTSN,: GPIO SPI  UART
 +
20        GND:
 +
21 UART1_CTSN,: GPIO SPI  UART
 +
22 I2S0_8CH_LR: GPIO
 +
23 UART1_RX,I2: GPIO I2C  SPI  UART
 +
24 UART1_TX,I2: GPIO I2C  SPI  UART
 +
25        GND:
 +
26    ADC_IN0: AIO
 +
root@rockpis:~# mraa-gpio set 15 1          #pin15 pull high
 +
root@rockpis:~# mraa-gpio set 15 0          #pin15 pull low
 +
 
 +
===== PWM test =====
 +
 
 +
ROCK Pi S V1.2 provides 2 PWM, PWM2 and PWM3. It is necessary to enable PWM1, PWM2 and PWM3 at the same time if you need PWM function.
 +
 
 +
Firstly, modify the /boot/uEnv.txt file to add the following
 +
 
 +
root@rockpis:~# cat /boot/uEnv.txt
 +
verbosity=7
 +
'''overlay_prefix=rockchip'''
 +
'''rootfstype=ext4'''
 +
fdtfile=rockchip/rk3308-rock-pi-s.dtb
 +
overlays=rk3308-console-on-uart0 '''rk3308-pwm1 rk3308-pwm2 rk3308-pwm3'''
 +
rootuuid=37055840-4ec4-444f-979b-9e47ee4bd848
 +
initrdsize=0x64d1d4
 +
kernelversion=4.4.143-47-rockchip-g495ff574976c
 +
initrdimg=initrd.img-4.4.143-47-rockchip-g495ff574976c
 +
kernelimg=vmlinuz-4.4.143-47-rockchip-g495ff574976c
 +
 
 +
 
 +
Modify the macro PWM in /home/rock/mraa-examples/pwm.c as follows to test PWM2. To test PWM3, change '''#define PWM 11''' to '''#define PWM 13'''.
 +
 
 +
'''/* PWM declaration */'''
 +
'''#define PWM 11'''
 +
 
 +
Save and compile pwm.c
 +
rock@rockpis:~/mraa-examples$ gcc -o pwm pwm.c -lmraa
 +
rock@rockpis:~/mraa-examples$ sudo ./pwm
 +
PWM value is 0.010015
 +
PWM value is 0.019985
 +
PWM value is 0.030000
 +
PWM value is 0.040014
 +
PWM value is 0.049984
 +
PWM value is 0.059999
 +
 
 +
===== I2C test =====
 +
ROCK Pi S V1.2 provides 3 I2C,There are  I2C0 ,I2C1, I2C3.
 +
ROCK Pi S V1.3 provides 3 I2C,There are  I2C0 ,I2C1, I2C3m0,I2C3m1.
 +
If you need the I2C function, you can turn on one or more of them,but you can just choose one between I2C3m0 and I2C3m1 .
 +
 
 +
Firstly, modify the /boot/uEnv.txt file to add the following
 +
 
 +
root@rockpis:~# cat /boot/uEnv.txt
 +
verbosity=7
 +
'''overlay_prefix=rockchip'''
 +
'''rootfstype=ext4'''
 +
fdtfile=rockchip/rk3308-rock-pi-s.dtb
 +
overlays=rk3308-console-on-uart0  '''rk3308-i2c0 rk3308-i2c1 rk3308-i2c3-m0'''
 +
rootuuid=37055840-4ec4-444f-979b-9e47ee4bd848
 +
initrdsize=0x64d1d4
 +
kernelversion=4.4.143-47-rockchip-g495ff574976c
 +
initrdimg=initrd.img-4.4.143-47-rockchip-g495ff574976c
 +
kernelimg=vmlinuz-4.4.143-47-rockchip-g495ff574976c
 +
 
 +
We use  MPU6050 tets i2c.
 +
Modify the macro  MPU6050 in '''/home/rock/mraa-examples/i2c_mpu6050.c''' ,as follows to test I2C0. To test I2C1 and I2C3, change '''#define I2C_BUS 0''' to '''#define I2C_BUS 1'''  or'''#define I2C_BUS 3''' .
 +
 +
  /* mraa header */
 +
  #include "mraa/i2c.h"
 +
  '''#define I2C_BUS 0'''
 +
 
 +
rock@rockpis:~/mraa-examples$ gcc -o i2c_mpu6050 i2c_mpu6050.c  -lmraa
 +
rock@rockpis:~/mraa-examples$ sudo ./i2c_mpu6050
 +
accel: x:0 y:0 z:0
 +
gyro: x:-10 y:1 z:7
 +
 
 +
accel: x:0 y:0 z:0
 +
gyro: x:107 y:-12 z:69
 +
   
 +
accel: x:0 y:0 z:0
 +
gyro: x:6 y:136 z:-50
 +
   
 +
accel: x:0 y:0 z:0
 +
gyro: x:-5 y:48 z:-103
 +
     
 +
accel: x:0 y:0 z:0
 +
gyro: x:3 y:3 z:5
 +
 
 +
===== UART test =====
 +
ROCK Pi S V1.2 provides 3 UART,There are  '''uart0''' ,'''uart1''', '''uart2'''.
 +
ROCK Pi S V1.3 provides 4 UART,There are  '''uart0''' ,'''uart1''', '''uart2''', '''uart3''' .
 +
If you need the uart function, you can turn on one or more of them.
 +
 
 +
Firstly, Disable console and enable '''uart0''' for uart test.modify the '''/boot/uEnv.txt''' file to add the following
 +
 
 +
root@rockpis:~# cat /boot/uEnv.txt
 +
verbosity=7
 +
'''overlay_prefix=rockchip'''
 +
'''rootfstype=ext4'''
 +
fdtfile=rockchip/rk3308-rock-pi-s.dtb
 +
'''overlays=rk3308-uart0 rk3308-uart1 rk3308-uart2 rk3308-uart3'''
 +
'''console='''
 +
rootuuid=c3800af9-fa58-4fb3-bb56-e52fd04837ba
 +
initrdsize=0x5c96c3
 +
kernelversion=4.4.143-47-rockchip-g495ff574976c
 +
initrdimg=initrd.img-4.4.143-47-rockchip-g495ff574976c
 +
kernelimg=vmlinuz-4.4.143-47-rockchip-g495ff574976c
 +
 
 +
Here set console to NULL value.
 +
 
 +
then reboot . use '''ssh''' connect to rockpis,we must have '''2 windows''',one is for send data,anothor is for receive.
 +
 
 +
send command follow:
 +
rock@rockpis:~$ sudo mraa-uart '''dev 0''' baud 1500000 send  radxa
 +
 
 +
Another window sets the baud  1500000 and receives the data
 +
 
 +
radxa
 +
 
 +
receive command follow:
 +
rock@rockpis:~$ sudo mraa-uart '''dev 0''' baud 1500000 recv  1000
 +
radxa
 +
 
 +
===== SPI test =====
 +
 
 +
Firstly, modify the '''/boot/uEnv.txt''' file.
 +
 
 +
root@rockpis:~# cat /boot/uEnv.txt
 +
verbosity=7
 +
overlay_prefix=rockchip
 +
rootfstype=ext4
 +
fdtfile=rockchip/rk3308-rock-pi-s.dtb
 +
overlays=rk3308-console-on-uart0 '''rk3308-spi-spidev'''
 +
'''param_spidev_spi_bus=2'''
 +
rootuuid=37055840-4ec4-444f-979b-9e47ee4bd848
 +
initrdsize=0x64d1d4
 +
kernelversion=4.4.143-47-rockchip-g495ff574976c
 +
initrdimg=initrd.img-4.4.143-47-rockchip-g495ff574976c
 +
kernelimg=vmlinuz-4.4.143-47-rockchip-g495ff574976c
 +
 
 +
then execute command, sync, followed by '''reboot'''.
 +
 
 +
Create file test-spi.c and add the following contents.
 +
 
 +
rock@rockpis:~/mraa-examples$ cat test-spi.c
 +
#include <signal.h>
 +
#include <stdlib.h>
 +
#include <unistd.h>
 +
 +
/* mraa header */
 +
#include "mraa/spi.h"
 +
 +
/* SPI declaration */
 +
'''#define SPI_BUS 2'''
 +
 +
/* SPI frequency in Hz */
 +
#define SPI_FREQ 10000000
 +
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;
 +
    }
 +
   
 +
    j = 10;
 +
    while(j) {
 +
  j--;
 +
        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;
 +
}
 +
rock@rockpis:~/mraa-examples$ gcc -o test-spi test-spi.c -lmraa
 +
 
 +
Then short pin19 and pin21 and run  test-spi
 +
 
 +
rock@rockpis:~/mraa-examples$ sudo ./test-spi
 +
0xaa
 +
0xaa
 +
0xaa
 +
0xaa
 +
0xaa
 +
0xaa
 +
0xaa
 +
0xaa
 +
0xaa
 +
0xaa
 +
MRAA: SUCCESS
 +
 
 +
===== ADC test =====
 +
 
 +
connect signal you want to measure, and then compile mraa example c file, aio.c, to test.
  
== Test ==
+
<pre>
=== test gpio ===
+
rock@rockpis:~/mraa-examples$ gcc -o aio aio.c -lmraa
 +
rock@rockpis:~/mraa-examples$ sudo ./aio
 +
ADC A0 read 1A5 - 421
 +
ADC A0 read float - 0.41153
 +
ADC A0 read 1A5 - 421
 +
ADC A0 read float - 0.41153
 +
ADC A0 read 1A5 - 421
 +
ADC A0 read float - 0.41153
 +
ADC A0 read 1A5 - 421
 +
ADC A0 read float - 0.41153
 +
</pre>
  
=== test pwm ===
+
==== Development ====
  
=== test uart ===
+
More introduction of libmraa can look at [http://iotdk.intel.com/docs/master/mraa/index.html libmraa official website].
  
=== test spi ===
+
==== Troubleshooting ====
  
=== test adc ===
+
* Refer [[RockpiS/getting_started/troubleshooting | Troubleshooting page]]
 +
* Post your issue on the forum: https://forum.radxa.com/c/rockpiS

Latest revision as of 09:52, 2 August 2022

    ROCK Pi S >  Development >  Install Libmraa 

Libmraa on ROCK Pi S

This guide describes how to use libmraa on ROCK Pi S.

Install essential packages

Package libmraa is in the Radxa APT bionic-stable and buster-stable repositories.

Execute the following commands to add Radxa APT

rock@rockpis:~$ export DISTRO=bionic-stable      # for Bionic

or

rock@rockpis:~$ export DISTRO=buster-stable      # for Buster
rock@rockpis:~$ echo "deb http://apt.radxa.com/$DISTRO/ ${DISTRO%-*} main" | sudo tee -a /etc/apt/sources.list.d/apt-radxa-com.list

Get the pub key

rock@rockpis:~$  wget -O -  apt.radxa.com/buster-testing/public.key | sudo apt-key add -

Install essential packages:

rock@rockpis:~$ sudo apt-get update
rock@rockpis:~$ sudo apt-get install -y rockchip-overlay libmraa # libmraa version: >=0.4
rock@rockpis:~$ sudo apt-get install -y linux-4.4-rock-pi-s-latest # ROCK Pi S kernel version: >= 4.4.143-47

Install compiler:

rock@rockpis:~$ sudo apt install -y build-essential

Enable interface

See ROCK Pi S GPIO pintout. ROCK Pi S has a 26-pin colorful expansion header. Each pin is distinguished by color. mraa define is shown below:

Hardware V1.2

16 GPIO:

   PIN03      GPIO2_A2
   PIN05      GPIO2_B0
   PIN07      GPIO2_B3
   PIN09      GPIO4_C4
   PIN11      GPIO4_C2
   PIN12      GPIO4_A3
   PIN13      GPIO4_C6
   PIN15      GPIO4_C5
   PIN16      GPIO4_D2
   PIN18      GPIO4_D4
   PIN19      GPIO1_B0
   PIN21      GPIO1_A7
   PIN22      GPIO4_D5
   PIN23      GPIO1_B1
   PIN24      GPIO1_B2
   PIN26      GPIO1_B2

3 I2C:

   PIN23      I2C0_SDA
   PIN24      I2C0_SCL
   PIN3       I2C1_SCL
   PIN5       I2C1_SDA
   PIN13      I2C3_SDA
   PIN15      I2C3_SCL
  

1 SPI:

   PIN19      SPI2TX        //must disable i2c0
   PIN21      SPI2RX        //must disable i2c0
   PIN23      SPI2CLK
   PIN24      SPI2CSN

3 UART:

   PIN8       UART0_TX
   PIN10      UART0_RX
   PIN23      UART1_TX
   PIN24      UART1_RX
   PIN19      UART2_RX
   PIN21      UART2_TX

2 PWM:

   PIN11      PWM2
   PIN13      PWM3

1 ADC:

   PIN26      ADC_IN0          //the measure voltage must lower than 1.8v

For those ROCK Pi S system images released after March 1st, 2020, the configuration file is /boot/uEnv.txt. For more details, follow this guide, Device tree overlays.

For those ROCK Pi S system images released before March 1st, 2020, the configuration file is /boot/hw_intfc.conf.

Hardware V1.3

28 GPIO:

   PIN03      GPIO2_A2
   PIN05      GPIO2_B0
   PIN07      GPIO2_B3
   PIN08      GPIO2_A1
   PIN09      GPIO4_C4
   PIN11      GPIO4_C2
   PIN12      GPIO4_A3
   PIN13      GPIO4_C6
   PIN15      GPIO4_C5
   PIN16      GPIO4_D2
   PIN18      GPIO4_D4
   PIN19      GPIO1_B0
   PIN21      GPIO1_A7
   PIN22      GPIO4_D5
   PIN23      GPIO1_B1
   PIN24      GPIO1_D1
   PIN28      GPIO2_B5
   PIN30      GPIO2_B6
   PIN32      GPIO2_B7
   PIN34      GPIO2_C0
   PIN39      GPIO3_B5
   PIN40      GPIO3_B4
   PIN41      GPIO3_B3
   PIN42      GPIO3_B2
   PIN43      GPIO2_B4
   PIN44      GPIO2_B3
   PIN45      GPIO2_B0
   PIN46      GPIO2_A6

3 I2C:

   PIN23      I2C0_SDA   //must disable SPI2 UART1
   PIN24      I2C0_SCL   //must disable SPI2 UART1
   PIN3       I2C1_SCL
   PIN5       I2C1_SDA
   PIN13      I2C3m0_SDA   
   PIN15      I2C3m0_SCL
   PIN40      I2C3m1_SDA    //must disable SPI1 UART3 
   PIN39      I2C3m1_SCL    //must disable SPI1 UART3 
  

2 SPI:

   PIN19      SPI2TX        //must disable i2c0 UART1 
   PIN21      SPI2RX       //must disable i2c0 UART1 
   PIN23      SPI2CLK
   PIN24      SPI2CSN
   PIN40      SPI1TX        //must disable i2c3  UART3 
   PIN42      SPI1RX        //must disable i2c3  UART3 
   PIN41      SPI1CLK
   PIN39      SPI1CSN

4 UART:

   PIN8       UART0_TX   
   PIN10      UART0_RX
   PIN23      UART1_TX
   PIN24      UART1_RX
   PIN19      UART2_RX  //must disable SPI2 i2c0
   PIN21      UART2_TX   //must disable SPI2 i2c0
   PIN40      UART3_RX  //must disable SPI1 i2c3
   PIN39      UART3_TX   //must disable SPI1 i2c3

2 PWM:

   PIN11      PWM2
   PIN13      PWM3

1 ADC:

   PIN26      ADC_IN0          //the measure voltage must lower than 1.8v

For those ROCK Pi S system images released after March 1st, 2020, the configuration file is /boot/uEnv.txt. For more details, follow this guide, Device tree overlays.

For those ROCK Pi S system images released before March 1st, 2020, the configuration file is /boot/hw_intfc.conf.

Test

Package libmraa provides some examples for testing spi, uart, i2c, gpio, etc. We way use the c files in /usr/local/share/mraa/examples/c.

And we copy them to home directory.

rock@rockpis:~/mraa-examples$ cp -av /usr/local/share/mraa/examples/c /home/rock/mraa-examples

You should pay more attention to the Black Bold words when modifying configuration file /boot/uEnv.txt.

GPIO test

Use mraa-gpio tool to test

root@rockpis:~# mraa-gpio list
01         3V3: 
02          5V: 
03     I2C_SDA: GPIO I2C  
04          5V: 
05     I2C_SCL: GPIO I2C  
06         GND: 
07 I2S0_8CH_MC: GPIO 
08    UART0_TX: GPIO UART 
09         GND: 
10    UART0_RX: GPIO UART 
11 PWM2,I2C3_S: GPIO I2C  PWM  
12 I2S0_8CH_SC: GPIO 
13 PWM3,I2C3_S: GPIO I2C  PWM  
14         GND: 
15    SPDIF_TX: GPIO 
16 I2S0_8CH_SD: GPIO 
17         3V3: 
18 I2S0_8CH_SD: GPIO 
19 UART1_RTSN,: GPIO SPI  UART 
20         GND: 
21 UART1_CTSN,: GPIO SPI  UART 
22 I2S0_8CH_LR: GPIO 
23 UART1_RX,I2: GPIO I2C  SPI  UART 
24 UART1_TX,I2: GPIO I2C  SPI  UART 
25         GND: 
26     ADC_IN0: AIO 
root@rockpis:~# mraa-gpio set 15 1           #pin15 pull high
root@rockpis:~# mraa-gpio set 15 0           #pin15 pull low
PWM test

ROCK Pi S V1.2 provides 2 PWM, PWM2 and PWM3. It is necessary to enable PWM1, PWM2 and PWM3 at the same time if you need PWM function.

Firstly, modify the /boot/uEnv.txt file to add the following

root@rockpis:~# cat /boot/uEnv.txt
verbosity=7
overlay_prefix=rockchip
rootfstype=ext4
fdtfile=rockchip/rk3308-rock-pi-s.dtb
overlays=rk3308-console-on-uart0 rk3308-pwm1 rk3308-pwm2 rk3308-pwm3
rootuuid=37055840-4ec4-444f-979b-9e47ee4bd848
initrdsize=0x64d1d4
kernelversion=4.4.143-47-rockchip-g495ff574976c
initrdimg=initrd.img-4.4.143-47-rockchip-g495ff574976c
kernelimg=vmlinuz-4.4.143-47-rockchip-g495ff574976c


Modify the macro PWM in /home/rock/mraa-examples/pwm.c as follows to test PWM2. To test PWM3, change #define PWM 11 to #define PWM 13.

/* PWM declaration */
#define PWM 11

Save and compile pwm.c

rock@rockpis:~/mraa-examples$ gcc -o pwm pwm.c -lmraa
rock@rockpis:~/mraa-examples$ sudo ./pwm 
PWM value is 0.010015
PWM value is 0.019985
PWM value is 0.030000
PWM value is 0.040014
PWM value is 0.049984
PWM value is 0.059999
I2C test

ROCK Pi S V1.2 provides 3 I2C,There are I2C0 ,I2C1, I2C3. ROCK Pi S V1.3 provides 3 I2C,There are I2C0 ,I2C1, I2C3m0,I2C3m1. If you need the I2C function, you can turn on one or more of them,but you can just choose one between I2C3m0 and I2C3m1 .

Firstly, modify the /boot/uEnv.txt file to add the following

root@rockpis:~# cat /boot/uEnv.txt
verbosity=7
overlay_prefix=rockchip
rootfstype=ext4
fdtfile=rockchip/rk3308-rock-pi-s.dtb
overlays=rk3308-console-on-uart0  rk3308-i2c0 rk3308-i2c1 rk3308-i2c3-m0
rootuuid=37055840-4ec4-444f-979b-9e47ee4bd848
initrdsize=0x64d1d4
kernelversion=4.4.143-47-rockchip-g495ff574976c
initrdimg=initrd.img-4.4.143-47-rockchip-g495ff574976c
kernelimg=vmlinuz-4.4.143-47-rockchip-g495ff574976c

We use MPU6050 tets i2c. Modify the macro MPU6050 in /home/rock/mraa-examples/i2c_mpu6050.c ,as follows to test I2C0. To test I2C1 and I2C3, change #define I2C_BUS 0 to #define I2C_BUS 1 or#define I2C_BUS 3 .

  /* mraa header */
  #include "mraa/i2c.h"
  #define I2C_BUS 0
  
rock@rockpis:~/mraa-examples$ gcc -o i2c_mpu6050 i2c_mpu6050.c  -lmraa
rock@rockpis:~/mraa-examples$ sudo ./i2c_mpu6050
accel: x:0 y:0 z:0
gyro: x:-10 y:1 z:7
  
accel: x:0 y:0 z:0
gyro: x:107 y:-12 z:69
   
accel: x:0 y:0 z:0
gyro: x:6 y:136 z:-50
   
accel: x:0 y:0 z:0
gyro: x:-5 y:48 z:-103
     
accel: x:0 y:0 z:0
gyro: x:3 y:3 z:5
UART test

ROCK Pi S V1.2 provides 3 UART,There are uart0 ,uart1, uart2. ROCK Pi S V1.3 provides 4 UART,There are uart0 ,uart1, uart2, uart3 . If you need the uart function, you can turn on one or more of them.

Firstly, Disable console and enable uart0 for uart test.modify the /boot/uEnv.txt file to add the following

root@rockpis:~# cat /boot/uEnv.txt 
verbosity=7
overlay_prefix=rockchip
rootfstype=ext4
fdtfile=rockchip/rk3308-rock-pi-s.dtb
overlays=rk3308-uart0 rk3308-uart1 rk3308-uart2 rk3308-uart3
console=
rootuuid=c3800af9-fa58-4fb3-bb56-e52fd04837ba
initrdsize=0x5c96c3
kernelversion=4.4.143-47-rockchip-g495ff574976c
initrdimg=initrd.img-4.4.143-47-rockchip-g495ff574976c
kernelimg=vmlinuz-4.4.143-47-rockchip-g495ff574976c

Here set console to NULL value.

then reboot . use ssh connect to rockpis,we must have 2 windows,one is for send data,anothor is for receive.

send command follow:

rock@rockpis:~$ sudo mraa-uart dev 0 baud 1500000 send  radxa

Another window sets the baud 1500000 and receives the data

radxa

receive command follow:

rock@rockpis:~$ sudo mraa-uart dev 0 baud 1500000 recv  1000
radxa
SPI test

Firstly, modify the /boot/uEnv.txt file.

root@rockpis:~# cat /boot/uEnv.txt
verbosity=7
overlay_prefix=rockchip
rootfstype=ext4
fdtfile=rockchip/rk3308-rock-pi-s.dtb
overlays=rk3308-console-on-uart0 rk3308-spi-spidev
param_spidev_spi_bus=2
rootuuid=37055840-4ec4-444f-979b-9e47ee4bd848
initrdsize=0x64d1d4
kernelversion=4.4.143-47-rockchip-g495ff574976c
initrdimg=initrd.img-4.4.143-47-rockchip-g495ff574976c
kernelimg=vmlinuz-4.4.143-47-rockchip-g495ff574976c

then execute command, sync, followed by reboot.

Create file test-spi.c and add the following contents.

rock@rockpis:~/mraa-examples$ cat test-spi.c 
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>

/* mraa header */
#include "mraa/spi.h"

/* SPI declaration */
#define SPI_BUS 2

/* SPI frequency in Hz */
#define SPI_FREQ 10000000
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;
    }
   
    j = 10;
    while(j) {
  	j--;
        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;
}
rock@rockpis:~/mraa-examples$ gcc -o test-spi test-spi.c -lmraa

Then short pin19 and pin21 and run test-spi

rock@rockpis:~/mraa-examples$ sudo ./test-spi 
0xaa
0xaa
0xaa
0xaa
0xaa
0xaa
0xaa
0xaa
0xaa
0xaa
MRAA: SUCCESS
ADC test

connect signal you want to measure, and then compile mraa example c file, aio.c, to test.

rock@rockpis:~/mraa-examples$ gcc -o aio aio.c -lmraa
rock@rockpis:~/mraa-examples$ sudo ./aio
ADC A0 read 1A5 - 421
ADC A0 read float - 0.41153
ADC A0 read 1A5 - 421
ADC A0 read float - 0.41153
ADC A0 read 1A5 - 421
ADC A0 read float - 0.41153
ADC A0 read 1A5 - 421
ADC A0 read float - 0.41153

Development

More introduction of libmraa can look at libmraa official website.

Troubleshooting