Skip to content

通过知识获得解放,通过技术获得自由

Menu
  • 专题目录
  • 液压相关
    • 液压技术
    • 液压相邻技术
    • 液压应用
  • 计算机相关
    • 计算机和软件
    • 网络和网站技术
  • 哲学
  • 关于本站
Menu

树莓派GPIO使用和测试[0]

Posted on 2023年11月14日 by

树莓派4b的GPIO是其输入输出模块。

  • 硬件接口

  • 软件环境配置

1)检查python版本

python

2)按python的GPIO库

apt-get install rpi.gpio

检查GPIO

gpio readall

不识别GPIO版本,需要安装wiringPi(http://wiringpi.com/)

wget https://project-downloads.drogon.net/wiringpi-latest.deb
sudo dpkg -i wiringpi-latest.deb

再次检查

gpio readall

pinout

其他常见硬件的pin检查:https://pinout.xyz/boards

  • 软硬件结合测试

1)硬件连接

2)测试代码test2.py

注意此处操作对象按照gpio readall中的name项,另外以下脚本不能再win10下采用text文本存储。

#!/usr/bin/python
## Blinking LED ###################################
import RPi.GPIO as GPIO   ## Import GPIO library
import time               ## Need this for blink delay
GPIO.setmode(GPIO.BOARD)  ## Use board pin numbering
GPIO.setwarnings(False)   ## Disable "Channel already
                          ## in use" warning
led = 7                   ## Variable for pin number
GPIO.setup(led, GPIO.OUT) ## Set pin to output
## Blink the LED 60 times, once per second for 2 minutes
print "Blinking"          ## Blinking in progress
for x in range(0, 59):    ## repeats 60 times
     GPIO.output(led, 1)  ## Turn LED on
     time.sleep(1)        ## Keep it on for 1 second
     GPIO.output(led, 0)  ## Turn LED off
     time.sleep(1)        ## Wait 1 second
GPIO.cleanup()

3)效果:

测试通过

  • linux shell直接控制

注意此处操作对象按照gpio readall中的BCM项

echo 4 > /sys/class/gpio/export  #创建一个可控硬件GPIO7的BCM为4
echo out > /sys/class/gpio/gpio4/direction  控制GPIO4的方向
echo 1 > /sys/class/gpio/gpio4/value  让PIN处于高电压3.3V
echo 0 > /sys/class/gpio/gpio4/value  让PIN处于低电压0V
echo 4 > /sys/class/gpio/unexport  #释放端口

测试通过

  • 补充

安装截图软件,为了使用screenshot截图,需要安装

apt-get scrot

 

参考资料:

  1. http://www.52pi.net/archives/1918
  2. Learning Computer Architecture with Raspberry Pi by Eben Upton, Jeffrey Duntemann 2016 (1st Edition)
  3. https://pinout.xyz/pinout/wiringpi
  4. http://wiringpi.com/download-and-install/
  5. https://www.cnblogs.com/guochaoxxl/p/11728108.html
  6. https://blog.csdn.net/qq_43161960/article/details/108305708

欢迎回来

希望本站对你有所帮助!

如有疑问请联系info@fanlog.org
2023 年 11 月
一二三四五六日
 12345
6789101112
13141516171819
20212223242526
27282930 
« 6 月    

AI辅助 (17)

© 2025 | Powered by Superbs Personal Blog theme
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT