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

Difference between revisions of "Rockpi4/dev/libmraa/es es"

< Rockpi4‎ | dev‎ | libmraa
(Created page with "{{rockpi4_header}} {{Languages|rockpi4/dev/libmraa}} ROCK Pi 4 > Desarrollando > rockpi4/dev/libmraa/es_es | Instalar L...")
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
{{rockpi4_header}}
+
{{Languages|rockpi4/dev/Debian}}
 +
{{rockpi4_header_es}}
  
{{Languages|rockpi4/dev/libmraa}}
+
 
 +
<div class="col-md-12" style="text-shadow: 2px 2px 4px #DDDDDD; box-shadow: 2px 2px 5px #999999;">
  
 
       [[rockpi4/es_es | ROCK Pi 4]] > [[rockpi4/dev/es_es | Desarrollando]] > [[rockpi4/dev/libmraa/es_es  | Instalar Libmraa ]]
 
       [[rockpi4/es_es | ROCK Pi 4]] > [[rockpi4/dev/es_es | Desarrollando]] > [[rockpi4/dev/libmraa/es_es  | Instalar Libmraa ]]
Line 10: Line 12:
 
Estas son las instrucciones para saber instalar '''libmraa'''.
 
Estas son las instrucciones para saber instalar '''libmraa'''.
  
== Install essential packages ==
+
== Instalación de Paquetes Esenciales ==
  
Edit your /etc/apt/sources.list and add the following:
+
Edita /etc/apt/sources.list y añade lo siguiente:
  
'''For Debian Stretch'''
+
'''Para Debian Stretch'''
  
 
     deb http://apt.radxa.com/stretch/ stretch main
 
     deb http://apt.radxa.com/stretch/ stretch main
  
'''For Ubuntu bionic'''
+
'''Para Ubuntu bionic'''
  
 
     deb http://apt.radxa.com/bionic/ bionic main
 
     deb http://apt.radxa.com/bionic/ bionic main
  
Get the pub key  
+
Obtenemos la clave pública  
 
     wget -O -  apt.radxa.com/stretch/public.key | sudo apt-key add -
 
     wget -O -  apt.radxa.com/stretch/public.key | sudo apt-key add -
  
Update 
+
Actualizamos
 
     sudo apt-get update && sudo apt-get upgrade
 
     sudo apt-get update && sudo apt-get upgrade
  
Install essential packages:
+
Instalamos los paquetes esenciales:
 
     sudo apt-get install -y rockchip-overlay rockchip-fstab && sudo apt-get install -y rockpi4-dtbo
 
     sudo apt-get install -y rockchip-overlay rockchip-fstab && sudo apt-get install -y rockpi4-dtbo
  
== Install the latest u-boot and kernel==  
+
== Instalamos el último cargador u-boot y el último núcleo==  
 
     apt-get install rockpi4b-rk-u-boot-lastest
 
     apt-get install rockpi4b-rk-u-boot-lastest
  
Manually run the u-boot flash script
+
Ejecutamos manualmente el script de u-boot flash
 
     /usr/local/sbin/rockpi4b_upgrade_bootloader.sh
 
     /usr/local/sbin/rockpi4b_upgrade_bootloader.sh
  
  
Type '''YES''' to perform the uboot.img flashing.
+
Tecleamos '''YES''' para realizar la grabación de la imagen uboot.img.
  
then install kernel  
+
... instalamos el núcleo  
 
     apt-get install linux-base
 
     apt-get install linux-base
 
     apt-get install linux-4.4-lastest
 
     apt-get install linux-4.4-lastest
  
  
After installation, check file '''/boot/extlinux/extlinux.conf'''. It lists all kernel version installed in ROCK Pi. The kernel corresponding to the first label is the newest version and the first boot option.
+
Después, comprobamos el fichero '''/boot/extlinux/extlinux.conf'''. Debe de listar todas las versiones del núcleo instaladas en el ROCK Pi. El núcleo correspondiente a la primera etiqueta es la versión más nueva y la primera opción de inicio.
  
