面包板使用教程 All In One
面包板使用教程 All In One
树莓派
3V 针脚供电
Raspberry Pi 3B
GPIO
干电池
3V (1.5x2节) 才能带动 LED 发光
(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!
面包板
https://www.yahboom.com/public/download/AR/4.下载专区/面包板使用简介.pdf
http://www.i-element.org/breadboard/
https://learn.sparkfun.com/tutorials/how-to-use-a-breadboard
虚拟面包板
导通图解
揭开
面包板
背面的双面胶贴纸
✅
https://youtu.be/spOVPgAwWNE?t=122
https://www.youtube.com/watch?v=SoGhKNgy7j0
万用表, 导通测试
https://www.youtube.com/watch?v=oWVDOomVKok
demos
https://github.com/xgqfrms/Raspberry-Pi/blob/master/Pico/zh-cn/chapter-06.md
GPIO & LED
Raspberry Pi &
LED
$ cat gpio.py
$ vim gpio.py
# 命令行传入参数
$ ./gpio.py 3
gpio.py
#!/usr/bin/env python3
# coding: utf8
import RPi.GPIO as GPIO
from datetime import datetime
import time
import sys
arg1 = sys.argv[1]
print("arg1 =", arg1);
# Python 获取时间戳 ✅
now = datetime.now()
# 转换为指定的格式
currentTime = now.strftime("%Y-%m-%d %H:%M:%S")
print("⏰ current datetime =", currentTime);
# $ pinout 命令查看,或 https://pinout.xyz/
# 指定 BCM 模式下的 GPIO 针脚编号是 12
# 对应的物理针脚编号是 32
PIN = 12
# BCM 模式
GPIO.setmode(GPIO.BCM)
# 指定 GPIO 针脚为一个电流输出针脚
GPIO.setup(PIN, GPIO.OUT)
# 输出低电平
GPIO.output(PIN, GPIO.LOW)
# index
i = 0
# 类型转换,str => int
n = int(arg1)
print("n =", n)
print('开始闪烁⏳')
while (i < n):
print("i =", i)
# 高电平,LED 点亮
GPIO.output(PIN, GPIO.HIGH)
# 休眠 1 秒,防止 LED 长时间点亮烧坏了
time.sleep(1.0)
# 低电平,LED 熄灭
GPIO.output(PIN, GPIO.LOW)
# 休眠 1 秒
time.sleep(1.0)
i = i + 1
# 输出低电平,LED 关闭
# GPIO.output(PIN, GPIO.LOW)
# 清除,释放内存
GPIO.cleanup()
print('结束闪烁 👌🏻')
crontab
$ crontab -l
# Edit this file to introduce tasks to be run by cron.
# 自动化执行脚本 ✅
# 每隔 3 分钟执行一次
# 分钟 小时 天 月 周
#3 * * * * pi sh ./Desktop/gpio.py
# user python 参数
# 3 * * * * python ./gpio.py 3
# 绝对路径 python ✅
# 二合一输出 log 🚀
# 每小时的第3 分钟执行一次
# >> 追加 log, > 覆盖 log
*/30 * * * * /usr/bin/python /home/pi/Desktop/gpio.py 3 >> /home/pi/Desktop/gpio.log.txt 2>&1
# Vixie Cron 不支持非标准 cron bug ❌
# 每个小时,从0 开始,每隔 5 分钟执行一次 ✅
# */5 * * * * /usr/bin/python /home/pi/Desktop/five.py >> /home/pi/Desktop/five.log.txt 2>&1
# */10 * * * * /usr/bin/python /home/pi/Desktop/five.py >> /home/pi/Desktop/ten.log.txt 2>&1
# 用户 crontab(⚠️ 没有用户字段 pi )
$ cat gpio.log.txt
arg1 = 3
⏰ current datetime = 2023-04-13 14:00:01
n = 3
开始闪烁⏳
i = 0
i = 1
i = 2
结束闪烁 👌🏻
arg1 = 3
⏰ current datetime = 2023-04-13 14:30:01
n = 3
开始闪烁⏳
i = 0
i = 1
i = 2
结束闪烁 👌🏻
arg1 = 3
⏰ current datetime = 2023-04-13 15:00:01
n = 3
开始闪烁⏳
i = 0
i = 1
i = 2
结束闪烁 👌🏻
arg1 = 3
⏰ current datetime = 2023-04-13 15:30:01
n = 3
开始闪烁⏳
i = 0
i = 1
i = 2
结束闪烁 👌🏻
arg1 = 3
⏰ current datetime = 2023-04-13 16:00:01
n = 3
开始闪烁⏳
i = 0
i = 1
i = 2
结束闪烁 👌🏻
arg1 = 3
⏰ current datetime = 2023-04-13 16:30:01
n = 3
开始闪烁⏳
i = 0
i = 1
i = 2
结束闪烁 👌🏻
arg1 = 3
⏰ current datetime = 2023-04-13 17:00:01
n = 3
开始闪烁⏳
i = 0
i = 1
i = 2
结束闪烁 👌🏻
arg1 = 3
⏰ current datetime = 2023-04-13 17:30:01
n = 3
开始闪烁⏳
i = 0
i = 1
i = 2
结束闪烁 👌🏻
arg1 = 3
⏰ current datetime = 2023-04-13 18:00:01
n = 3
开始闪烁⏳
i = 0
i = 1
i = 2
结束闪烁 👌🏻
GPIO
针脚图解
https://www.raspberrypi.com/documentation/computers/os.html#gpio-and-the-40-pin-header
refs
https://www.cnblogs.com/xgqfrms/tag/GPIO/
https://github.com/xgqfrms/Raspberry-Pi/tree/master/Pico
©xgqfrms 2012-2021
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/17266194.html
未经授权禁止转载,违者必究!