xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

电子电路技术常识:数字信号 & 模拟信号 All In One

电子电路技术常识:数字信号 & 模拟信号 All In One

数模转换 / 模数转换

DA: Digital signal => Analog signal / 数字信号转模拟信号

AD: Analog signal => Digital signal / 模拟信号转数字信号

数字量 &模拟量

普通电灯,只有打开或关闭 2 种状态,与计算机的数字电路 1 或 0 类似,电路信号图上看不具有连续性,所以是数字信号

具有 256 级可变、可调节的亮度的智能 LED 灯,是有连续的多种状态组成,电路信号图上看具有连续性,故是模拟信号

image

demos

image

image

image

面包版

image

源代码


#!/usr/bin/env python3
# coding: utf8

__author__ = 'xgqfrms'
__editor__ = 'vscode'
__version__ = '1.0.1'
__copyright__ = """
  Copyright (c) 2012-2050, xgqfrms; mailto:xgqfrms@xgqfrms.xyz
"""

"""

/**
 *
 * @author xgqfrms
 * @license MIT
 * @copyright xgqfrms
 * @created 2020-01-01
 * @updated 2023-05-01
 *
 * @description
 * @augments
 * @example
 * @link
 *
 */

"""

import RPi.GPIO as GPIO
from time import sleep

# blink
def twinkle(PIN, n):
  # 设置引脚模式为 BCM 编码 ✅
  GPIO.setmode(GPIO.BCM)
  # 指定 GPIO 对应的 PIN 为电流输出针脚
  GPIO.setup(PIN, GPIO.OUT)
  for i in range(n):
    # 高电平,LED 点亮
    GPIO.output(PIN, GPIO.HIGH)
    # 防止 LED 长时间点亮烧坏了
    # 休眠 0.5 秒
    sleep(0.5)
    # 低电平,LED 熄灭
    GPIO.output(PIN, GPIO.LOW)
    # 休眠 0.5 秒
    sleep(0.5)

# 绿黄红 LED 的 BCM GPIO 针脚编号
GYR_PINS = [23, 24, 25]

# BCM 模式
GPIO.setmode(GPIO.BCM)
# 指定 GPIO 针脚为一个电流输出针脚
GPIO.setup(GYR_PINS, GPIO.OUT) # ???

print('启动程序 🐍')

for PIN in GYR_PINS:
  # 高电平,LED 点亮
  # GPIO.output(PIN, GPIO.HIGH)
  # 低电平,LED 熄灭
  GPIO.output(PIN, GPIO.LOW)

try:
  # 无限循环
  while True:
    # GPIO.output(GYR_PINS[0], GPIO.LOW)
    # GPIO.output(GYR_PINS[0], GPIO.HIGH)
    # sleep(1)
    # 绿灯
    twinkle(GYR_PINS[0], 3)
    sleep(1)
    # 黄灯
    twinkle(GYR_PINS[1], 2)
    sleep(1)
    # GPIO.output(GYR_PINS[2], GPIO.LOW)
    # sleep(1)
    # 红灯
    GPIO.output(GYR_PINS[2], 3)
    sleep(1)
except KeyboardInterrupt:
  # Ctrl + C 停止程序
  print('停止程序 🐍')
  # 清除,释放内存
  GPIO.cleanup()


"""
$ py3 ./gyr-led.py

$ python3 ./gyr-led.py

# 可执行文件
$ chmod +x ./gyr-led.py
$ ./gyr-led.py

"""


GPIO 针脚选择 ??? PWM 仅支持的几个 BCM GPIO 针脚

绿黄红 LED 的 BCM GPIO 针脚编号: 23, 24, 25

image

两个树莓派之间,如何进行通信 ???

  1. Wi-Fi
  2. bluetooth 蓝牙
  3. 无线电台广播信号
  4. API service 查询(轮询/消息推送)
  5. CV 计算机视觉识别信号灯颜色 🚥

