Programa Raspberry Pi

en

Lenguaje C

Apr 21, 2024

Programemos Raspberry Pi con Lenguaje C:

We Program Raspberry Pi with C:

Actualización gracias a Agusthina Oliva

¿Por qué?--Why?:

Porque es el mismo lenguaje que usa eficazmente tu Aire acondicionado, tu microondas, tu lavarropas, se comunica con mayor eficiencia que Python.Because is the more efficient Language, run in your Microwave, in your air-conditioning . 

Para programar nuestros proyectos con C en Raspberry Pi tenemos 2 opciones--We have 2 options:

Diagrama de conexión--Diagram:

Comencemos con la librería BCM2835--Start with BCM2835 library :

Utilizar este Fork --- Newest WiringPi Fork works in Pi400:

Podemos confirmar con--We can check with:

Eso es todo saltemos a la parte de--That's all jump to Geany part.

gpio readall

Abrimos el Terminal y tecleamos lo siguiente--Open Terminal and choose the latest version by typing:


Método antiguo--Old method

Documentación--Docs:

Example

Descomprimimos la versión descargada--Untar:

Nos situamos en el nuevo directorio--Go to the new directory:

Ejecutamos configure--Type:

Ejecutamos make--Type:

Ejecutamos con permisos root make check--Check with sudo:

Ejecutamos con permiso root la instalación--Install:

Configuremos nuestro compilador Geany--Config Geany for use the library:

Debemos enlazar la librería bcm2835 a nuestros comandos, yendo a la opción Construir-> Establecer comando de construcción:

We need link the library wiringPi to our build commands, go to Build -->Set Build Commands:

Si compilamos desde Terminal solo debemos escribir el comando--If we compile from Terminal then:

Ejecutandolo así--And we execute:

Creamos nuestro primer Blink:

Segunda opción de Blink:

Mas ejemplos en la carpeta--More examples:

Ahora con Wiring Pi--Now with WiringPi:

Veamos si está instalado--Look if is installed typing:

Antes no venia instalado en Raspbian Stretch y veíamos esto.--On Raspbian we see these on the past, because not came with the OS.

Hoy en dia con Raspberry Pi OS ya viene pre-instalado.--Now came pre-installed but not in his latest version 

Si tenemos alguna version instalada, la eliminamos--We purge the old version with:

sudo apt-get purge -y wiringpi

hash -r

Obtenemos la ultima version de Wiring Pi--Getting the latest:

Instalamos el paquete .deb obtenido--Install it:

Podemos observar la última versión instalada.--We can see the lates version installed

Verificamos con gpio -v la nueva--Check the difference vesion with gpio -v

Observamos la nomenclatura de pines utilizada por wiringPi (wPi) con--We can see the nomenclature of WiringPi(wPi):

gpio readall de una--on a Raspberry Pi 3B

gpio readall de una--on a Raspberry pi 4B

Como realizamos antes, en Geany debemos indicarle el nombre de la biblioteca utilizada--Like we do before, we need to tell to Geany the name of library used:

Debemos enlazar la librería wiringPi a nuestros comandos, yendo a la opción Construir --> Establecer comandos de construcción:

We need link the library wiringPi to our build commands, go to Build -->Set Build Commands:

Si compilamos desde Terminal solo debemos escribir el comando--If we compile from Terminal then:

Ejecutandolo así--And we execute:

Código Blink con Wiring Pi--Code Blink with WiringPi:

Mas ejemplos en--More examples in:

Y su nuevo GitHub, ya no por Gordon--The new Github:

https://github.com/WiringPi/WiringPi