控制HC-SR04超声波测距传感器的电路Python库。
adafruit-circuitpython-hcsr04的Python项目详细描述
简介图片::https://readthedocs.org/projects/adafruit-circipython-hcsr04/badge/?version=latest
:目标:https://circuitpython.readthedocs.io/projects/hcsr04/en/latest/
:alt:文档状态
…图片::https://img.shields.io/discord/327254708534116352.svg
:目标:https://discord.gg/nbqh6qu
:alt:discord
图片::https://travis-ci.com/adafruit/adafruit_circuitpython_hcsr04.svg?branch=master
:目标:https://travis ci.com/adafruit/adafruit\u circuitpython\u hcsr04
:alt:build status
…图片::https://github.com/adafruit/adafruit_circuit python_hc sr04/blob/master/docs/hcsr04.jpg
:宽度:300px
:alt:hcsr04
hc-sr04是使用微控制器测量距离的廉价解决方案。此库提供了一个简单的
驱动程序,用于从CircuitPython控制这些传感器。
依赖项
===
此驱动程序依赖于:
*`Adafruit CircuitPython<;https://github.com/adafruit/CircuitPython>;``u
请确保所有依赖项都可用e在circuitpython文件系统上。
这可以通过下载
` adafruit库和驱动程序包<;https://github.com/adafruit/adafruit_circuitpython_bundle>;``来轻松实现。
使用示例
==警告:
HC-SR04使用5V逻辑,因此您必须使用"电平移位器"https://www.adafruit.com/product/2653?q=level%20shifter&;`uu介于它和电路python板(使用3.3v逻辑)之间。注意:
传感器以一种非常基本的方式进行通信,所以不管您选择哪个管脚,只要它们是数字IO管脚(以"``D``"开头的管脚是数字的)。
经理注::
一旦我有机会确定一个安全的方法来做这件事,我计划把它作为
一个特性添加到库中。另请参见:
《Adafruit的生存期和上下文管理器指南》<;https://circuitpython.readthedocs.io/en/latest/docs/design_guide.html生存期和上下文管理器>;`
提供有关使用上下文管理器和circuitpython驱动程序的更多信息。
:任意:`board`
设备上可用的管脚列表。要查看此列表,请先"获取repl
<;http://circuitpython.readthedocs.io/en/latest/docs/pyboard/tutorial/repl.html>;`(链接的指南是为pyboard编写的,但仍然有效),然后输入以下内容:
:
dir(board)
/>sonar=hcsr04(trig,echo)
尝试:
如果为真:
打印(sonar.dist_cm())
睡眠(2)
键盘中断除外:
通过
sonar.deinit()
w,我们使用上下文管理器(the:any:`with<;with>;`statement)创建:类:`~hcsr04.hcsr04`
实例,每2秒获取一次距离,但是上下文管理器处理de-为我们初始化设备。
:
通过
投稿
==
欢迎投稿!请阅读我们的"行为准则
<;https://github.com/adafruit/adafruit_circuit python_hcsr04/blob/master/code_conduct.md>;`
在帮助该项目保持受欢迎之前。
r/>要在本地构建此库,您需要安装
`circuitpython build tools<;https://github.com/adafruit/circuitpython build tools>;``包。
代码块::shell
python3-m venv.env
source.env/bin/activate
pip install circuitpython编译工具
代码块::shell
source.env/bin/activate
,然后运行生成:
。代码块::shell
circuitpython构建包——文件名前缀adafruit-circuitpython-hcsr04——库位置。
----
安装依赖项(请随意重用上面的虚拟环境):
…代码块::shell
source.env/bin/activate
pip安装sphinx sphinx rtd主题
代码块:shell
cd docs
sphinx build-e-w-b html。_ build/html
这将把文档输出到"docs/u build/html"。在浏览器中打开index.html以查看它们。它还将(由于-w)错误的任何警告,像特拉维斯将。这是
本地验证它是否通过的好方法。
:目标:https://circuitpython.readthedocs.io/projects/hcsr04/en/latest/
:alt:文档状态
…图片::https://img.shields.io/discord/327254708534116352.svg
:目标:https://discord.gg/nbqh6qu
:alt:discord
图片::https://travis-ci.com/adafruit/adafruit_circuitpython_hcsr04.svg?branch=master
:目标:https://travis ci.com/adafruit/adafruit\u circuitpython\u hcsr04
:alt:build status
…图片::https://github.com/adafruit/adafruit_circuit python_hc sr04/blob/master/docs/hcsr04.jpg
:宽度:300px
:alt:hcsr04
hc-sr04是使用微控制器测量距离的廉价解决方案。此库提供了一个简单的
驱动程序,用于从CircuitPython控制这些传感器。
依赖项
===
此驱动程序依赖于:
*`Adafruit CircuitPython<;https://github.com/adafruit/CircuitPython>;``u
请确保所有依赖项都可用e在circuitpython文件系统上。
这可以通过下载
` adafruit库和驱动程序包<;https://github.com/adafruit/adafruit_circuitpython_bundle>;``来轻松实现。
使用示例
==警告:
HC-SR04使用5V逻辑,因此您必须使用"电平移位器"https://www.adafruit.com/product/2653?q=level%20shifter&;`uu介于它和电路python板(使用3.3v逻辑)之间。注意:
传感器以一种非常基本的方式进行通信,所以不管您选择哪个管脚,只要它们是数字IO管脚(以"``D``"开头的管脚是数字的)。
经理注::
一旦我有机会确定一个安全的方法来做这件事,我计划把它作为
一个特性添加到库中。另请参见:
《Adafruit的生存期和上下文管理器指南》<;https://circuitpython.readthedocs.io/en/latest/docs/design_guide.html生存期和上下文管理器>;`
提供有关使用上下文管理器和circuitpython驱动程序的更多信息。
:任意:`board`
设备上可用的管脚列表。要查看此列表,请先"获取repl
<;http://circuitpython.readthedocs.io/en/latest/docs/pyboard/tutorial/repl.html>;`(链接的指南是为pyboard编写的,但仍然有效),然后输入以下内容:
:
/>sonar=hcsr04(trig,echo)
尝试:
如果为真:
打印(sonar.dist_cm())
睡眠(2)
键盘中断除外:
通过
sonar.deinit()
w,我们使用上下文管理器(the:any:`with<;with>;`statement)创建:类:`~hcsr04.hcsr04`
实例,每2秒获取一次距离,但是上下文管理器处理de-为我们初始化设备。
:
通过
投稿
==
欢迎投稿!请阅读我们的"行为准则
<;https://github.com/adafruit/adafruit_circuit python_hcsr04/blob/master/code_conduct.md>;`
在帮助该项目保持受欢迎之前。
r/>要在本地构建此库,您需要安装
`circuitpython build tools<;https://github.com/adafruit/circuitpython build tools>;``包。
代码块::shell
python3-m venv.env
source.env/bin/activate
pip install circuitpython编译工具
代码块::shell
source.env/bin/activate
,然后运行生成:
。代码块::shell
circuitpython构建包——文件名前缀adafruit-circuitpython-hcsr04——库位置。
…代码块::shell
pip安装sphinx sphinx rtd主题
代码块:shell
cd docs
sphinx build-e-w-b html。_ build/html
这将把文档输出到"docs/u build/html"。在浏览器中打开index.html以查看它们。它还将(由于-w)错误的任何警告,像特拉维斯将。这是
本地验证它是否通过的好方法。