(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

Python RPi.GPIO docs

https://pythonhosted.org/RPIO/

https://pypi.org/project/RPi.GPIO/

源码

https://github.com/metachris/RPIO

⚠️ This repository has been archived by the owner on Nov 28, 2022.
It is now read-only.

https://github.com/metachris/RPIO/blob/master/source/RPIO/init.py#L75

https://github.com/metachris/RPIO/blob/master/source/RPIO/PWM/init.py#L78

errors

$ python3 -m pip install RPi.GPIO

$ pip3 install RPi.GPIO

python3 -m pip install RPi.GPIO
Defaulting to user installation because normal site-packages is not writeable
Collecting RPi.GPIO
  Using cached RPi.GPIO-0.7.1.tar.gz (29 kB)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: RPi.GPIO
  Building wheel for RPi.GPIO (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [37 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.macosx-10.9-universal2-3.9
      creating build/lib.macosx-10.9-universal2-3.9/RPi
      copying RPi/__init__.py -> build/lib.macosx-10.9-universal2-3.9/RPi
      creating build/lib.macosx-10.9-universal2-3.9/RPi/GPIO
      copying RPi/GPIO/__init__.py -> build/lib.macosx-10.9-universal2-3.9/RPi/GPIO
      running build_ext
      building 'RPi._GPIO' extension
      creating build/temp.macosx-10.9-universal2-3.9
      creating build/temp.macosx-10.9-universal2-3.9/source
      clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -iwithsysroot/System/Library/Frameworks/System.framework/PrivateHeaders -iwithsysroot/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/Headers -arch arm64 -arch x86_64 -Werror=implicit-function-declaration -I/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/include/python3.9 -c source/c_gpio.c -o build/temp.macosx-10.9-universal2-3.9/source/c_gpio.o
      source/c_gpio.c:170:9: warning: cast to smaller integer type 'uint32_t' (aka 'unsigned int') from 'uint8_t *' (aka 'unsigned char *') [-Wpointer-to-int-cast]
          if ((uint32_t)gpio_mem % PAGE_SIZE)
              ^~~~~~~~~~~~~~~~~~
      source/c_gpio.c:171:34: warning: cast to smaller integer type 'uint32_t' (aka 'unsigned int') from 'uint8_t *' (aka 'unsigned char *') [-Wpointer-to-int-cast]
              gpio_mem += PAGE_SIZE - ((uint32_t)gpio_mem % PAGE_SIZE);
                                       ^~~~~~~~~~~~~~~~~~
      2 warnings generated.
      source/c_gpio.c:170:9: warning: cast to smaller integer type 'uint32_t' (aka 'unsigned int') from 'uint8_t *' (aka 'unsigned char *') [-Wpointer-to-int-cast]
          if ((uint32_t)gpio_mem % PAGE_SIZE)
              ^~~~~~~~~~~~~~~~~~
      source/c_gpio.c:171:34: warning: cast to smaller integer type 'uint32_t' (aka 'unsigned int') from 'uint8_t *' (aka 'unsigned char *') [-Wpointer-to-int-cast]
              gpio_mem += PAGE_SIZE - ((uint32_t)gpio_mem % PAGE_SIZE);
                                       ^~~~~~~~~~~~~~~~~~
      2 warnings generated.
      clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -iwithsysroot/System/Library/Frameworks/System.framework/PrivateHeaders -iwithsysroot/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/Headers -arch arm64 -arch x86_64 -Werror=implicit-function-declaration -I/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/include/python3.9 -c source/common.c -o build/temp.macosx-10.9-universal2-3.9/source/common.o
      clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -iwithsysroot/System/Library/Frameworks/System.framework/PrivateHeaders -iwithsysroot/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/Headers -arch arm64 -arch x86_64 -Werror=implicit-function-declaration -I/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/include/python3.9 -c source/constants.c -o build/temp.macosx-10.9-universal2-3.9/source/constants.o
      clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -iwithsysroot/System/Library/Frameworks/System.framework/PrivateHeaders -iwithsysroot/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/Headers -arch arm64 -arch x86_64 -Werror=implicit-function-declaration -I/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/include/python3.9 -c source/cpuinfo.c -o build/temp.macosx-10.9-universal2-3.9/source/cpuinfo.o
      clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -iwithsysroot/System/Library/Frameworks/System.framework/PrivateHeaders -iwithsysroot/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/Headers -arch arm64 -arch x86_64 -Werror=implicit-function-declaration -I/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/include/python3.9 -c source/event_gpio.c -o build/temp.macosx-10.9-universal2-3.9/source/event_gpio.o
      source/event_gpio.c:24:10: fatal error: 'sys/epoll.h' file not found
      #include <sys/epoll.h>
               ^~~~~~~~~~~~~
      1 error generated.
      error: command '/usr/bin/clang' failed with exit code 1
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for RPi.GPIO
  Running setup.py clean for RPi.GPIO
Failed to build RPi.GPIO
ERROR: Could not build wheels for RPi.GPIO, which is required to install pyproject.toml-based projects
➜  Python git:(master) ✗

https://pypi.org/project/RPi.GPIO/

refs

https://www.bilibili.com/video/BV16U4y1879Q/?p=14

无线小电台

https://www.bilibili.com/video/BV1eT4y157dG/



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2023-05-04 21:32  xgqfrms  阅读(83)  评论(1编辑  收藏  举报