This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
products:sbc:common:applications:gpio:wiringpi [2022/06/30 00:03] nick ↷ Page name changed from products:sbc:common:applications:gpio:wiringpi-python to products:sbc:common:applications:gpio:wiringpi |
products:sbc:common:applications:gpio:wiringpi [2023/06/25 23:24] (current) nick |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== WiringPi | + | ====== 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 '' | ||
+ | |||
+ | '' | ||
+ | '' | ||
+ | '' | ||
+ | '' | ||
+ | '' | ||
+ | |||
+ | ==== 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: | ||
+ | /* | ||
+ | * Copyright (c) 2022 Wesion Technology Co., Ltd. | ||
+ | * | ||
+ | * Author: Yan < | ||
+ | * | ||
+ | */ | ||
+ | |||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | const int gpio_pin = 1; | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | if(-1 == wiringPiSetup()){ | ||
+ | printf(" | ||
+ | exit(1); | ||
+ | } | ||
+ | |||
+ | pinMode(gpio_pin, | ||
+ | |||
+ | while(1){ | ||
+ | digitalWrite(gpio_pin, | ||
+ | printf(" | ||
+ | delay(5000); | ||
+ | digitalWrite(gpio_pin, | ||
+ | printf(" | ||
+ | delay(5000); | ||
+ | } | ||
+ | |||
+ | exit(0); | ||
+ | } | ||
+ | ``` | ||
+ | |||
+ | Compile | ||
+ | |||
+ | ```shell | ||
+ | $ gcc -o wiringpi wiringpi.c -lwiringPi -lpthread -lrt -lm -lcrypt | ||
+ | ``` | ||
+ | |||
+ | Run | ||
+ | ```shell | ||
+ | sudo ./ | ||
+ | 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 '' | ||
+ | |||
+ | ==== Special Pin Functions ==== | ||
+ | |||
+ | Special pin functions of wiringpi include '' | ||
+ | Please refer to the [[/ | ||