本次型号M1 1.安装WiringNP git clone https://github.com/friendlyarm/WiringNP cd WiringNP/ chmod 755 build ./build
2. 编译成功后执行测试 gpio readall
root@FriendlyARM:~# gpio readall +-----+-----+----------+------+---+-NanoPi NEO/NEO2--+------+----------+-----+-----+ | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM | +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+ | | | 3.3V | | | 1 || 2 | | | 5V | | | | 12 | 8 | GPIOA12 | OFF | 0 | 3 || 4 | | | 5V | | | | 11 | 9 | GPIOA11 | OFF | 0 | 5 || 6 | | | 0v | | | | 203 | 7 | GPIOG11 | OUT | 1 | 7 || 8 | 0 | OFF | GPIOG6 | 15 | 198 | | | | 0v | | | 9 || 10 | 0 | OFF | GPIOG7 | 16 | 199 | | 0 | 0 | GPIOA0 | OFF | 0 | 11 || 12 | 0 | OFF | GPIOA6 | 1 | 6 | | 2 | 2 | GPIOA2 | OFF | 0 | 13 || 14 | | | 0v | | | | 3 | 3 | GPIOA3 | OFF | 0 | 15 || 16 | 0 | OFF | GPIOG8 | 4 | 200 | | | | 3.3v | | | 17 || 18 | 0 | OFF | GPIOG9 | 5 | 201 | | 64 | 12 | GPIOC0 | OFF | 0 | 19 || 20 | | | 0v | | | | 65 | 13 | GPIOC1 | OFF | 0 | 21 || 22 | 0 | OFF | GPIOA1 | 6 | 1 | | 66 | 14 | GPIOC2 | OFF | 0 | 23 || 24 | 0 | OFF | GPIOC3 | 10 | 67 | +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+ | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM | +-----+-----+----------+------+---+-NanoPi NEO/NEO2--+------+----------+-----+-----+ +-----+----NanoPi NEO/NEO2 Debug UART-+----+ | BCM | wPi | Name | Mode | V | Ph | +-----+-----+----------+------+---+----+ | 4 | 17 | GPIOA4 | ALT5 | 0 | 37 | | 5 | 18 | GPIOA5 | ALT4 | 0 | 38 | +-----+-----+----------+------+---+----+
3.将LED灯连接2管脚与7管脚
4.创建test.c文件
vi test.c
输入以下代码:
#include <wiringPi.h>
int main(void)
{
wiringPiSetup() ;
pinMode (7, OUTPUT) ;
for(;;)
{
digitalWrite(7, HIGH) ;
delay (500) ;
digitalWrite(7, LOW) ;
delay (500) ;
}
}
5.编译
gcc -Wall -o test test.c -lwiringPi -lpthread
编译成功后生成test文件
6.运行程序
sudo ./test
7.运行之后观察LED灯,每隔500ms变换一次状态
如果没LED可使用 watch -n 0.1 gpio readall 监控GPIO口状态