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

Rock3/dev/libmraa-cm3-io

< Rock3‎ | dev
Revision as of 09:16, 5 June 2023 by Nascs (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
       ROCK 3 >  Development >  Install Libmraa 


Enable interface

See Radxa CM3 IO [| GPIO pinout]. ROCK 4 has a 40-pin expansion header. Each pin is distinguished by color. mraa define follow:

27 GPIO:

   PIN03    GPIO0_B6
   PIN05    GPIO0_B5
   PIN07    GPIO3_D5
   PIN11    GPIO0_C7
   PIN13    GPIO0_B7
   PIN15    GPIO0_C3
   PIN19    GPIO4_B2
   PIN21    GPIO4_B0
   PIN23    GPIO4_B3
   PIN27    GPIO4_B4
   PIN29    GPIO4_B1
   PIN31    GPIO0_C5
   PIN33    GPIO0_C6
   PIN35    GPIO3_D0
   PIN37    GPIO0_C2
   PIN08    GPIO0_D1
   PIN10    GPIO0_D0
   PIN12    GPIO3_C7
   PIN16    GPIO3_D4
   PIN18    GPIO3_D3
   PIN22    GPIO3_C6
   PIN24    GPIO4_A6
   PIN28    GPIO4_B5
   PIN32    GPIO4_C0
   PIN36    GPIO4_A7
   PIN38    GPIO3_D2
   PIN40    GPIO3_D1

3 I2C:

   PIN3     I2C2_SDA_M0
   PIN5     I2C2_SCL_M0
   PIN19    I2C4_SDA_M0
   PIN23    I2C4_SCL_M0
   PIN29    I2C2_SDA_M1
   PIN31    I2C2_SCL_M1

2 SPI:

   PIN3     SPI0_MOSI_M0
   PIN5     SPI0_CLK_M0
   PIN31    SPI0_MISO_M0
   PIN33    SPI0_CS0_M0
   PIN19    SPI0_CS0_M0
   PIN31    SPI3_MISO_M0
   PIN7     SPI3_CLK_M0
   PIN33    SPI3_CS0_M0

1 UART:

   PIN8      UART2_TX_M0
   PIN10     UART2_RX_M0

9 PWM:

   PIN3     PWM2_M1
   PIN5     PWM1_M1
   PIN11    PWM0_M1
   PIN13    PWM0_M0
   PIN15    PWM4
   PIN31    PWM6
   PIN33    PWM7_IR
   PIN37    PWM3_IR
   PIN32    PWM11_IR_M1


1 ADC:

   PIN26      SARADC_VIN3

Test

GPIO Test

Use mraa-gpio tool to test

   radxa@radxa-cm3-io:~$ sudo mraa-gpio list
   [sudo] password for radxa: 
   01         3V3: 
   02          5V: 
   03        SDA2: GPIO I2C  
   04          5V: 
   05        SCL2: GPIO I2C  
   06         GND: 
   07    GPIO3_D5: GPIO 
   08        TXD2: GPIO UART 
   09         GND: 
   10        RXD2: GPIO UART 
   11     PWM0_M0: GPIO PWM  
   12    GPIO3_A7: GPIO 
   13     PWM0_M1: GPIO PWM  
   14         GND: 
   15        PWM4: GPIO PWM  
   16    GPIO3_D4: GPIO 
   17         3V3: 
   18    GPIO3_D3: GPIO 
   19 SPI3_MOSI_M: GPIO SPI  UART 
   20         GND: 
   21 SPI3_MISO_M: GPIO SPI  UART 
   22    GPIO3_C6: GPIO 
   23  SPI1CLK_M0: GPIO SPI  UART 
   24 SPI3_CS0_M0: GPIO SPI  
   25         GND: 
   26      SARADC: AIO  
   27     SDA2_M1: GPIO I2C  
   28     SCL2_M1: GPIO I2C  
   29 SDO2,SPI3_C: GPIO I2C  SPI  
   30         GND: 
   31 SDA6,SPI0_M: GPIO I2C  SPI  
   32 PWM11_IR_M1: GPIO 
   33 SPI0_SC0_M0: GPIO SPI  
   34         GND: 
   35    GPIO3_D0: GPIO 
   36 SPI3_SC1_M0: GPIO 
   37     PWM3_IR: GPIO 
   38    GPIO3_D2: GPIO 
   39         GND: 
   40    GPIO3_D1: GPIO 
   radxa@radxa-cm3-io:~$   sudo mraa-gpio set 40 1  //pin40 pull high                                                                                                                      
   radxa@radxa-cm3-io:~$   sudo mraa-gpio set 40 0  //pin40 pull low

I2C Test

Firstly, use rsetup command to enable i2c2, i2c4

Then, use mraa-i2c tool to test,we must have a i2c slave device,for example,we use I2C led(0x20):

   radxa@radxa-cm3-io:~$ sudo mraa-i2c list
   Bus   0: id=02 type=linux  default
   Bus   1: id=04 type=linux
   radxa@radxa-cm3-io:~$ sudo i2cdetect -r -y 0
    0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
   00:                         -- -- -- -- -- -- -- -- 
   10: -- -- -- -- -- -- -- -- -- -- -- -- UU -- -- -- 
   20: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
   30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
   40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
   50: 50 51 52 53 54 55 56 57 -- -- -- -- -- -- -- -- 
   60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
   70: -- -- -- -- -- -- -- -- 
   
   then download the test example led_i2c_blink
   radxa@radxa-cm3-io:~$ gcc i2c_led_blink.c -lmraa -o i2c_led_blink
   radxa@radxa-cm3-io:~$ sudo ./i2c_led_blink
   

SPI Test

   Firstly, use rsetup command to enable spi0,
   compile the example file /usr/local/share/mraa/examples/c/spi.c
   then short pin2 and pin31 and run the ./a.out
   radxa@radxa-cm3-io:~$  gcc /usr/local/share/mraa/examples/c/spi.c -lmraa 
   radxa@radxa-cm3-io:~$  sudo ./a.out

   0xaa
   0xaa
   ......

PWM test

Use c program in /usr/local/share/mraa/examples/c/pwm.c to test:

Modify the macro PWM in /usr/local/share/mraa/examples/c/pwm.c as follows to test PWM0. To test PWM1, change #define PWM 11 to #define PWM 13.


More examples

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

/usr/local/share/mraa/examples/