Khadas Docs

Amazing Khadas, always amazes you!

User Tools

Site Tools


products:sbc:common:applications:gpio:wiringpi

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
products:sbc:common:applications:gpio:wiringpi [2022/06/30 00:03]
nick created
products:sbc:common:applications:gpio:wiringpi [2023/06/25 23:24] (current)
nick
Line 1: Line 1:
-====== WiringPi Python ======+====== WiringPi ====== 
 + 
 +===== Introduction ===== 
 + 
 +WiringPi is a C++ library for Raspberry Pi, we port it to Khadas SBC, With this library you can use many of the functionalities provided by the GPIO header: digital pins, SPI, I2C, UART, etc. 
 + 
 +===== WiringPi Instructions ===== 
 + 
 +There are two methods here, via command line or C program. 
 + 
 +==== Get Pin Info ==== 
 + 
 +Run ''gpio readall'', and it will print a table about the status of all GPIO pins. 
 + 
 +''GPIO'' –> GPIO native number \\ 
 +''wPi'' –> WiringPi number \\ 
 +''Mode'' –> GPIO Mode ,''ALT'' mean that this pin defined as a special function \\ 
 +''V'' –> 1 - HIGH, 0 - LOW \\ 
 +''PU/PD'' –> ''PU'' - pull up, ''PD'' - pull down, ''DSBLD'' - disabled 
 + 
 +==== Using via Command Line ==== 
 + 
 +Here’s an example of controlling wpi number 1. 
 + 
 +  * Set GPIO mode to output  
 +```shell 
 +$ gpio mode 1 out 
 +``` 
 +  * Set output low level 
 +```shell 
 +$ gpio write 1 0 
 +``` 
 +  * Set output high level 
 +```shell 
 +$ gpio write 1 1 
 +``` 
 + 
 +==== Using via C Program ==== 
 + 
 +The test program changes the level value every 5S. 
 + 
 +```c wiringpi.c 
 +// SPDX-License-Identifier: (GPL-2.0+ OR MIT) 
 +/* 
 + * Copyright (c) 2022 Wesion Technology Co., Ltd. 
 + * 
 + * Author: Yan <yan-wyb@foxmail.com>  
 + * 
 + */ 
 + 
 +#include <stdio.h> 
 +#include <wiringPi.h> 
 + 
 +const int gpio_pin = 1; 
 + 
 +int main() 
 +
 +    if(-1 == wiringPiSetup()){ 
 +        printf("set up error"); 
 +        exit(1); 
 +    } 
 + 
 +    pinMode(gpio_pin,OUTPUT); 
 + 
 +    while(1){ 
 +        digitalWrite(gpio_pin,HIGH); 
 +        printf("wPi Pin %d now is GIGH\n",gpio_pin); 
 +        delay(5000); 
 +        digitalWrite(gpio_pin,LOW); 
 +        printf("wPi Pin %d now is LOW\n",gpio_pin); 
 +        delay(5000); 
 +    } 
 + 
 +    exit(0); 
 +
 +``` 
 + 
 +Compile 
 + 
 +```shell 
 +$ gcc -o wiringpi wiringpi.c -lwiringPi -lpthread -lrt -lm -lcrypt 
 +``` 
 + 
 +Run 
 +```shell 
 +sudo ./wiringpi 
 +wPi Pin 1 now is GIGH 
 +wPi Pin 1 now is LOW 
 +wPi Pin 1 now is GIGH 
 +wPi Pin 1 now is LOW 
 +``` 
 +You can use ''gpio read 1'' to observe the pin level changes. 
 + 
 +==== Special Pin Functions ==== 
 + 
 +Special pin functions of wiringpi include ''SPI'',''I2C'',''ADC'',''SoftPWM''
 +Please refer to the [[/products/sbc/common/applications/gpio/40pin-header|40-Pin Header]] for the corresponding physical pins.
  
Last modified: 2022/06/30 00:03 by nick