这里写自定义目录标题
在树莓派4B+ubuntu21.4系统上利用wiringPi库控制GPIO
直接用apt命令只能安装到2.50版本
在4B+ubuntu21.4上执行指令
gpio readall
或者编译相关库的.c程序需要安装wiring 2.52版本。但是直接利用
apt-get xxx
安装,只能安装至2.50版本。
利用有2.52的.deb包安装
网上可以找到资源2.52版本:
wget https://project-downloads.drogon.net/wiringpi-latest.deb
sudo dpkg -i wiringpi-latest.deb
但是发现会产生系统不兼容报错因为这个包是基于armhf架构的,但是我的系统采用的是arm64架构,所以无法直接安装
解决包的架构与系统架构不兼容无法安装的问题
再多安装一个foreign_architecture,用如下命令执行
sudo dpkg --add-architecture armhf
sudo apt-get update
sudo apt-get upgrade
再进行安装可升级至2.52版本
安装完成后可以用指令:
gpio -
查看,得
gpio version: 2.52
Copyright (c) 2012-2018 Gordon Henderson
This is free software with ABSOLUTELY NO WARRANTY.
For details type: gpio -warranty
Raspberry Pi Details:
Type: Pi 4B, Revision: 04, Memory: 8192MB, Maker: Sony
* Device tree is enabled.
*--> Raspberry Pi 4 Model B Rev 1.4
* This Raspberry Pi supports user-level GPIO access.
查看引脚功能:
gpio readall
得
+-----+-----+---------+------+---+---Pi 4B--+---+------+---------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| | | 3.3v | | | 1 || 2 | | | 5v | | |
| 2 | 8 | SDA.1 | ALT0 | 1 | 3 || 4 | | | 5v | | |
| 3 | 9 | SCL.1 | ALT0 | 1 | 5 || 6 | | | 0v | | |
| 4 | 7 | GPIO. 7 | IN | 1 | 7 || 8 | 1 | IN | TxD | 15 | 14 |
| | | 0v | | | 9 || 10 | 1 | IN | RxD | 16 | 15 |
| 17 | 0 | GPIO. 0 | IN | 0 | 11 || 12 | 0 | OUT | GPIO. 1 | 1 | 18 |
| 27 | 2 | GPIO. 2 | IN | 0 | 13 || 14 | | | 0v | | |
| 22 | 3 | GPIO. 3 | IN | 0 | 15 || 16 | 0 | IN | GPIO. 4 | 4 | 23 |
| | | 3.3v | | | 17 || 18 | 0 | IN | GPIO. 5 | 5 | 24 |
| 10 | 12 | MOSI | ALT0 | 0 | 19 || 20 | | | 0v | | |
| 9 | 13 | MISO | ALT0 | 0 | 21 || 22 | 0 | IN | GPIO. 6 | 6 | 25 |
| 11 | 14 | SCLK | ALT0 | 0 | 23 || 24 | 1 | OUT | CE0 | 10 | 8 |
| | | 0v | | | 25 || 26 | 1 | OUT | CE1 | 11 | 7 |
| 0 | 30 | SDA.0 | IN | 1 | 27 || 28 | 1 | IN | SCL.0 | 31 | 1 |
| 5 | 21 | GPIO.21 | IN | 1 | 29 || 30 | | | 0v | | |
| 6 | 22 | GPIO.22 | IN | 1 | 31 || 32 | 0 | IN | GPIO.26 | 26 | 12 |
| 13 | 23 | GPIO.23 | IN | 0 | 33 || 34 | | | 0v | | |
| 19 | 24 | GPIO.24 | IN | 0 | 35 || 36 | 0 | IN | GPIO.27 | 27 | 16 |
| 26 | 25 | GPIO.25 | IN | 0 | 37 || 38 | 0 | IN | GPIO.28 | 28 | 20 |
| | | 0v | | | 39 || 40 | 0 | IN | GPIO.29 | 29 | 21 |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+---------+------+---+---Pi 4B--+---+------+---------+-----+-----+
但是当我用gcc编译时出现了下面的报错
输入:
gcc led.c -lwiringPi
得到
/usr/bin/ld: 当搜索用于 /usr/lib/gcc/aarch64-linux-gnu/10/../../../../lib/libwiringPi.so 时跳过不兼容的 -lwiringPi
/usr/bin/ld: 当搜索用于 /lib/../lib/libwiringPi.so 时跳过不兼容的 -lwiringPi
/usr/bin/ld: 当搜索用于 /usr/lib/../lib/libwiringPi.so 时跳过不兼容的 -lwiringPi
/usr/bin/ld: 当搜索用于 /usr/lib/gcc/aarch64-linux-gnu/10/../../../libwiringPi.so 时跳过不兼容的 -lwiringPi
/usr/bin/ld: 当搜索用于 /lib/libwiringPi.so 时跳过不兼容的 -lwiringPi
/usr/bin/ld: 当搜索用于 /usr/lib/libwiringPi.so 时跳过不兼容的 -lwiringPi
/usr/bin/ld: 找不到 -lwiringPi
/usr/bin/ld: 当搜索用于 /usr/lib/gcc/aarch64-linux-gnu/10/../../../../lib/libwiringPi.so 时跳过不兼容的 -lwiringPi
/usr/bin/ld: 当搜索用于 /lib/../lib/libwiringPi.so 时跳过不兼容的 -lwiringPi
/usr/bin/ld: 当搜索用于 /usr/lib/../lib/libwiringPi.so 时跳过不兼容的 -lwiringPi
/usr/bin/ld: 当搜索用于 /usr/lib/gcc/aarch64-linux-gnu/10/../../../libwiringPi.so 时跳过不兼容的 -lwiringPi
/usr/bin/ld: 当搜索用于 /lib/libwiringPi.so 时跳过不兼容的 -lwiringPi
/usr/bin/ld: 当搜索用于 /usr/lib/libwiringPi.so 时跳过不兼容的 -lwiringPi
collect2: error: ld returned 1 exit status
解决编译跳过不兼容库的问题
经过反复查找,发现还是架构不兼容的问题
可以利用armhf架构的gcc来编译就不会有问题
安装armhf的gcc
sudo apt install gcc-arm-linux-gnueabihf
再用他进行编译
arm-linux-gnueabihf-gcc led.c -lwiringPi
可成功编译产生可执行的a.out