== Enable interface ==  
+
== Activando una Interfaz ==  
See rockpi4 [[Rockpi4/hardware/rockpi4#gpio | GPIO pinout]],ROCK Pi 4 has a 40-pin expansion header. Each pin is distinguished by color. mraa define follow:   
+
Mirar en rockpi4 [[Rockpi4/hardware/rockpi4/es_es#gpio | pines GPIO]],ROCK Pi 4 tiene 40 pines de expansión. Cada pin se diferencia por un color. En la librería mraa se definen así los pines:   
  
 
15 GPIO:
 
15 GPIO:
Line 83: Line 85:
 
     PIN13      PWM'''1'''
 
     PIN13      PWM'''1'''
  
modify '''/boot/hw_intfc.conf''' to enable '''pwm0,pwm1,spi1,i2c2,i2c7''' for test
+
modifica '''/boot/hw_intfc.conf''' para activar '''pwm0,pwm1,spi1,i2c2,i2c7''' para su comprobación
 
     root@localhost:/# cat boot/hw_intfc.conf  
 
     root@localhost:/# cat boot/hw_intfc.conf  
 
      
 
      
     # Hardware Interface Config
+
     # Configuración de Interfaz Hardware
 
      
 
      
     # For more details, check file /usr/local/share/doc/rockpi4-dtbo/README
+
     # Para más detalles, mira el archivo /usr/local/share/doc/rockpi4-dtbo/README
 
      
 
      
     # Uncomment configuration line if you use it. Take i2c6 as an example,
+
     # Descomenta la línea de configuración si quieres usar esta característica. Como ejemplo i2c6.
     # setting off disables i2c6 bus and setting on enables i2c6 bus.
+
     # off desactiva el bus i2c6 y on activa el bus i2c6.
 
      
 
      
 
     '''intfc:pwm0=on'''
 
     '''intfc:pwm0=on'''
Line 103: Line 105:
 
     '''intfc:i2c7=on'''
 
     '''intfc:i2c7=on'''
 
      
 
      
     # DTS Overlay Config
+
     # Configuración DTS Overlay
     # 1. check the name.dtbo in /boot/overlays
+
     # 1. comprobar nombre.dtbo en /boot/overlays
     # 2. add intfc:dtoverlay=name as below
+
     # 2. añadir intfc:dtoverlay=nombre como se usa debajo
 
      
 
      
 
     #intfc:dtoverlay=at24c02
 
     #intfc:dtoverlay=at24c02
Line 112: Line 114:
 
     #intfc:dtoverlay=console-on-uart4
 
     #intfc:dtoverlay=console-on-uart4
 
     root@localhost:/#  
 
     root@localhost:/#  
then '''reboot'''
 
  
==Install libmraa-rockpi4==  
+
luego '''reinicia'''
 +
 
 +
==Instala la librería libmraa-rockpi4==  
  
 
     apt-get install libmraa-rockpi4
 
     apt-get install libmraa-rockpi4
  
==Test==
+
==Haciendo Pruebas...==
===test gpio===
+
===Probando los gpio===
  
Use '''mraa-gpio''' tool to test  
+
Usa la herramienta '''mraa-gpio''' para probar  
  
 
     root@localhost:~# mraa-gpio list
 
     root@localhost:~# mraa-gpio list
Line 139: Line 142:
 
     38    GPIO4_A6: GPIO  
 
     38    GPIO4_A6: GPIO  
 
     40    GPIO4_A7: GPIO  
 
     40    GPIO4_A7: GPIO  
     root@localhost:~# mraa-gpio set 40 1  //pin40 pull high                                                                                                                      
+
     root@localhost:~# mraa-gpio set 40 1  // pin40 se activa a nivel alto                                                                                                                      
     root@localhost:~# mraa-gpio set 40 0  //pin40 pull low
+
     root@localhost:~# mraa-gpio set 40 0  // pin40 se activa a nivel bajo
 
     root@localhost:~#  
 
     root@localhost:~#  
===test i2c===
+
 
Use '''mraa-i2c''' tool to test,we must have a i2c slave device,for example,we use I2C EEPROM:
+
===Probando i2c===
 +
Usa la herramienta '''mraa-i2c''' para probar, si tenemos un dispositivo esclavo i2c, por ejemplo una EEPROM I2C, haremos:
 
     root@localhost:~# mraa-i2c list     
 
     root@localhost:~# mraa-i2c list     
 
     Bus  0: id=07 type=linux  default
 
     Bus  0: id=07 type=linux  default
 
     Bus  1: id=02 type=linux
 
     Bus  1: id=02 type=linux
     root@localhost:~# mraa-i2c detect 0      //device on bus 0
+
     root@localhost:~# mraa-i2c detect 0      // dispositivo en el bus 0
 
     00: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --  
 
     00: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --  
 
     10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --  
 
     10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --  
Line 156: Line 160:
 
     60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --  
 
     60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --  
 
     70: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
 
     70: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
     root@localhost:~# mraa-i2c detect 1    //no device on bus 1
+
     root@localhost:~# mraa-i2c detect 1    // ningún dispositivo en el bus 1
 
     00: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --  
 
     00: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --  
 
     10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --  
 
     10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --  
Line 165: Line 169:
 
     60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --  
 
     60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --  
 
     70: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
 
     70: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
     root@localhost:~# mraa-i2c set 0 0x50 0x10 0x55  //write                                                                                                                          
+
     root@localhost:~# mraa-i2c set 0 0x50 0x10 0x55  // escribir                                                                                                                          
     Device 50, Register = 10, Value = 55
+
     en el dispositivo 50, en su registro 10 el valor 55; grabará 0x55.
     root@localhost:~# mraa-i2c get 0 0x50 0x10              //read                                                                                              
+
 
     Register 0X10 = 0X55
+
     root@localhost:~# mraa-i2c get 0 0x50 0x10              // leer                                                                                              
 +
     del dispositivo 50, su registro 10; se devolverá 0x55.
 +
 
 
     root@localhost:~#     
 
     root@localhost:~#     
  
===test spi===
+
===Probando spi===
use '''c''' to test spi,compile spi.c
+
Usamos '''c''' para probar el spi, compilamos spi.c
 +
 
 
     root@localhost:~# cat spi.c
 
     root@localhost:~# cat spi.c
 
     #include <signal.h>
 
     #include <signal.h>
Line 178: Line 185:
 
     #include <unistd.h>
 
     #include <unistd.h>
 
      
 
      
     /* mraa header */
+
     /* cabecera mraa */
 
     #include "mraa/spi.h"
 
     #include "mraa/spi.h"
 
      
 
      
     /* SPI declaration */
+
     /* declaración SPI */
 
     #define SPI_BUS 0
 
     #define SPI_BUS 0
 
      
 
      
     /* SPI frequency in Hz */
+
     /* frecuencia SPI Hz */
 
     #define SPI_FREQ 400000
 
     #define SPI_FREQ 400000
 
     int
 
     int
Line 193: Line 200:
 
         int i, j;
 
         int i, j;
 
      
 
      
         /* initialize mraa for the platform (not needed most of the times) */
+
         /* inicializar mraa para la plataforma (no es necesario la mayoría de las veces) */
 
         mraa_init();
 
         mraa_init();
 
      
 
      
         //! [Interesting]
+
         //! [Interesante]
         /* initialize SPI bus */
+
         /* inicializamos en bus SPI */
 
         spi = mraa_spi_init(SPI_BUS);
 
         spi = mraa_spi_init(SPI_BUS);
 
         if (spi == NULL) {
 
         if (spi == NULL) {
             fprintf(stderr, "Failed to initialize SPI\n");
+
             fprintf(stderr, "Fallo al inicializar SPI\n");
 
             mraa_deinit();
 
             mraa_deinit();
 
             return EXIT_FAILURE;
 
             return EXIT_FAILURE;
 
         }
 
         }
 
      
 
      
         /* set SPI frequency */
+
         /* establecemos la frecuencia del bus SPI */
 
         status = mraa_spi_frequency(spi, SPI_FREQ);
 
         status = mraa_spi_frequency(spi, SPI_FREQ);
 
         if (status != MRAA_SUCCESS)
 
         if (status != MRAA_SUCCESS)
 
             goto err_exit;
 
             goto err_exit;
 
      
 
      
         /* set big endian mode */
+
         /* ponemos el modo big endian */
 
         status = mraa_spi_lsbmode(spi, 0);
 
         status = mraa_spi_lsbmode(spi, 0);
 
         if (status != MRAA_SUCCESS) {
 
         if (status != MRAA_SUCCESS) {
Line 221: Line 228:
 
         mraa_result_print(status);
 
         mraa_result_print(status);
 
      
 
      
         /* stop spi */
+
         /* paramos el bus spi */
 
         mraa_spi_stop(spi);
 
         mraa_spi_stop(spi);
 
      
 
      
         /* deinitialize mraa for the platform (not needed most of the times) */
+
         /* desinicializamos mraa para la plataforma (no es necesario la mayoría de las veces) */
 
         mraa_deinit();
 
         mraa_deinit();
 
      
 
      
Line 230: Line 237:
 
     }
 
     }
 
     root@localhost:~# gcc spi.c -lmraa
 
     root@localhost:~# gcc spi.c -lmraa
then short '''pin19''' and '''pin21''' and run a.out
+
 
 +
entonces usamos '''pin19''' y '''pin21''' y ejecutamos run a.out
 +
 
 
     root@localhost:~# ./a.out  
 
     root@localhost:~# ./a.out  
 
     0xaa
 
     0xaa
Line 236: Line 245:
 
     ......
 
     ......
  
===test pwm===
+
===Probando pwm===
  
for pwm python test,should install python and libpython2.7   
+
Para probar pwm con python, deberemos instalar python y libpython2.7   
  
 
     apt-get install libpython2.7 python
 
     apt-get install libpython2.7 python
  
use python script follow:   
+
usamos el siguiente script python:   
  
 
     root@localhost:~# cat pwm.py  
 
     root@localhost:~# cat pwm.py  
 
     #!/usr/bin/env python
 
     #!/usr/bin/env python
     # Example Usage: Generates PWM at a step rate of 0.01 continuously.
+
     # Ejemplo de Uso: Genera un PWM a un ratio de paso de 0.01 constantemente.
 
     import mraa
 
     import mraa
 
     import time
 
     import time
Line 267: Line 276:
 
     root@localhost:~#  
 
     root@localhost:~#  
  
then run pwm.py   
+
entonces ejecutamos run pwm.py   
  
 
     root@localhost:~# ls
 
     root@localhost:~# ls
Line 274: Line 283:
 
     root@localhost:~# ./pwm.py
 
     root@localhost:~# ./pwm.py
  
===test uart===
+
===Probando uart===
Disable console and enable uart2 for uart test
+
Desactivando la consola de depuración y activando uart2
 
     root@localhost:/# cat boot/hw_intfc.conf  
 
     root@localhost:/# cat boot/hw_intfc.conf  
 
      
 
      
     # Hardware Interface Config
+
     # Configuración Interfaz Hardware
 
      
 
      
     # For more details, check file /usr/local/share/doc/rockpi4-dtbo/README
+
     # Para más detalles, mira el fichero /usr/local/share/doc/rockpi4-dtbo/README
 
      
 
      
     # Uncomment configuration line if you use it. Take i2c6 as an example,
+
     # Descomenta la línea de configuración si quieres usar esta característica. Como ejemplo i2c6.
     # setting off disables i2c6 bus and setting on enables i2c6 bus.
+
     # off desactiva el bus i2c6 y on activa el bus i2c6.
 
      
 
      
 
     intfc:pwm0=on
 
     intfc:pwm0=on
Line 295: Line 304:
 
     intfc:i2c7=off
 
     intfc:i2c7=off
 
      
 
      
     # DTS Overlay Config
+
     # Configuración DTS Overlay
     # 1. check the name.dtbo in /boot/overlays
+
     # 1. comprobar nombre.dtbo en /boot/overlays
     # 2. add intfc:dtoverlay=name as below
+
     # 2. añadir intfc:dtoverlay=nombre como se usa debajo
 
      
 
      
 
     #intfc:dtoverlay=at24c02
 
     #intfc:dtoverlay=at24c02
Line 303: Line 312:
 
     '''intfc:dtoverlay=console-disabled'''
 
     '''intfc:dtoverlay=console-disabled'''
 
     #intfc:dtoverlay=console-on-uart4
 
     #intfc:dtoverlay=console-on-uart4
 +
 
     root@localhost:/#  
 
     root@localhost:/#  
then '''reboot''' and short '''pin8''' and '''pin10'''.
+
entonces '''reinicia''' y conecta '''pin8''' y '''pin10'''.
use ssh connect to rockpi4,we must have 2 windows,one is for send data,anothor is for receive.   
+
usa ssh para conectarte al rockpi4, debemos tener 2 ventanas, una para enviar datos y otra para recibirlos.   
  
send command follow:
+
enviar el siguiente comando:
 
     sudo mraa-uart dev 0 baud 1500000 send  data
 
     sudo mraa-uart dev 0 baud 1500000 send  data
receive command follow:
+
recibir el siguiente comando:
 
     sudo mraa-uart dev 0 baud 1500000 recv  1000
 
     sudo mraa-uart dev 0 baud 1500000 recv  1000
  
the receive window will show the data
+
la ventana de recepción mostrará los datos
 +
 
 +
</div>

Latest revision as of 19:47, 19 March 2019


       ROCK Pi 4 >  Desarrollando >  Instalar Libmraa 


Libmraa-rockpi4

Estas son las instrucciones para saber instalar libmraa.

Instalación de Paquetes Esenciales

Edita /etc/apt/sources.list y añade lo siguiente:

Para Debian Stretch

   deb http://apt.radxa.com/stretch/ stretch main

Para Ubuntu bionic

   deb http://apt.radxa.com/bionic/ bionic main

Obtenemos la clave pública

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

Actualizamos

   sudo apt-get update && sudo apt-get upgrade

Instalamos los paquetes esenciales:

   sudo apt-get install -y rockchip-overlay rockchip-fstab && sudo apt-get install -y rockpi4-dtbo

Instalamos el último cargador u-boot y el último núcleo

   apt-get install rockpi4b-rk-u-boot-lastest

Ejecutamos manualmente el script de u-boot flash

   /usr/local/sbin/rockpi4b_upgrade_bootloader.sh


Tecleamos YES para realizar la grabación de la imagen uboot.img.

... instalamos el núcleo

   apt-get install linux-base
   apt-get install linux-4.4-lastest


Después, comprobamos el fichero /boot/extlinux/extlinux.conf. Debe de listar todas las versiones del núcleo instaladas en el ROCK Pi. El núcleo correspondiente a la primera etiqueta es la versión más nueva y la primera opción de inicio.

Activando una Interfaz

Mirar en rockpi4 pines GPIO,ROCK Pi 4 tiene 40 pines de expansión. Cada pin se diferencia por un color. En la librería mraa se definen así los pines:

15 GPIO:

   PIN07    GPIO2_B3
   PIN12    GPIO4_A3
   PIN15    GPIO4_C5
   PIN16    GPIO4_D2
   PIN18    GPIO4_D4
   PIN22    GPIO4_D5
   PIN29    GPIO2_B2
   PIN31    GPIO2_B1
   PIN32    GPIO3_C0
   PIN33    GPIO2_B4
   PIN35    GPIO4_A5
   PIN36    GPIO4_A4
   PIN37    GPIO4_D6
   PIN38    GPIO4_A6
   PIN40    GPIO4_A7

2 I2C:

   PIN3       I2C7_SDA
   PIN5       I2C7_SCL
   PIN27      I2C2_SCL
   PIN28      I2C2_SCL

1 SPI:

   PIN19      SPI1_MOSI
   PIN21      SPI1_MISO
   PIN23      SPI1_CLK
   PIN24      SPI1_CS0

1 UART:

   PIN8       UART2_TX
   PIN10      UART2_RX

2 PWM:

   PIN11      PWM0
   PIN13      PWM1

modifica /boot/hw_intfc.conf para activar pwm0,pwm1,spi1,i2c2,i2c7 para su comprobación

   root@localhost:/# cat boot/hw_intfc.conf 
   
   # Configuración de Interfaz Hardware
   
   # Para más detalles, mira el archivo /usr/local/share/doc/rockpi4-dtbo/README
   
   # Descomenta la línea de configuración si quieres usar esta característica.  Como ejemplo i2c6.
   # off desactiva el bus i2c6 y on activa el bus i2c6.
   
   intfc:pwm0=on
   intfc:pwm1=on
   intfc:uart2=off
   intfc:uart4=off
   intfc:spi1=on
   intfc:spi2=off
   intfc:i2c2=on
   intfc:i2c6=off
   intfc:i2c7=on
   
   # Configuración DTS Overlay
   # 1. comprobar nombre.dtbo en /boot/overlays
   # 2. añadir intfc:dtoverlay=nombre como se usa debajo
   
   #intfc:dtoverlay=at24c02
   #intfc:dtoverlay=two-color-led
   #intfc:dtoverlay=console-disabled
   #intfc:dtoverlay=console-on-uart4
   root@localhost:/# 

luego reinicia

Instala la librería libmraa-rockpi4

   apt-get install libmraa-rockpi4

Haciendo Pruebas...

Probando los gpio

Usa la herramienta mraa-gpio para probar

   root@localhost:~# mraa-gpio list
   07    GPIO2_B3: GPIO 
   12    GPIO4_A3: GPIO 
   15    GPIO4_C5: GPIO 
   16    GPIO4_D2: GPIO 
   18    GPIO4_D4: GPIO 
   22    GPIO4_D5: GPIO 
   29    GPIO2_B2: GPIO 
   31    GPIO2_B1: GPIO 
   32    GPIO3_C0: GPIO 
   33    GPIO2_B4: GPIO 
   35    GPIO4_A5: GPIO 
   36    GPIO4_A4: GPIO 
   37    GPIO4_D6: GPIO 
   38    GPIO4_A6: GPIO 
   40    GPIO4_A7: GPIO 
   root@localhost:~# mraa-gpio set 40 1  // pin40 se activa a nivel alto                                                                                                                      
   root@localhost:~# mraa-gpio set 40 0  // pin40 se activa a nivel bajo
   root@localhost:~# 

Probando i2c

Usa la herramienta mraa-i2c para probar, si tenemos un dispositivo esclavo i2c, por ejemplo una EEPROM I2C, haremos:

   root@localhost:~# mraa-i2c list    
   Bus   0: id=07 type=linux  default
   Bus   1: id=02 type=linux
   root@localhost:~# mraa-i2c detect 0       // dispositivo en el bus 0
   00: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
   10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
   20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
   30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
   40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
   50: 50 51 52 53 54 55 56 57 -- -- -- -- -- -- -- -- 
   60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
   70: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
   root@localhost:~# mraa-i2c detect 1    // ningún dispositivo en el bus 1
   00: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
   10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
   20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
   30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
   40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
   50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
   60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
   70: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
   root@localhost:~# mraa-i2c set 0 0x50 0x10 0x55   // escribir                                                                                                                          
   en el dispositivo 50, en su registro 10 el valor 55; grabará 0x55.
   root@localhost:~# mraa-i2c get 0 0x50 0x10              // leer                                                                                              
   del dispositivo 50, su registro 10; se devolverá 0x55.
   root@localhost:~#     

Probando spi

Usamos c para probar el spi, compilamos spi.c

   root@localhost:~# cat spi.c
   #include <signal.h>
   #include <stdlib.h>
   #include <unistd.h>
   
   /* cabecera mraa */
   #include "mraa/spi.h"
   
   /* declaración SPI */
   #define SPI_BUS 0
   
   /* frecuencia SPI Hz */
   #define SPI_FREQ 400000
   int
   main(int argc, char** argv)
   {
       mraa_result_t status = MRAA_SUCCESS;
       mraa_spi_context spi;
       int i, j;
   
       /* inicializar mraa para la plataforma (no es necesario la mayoría de las veces) */
       mraa_init();
   
       //! [Interesante]
       /* inicializamos en bus SPI */
       spi = mraa_spi_init(SPI_BUS);
       if (spi == NULL) {
           fprintf(stderr, "Fallo al inicializar SPI\n");
           mraa_deinit();
           return EXIT_FAILURE;
       }
   
       /* establecemos la frecuencia del bus SPI */
       status = mraa_spi_frequency(spi, SPI_FREQ);
       if (status != MRAA_SUCCESS)
           goto err_exit;
   
       /* ponemos el modo big endian */
       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);
   
       /* paramos el bus spi */
       mraa_spi_stop(spi);
   
       /* desinicializamos mraa para la plataforma (no es necesario la mayoría de las veces) */
       mraa_deinit();
   
       return EXIT_FAILURE;
   }
   root@localhost:~# gcc spi.c -lmraa

entonces usamos pin19 y pin21 y ejecutamos run a.out

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

Probando pwm

Para probar pwm con python, deberemos instalar python y libpython2.7

   apt-get install libpython2.7 python

usamos el siguiente script python:

   root@localhost:~# cat pwm.py 
   #!/usr/bin/env python
   # Ejemplo de Uso: Genera un PWM a un ratio de paso de 0.01 constantemente.
   import mraa
   import time
   
   x = mraa.Pwm(11) # pin11 pwm0
   # x = mraa.Pwm(13) # pin13 pwm1
   x.period_us(700)
   x.enable(True)
   
   value= 0.0
   
   while True:
       x.write(value)
   
       time.sleep(0.05)
   
   value = value + 0.01
       if value >= 1:
           value = 0.0
   root@localhost:~# 

entonces ejecutamos run pwm.py

   root@localhost:~# ls
   pwm.py
   root@localhost:~# chmod +x pwm.py 
   root@localhost:~# ./pwm.py

Probando uart

Desactivando la consola de depuración y activando uart2

   root@localhost:/# cat boot/hw_intfc.conf 
   
   # Configuración Interfaz Hardware
   
   # Para más detalles, mira el fichero /usr/local/share/doc/rockpi4-dtbo/README
   
   # Descomenta la línea de configuración si quieres usar esta característica.  Como ejemplo i2c6.
   # off desactiva el bus i2c6 y on activa el bus i2c6.
   
   intfc:pwm0=on
   intfc:pwm1=on
   intfc:uart2=on
   intfc:uart4=off
   intfc:spi1=on
   intfc:spi2=off
   intfc:i2c2=on
   intfc:i2c6=off
   intfc:i2c7=off
   
   # Configuración DTS Overlay
   # 1. comprobar nombre.dtbo en /boot/overlays
   # 2. añadir intfc:dtoverlay=nombre como se usa debajo
   
   #intfc:dtoverlay=at24c02
   #intfc:dtoverlay=two-color-led
   intfc:dtoverlay=console-disabled
   #intfc:dtoverlay=console-on-uart4
   root@localhost:/# 

entonces reinicia y conecta pin8 y pin10. usa ssh para conectarte al rockpi4, debemos tener 2 ventanas, una para enviar datos y otra para recibirlos.

enviar el siguiente comando:

   sudo mraa-uart dev 0 baud 1500000 send  data

recibir el siguiente comando:

   sudo mraa-uart dev 0 baud 1500000 recv  1000

la ventana de recepción mostrará los datos