Difference between revisions of "BakeBit - Ultrasonic Ranger"

From FriendlyELEC WiKi
Jump to: navigation, search
 
(7 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
==Introduction==
 
==Introduction==
 
[[File:BakeBit - Ultrasonic.jpg|thumb|Ultrasonic Ranger]]
 
[[File:BakeBit - Ultrasonic.jpg|thumb|Ultrasonic Ranger]]
*BakeBit - Ultrasonic Ranger是超声波模块,模块使用了一个人超声波发射器和一个接收器,经发射器发射出波长约6mm,频率为40KHZ的超声波信号,在传输的过程中,超声波碰到障碍物会反射形成反射回波,接收器接收到反射回波,通过压电效应的换能器产生mV级的微弱电压信号。
+
* The BakeBit - Ultrasonic Ranger is an ultrasonic module.The module's sensor emits a sound wave whose wave length is around 6mm and frequency is 40K Hz, which bounces off a reflective surface and returns to the sensor. Then, using the amount of time it takes for the wave to return to the sensor, the distance to the object can be computed.The receiver converts ultrasound waves to electrical signals in mV.
*给模块发送一个触发信号,模块开始发出超声波测距,同时在输出脚产生高电平,当检测到反射回波后,模块输出脚输出低电平。模块输出的高电平信号持续的时间就是超声波在空气中传播的时间,按照测试距离=(高电平时间*声速(340M/S))/2就可以算出超声波到障碍物的距离。
+
* The master sends a signal to the module starting to emit a sound wave. After the module receives the returned signal it will will generate a high level indicating the elapsed time and the distance will be calculated by distance = (elapsed time * speed of sound)/2.
  
==特性==
+
==Hardware Spec==
* 使用标准的2.0mm 4 Pin BakeBit接口
+
* Standard 2.0mm pitch 4-Pin BakeBit Interface
* 测试距离:5cm-300cm
+
* Range: 5cm - 300cm
* 测试精度:1cm
+
* Accuracy: 1cm
* PCB尺寸(mm):24x42
+
* PCB dimension(mm): 24 x 42
 
[[File:BakeBit - Ultrasonic_Top_PCB.png | frameless|400px|BakeBit - Ultrasonic_Top]]
 
[[File:BakeBit - Ultrasonic_Top_PCB.png | frameless|400px|BakeBit - Ultrasonic_Top]]
 
[[File:BakeBit - Ultrasonic_Bottom_PCB.png | frameless|400px|BakeBit - Ultrasonic_Bottom]]
 
[[File:BakeBit - Ultrasonic_Bottom_PCB.png | frameless|400px|BakeBit - Ultrasonic_Bottom]]
  
* 引脚说明:
+
* Pin Desription:
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
|名称 || 描述
+
|Pin || Description
 
|-
 
|-
|GND  ||
+
|GND  || Ground
 
|-
 
|-
|5V    || 电源5V
+
|5V    || 5V Supply Voltage
 
|-
 
|-
|NC    ||
+
|NC    || Not Connected
 
|-
 
|-
|SIG  || 信号
+
|SIG  || Signal
 
|}
 
|}
== 示例程序:Ultrasonic Sensor with LED ==
 
  
这个示例演示使用距离传感器来探测障碍物,当探测到前方有障碍物时,亮起LED进行报警。
+
== Code Sample:Ultrasonic Sensor with LED ==
  
=== 硬件连接 ===
+
This code sample shows how to use the ultrasonic sensor module to measure a distance. When the module detects an object in front of itself the LED will be turned on.
简单的将 LED 模块插入 D3接口,将 距离传感器 插入 D4 接口,如下面这样:
+
 
 +
=== Hardware Setup ===
 +
Connect the LED module to the NanoHat Hub's D3 and the ultrasonic sensor module to the NanoHat Hub's D4:
  
 
::{| class="wikitable"
 
::{| class="wikitable"
Line 40: Line 41:
 
|}
 
|}
  
=== 示例源代码 ===
+
=== Source Code ===
  
 
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
Line 88: Line 89:
  
  
=== 运行示例 ===
+
=== Run Code Sample ===
 
   
 
   
假设你已经参考[http://wiki.friendlyarm.com/bakebit bakebit教程]安装了BakeBit源代码,<br />
+
Before you run the code sample you need to follow the steps in [http://wiki.friendlyarm.com/bakebit bakebit tutorial] to install the BakeBit package.<br />
要运行示例程序,可以在开发板上进入 BakeBit/Software/Python目录,运行bakebit_prj_Ultrasonic_Sensor_with_LED.py:
+
Enter the "BakeBit/Software/Python" directory and run the "bakebit_prj_Ultrasonic_Sensor_with_LED.py" program:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
cd ~/BakeBit/Software/Python
 
cd ~/BakeBit/Software/Python
Line 97: Line 98:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
=== 运行结果 ===
+
=== Observation ===
  
当距离传感器检测到前方10厘米处有障碍物时,LED将被点亮来告警,没有障碍物挡住时LED自动熄灭。
+
When an object is in front of the sensor module within 10 cm the LED will be turned on otherwise the LED will be off.
  
==相关资料==
+
==Resources==
 
*[Schematic]([http://wiki.friendlyarm.com/wiki/images/e/e0/12-SCHEMATIC_Ultrasonic.pdf BakeBit - Ultrasonic Ranger.pdf])
 
*[Schematic]([http://wiki.friendlyarm.com/wiki/images/e/e0/12-SCHEMATIC_Ultrasonic.pdf BakeBit - Ultrasonic Ranger.pdf])
*[BakeBit Github项目](https://github.com/friendlyarm/BakeBit)
+
*[BakeBit Github Project Page](https://github.com/friendlyarm/BakeBit)
*[BakeBit Starter Kit手册](http://wiki.friendlyarm.com/bakebit/bakebit_starter_kit_manual_cn.pdf)
+
*[BakeBit Starter Kit User's Manual](http://wiki.friendlyarm.com/bakebit/bakebit_starter_kit_manual_en.pdf)
 +
 
 +
==Update Log==
 +
===December-15-2016===
 +
* Released English version
 +
 
 +
===Jan-19-2017===
 +
* Renamed "NEO-Hub" to "NanoHat-Hub"
 +
 
 +
===Jan-20-2017===
 +
* Renamed "NanoHat-Hub" to "NanoHat Hub"

Latest revision as of 08:22, 20 January 2017

查看中文

1 Introduction

Ultrasonic Ranger
  • The BakeBit - Ultrasonic Ranger is an ultrasonic module.The module's sensor emits a sound wave whose wave length is around 6mm and frequency is 40K Hz, which bounces off a reflective surface and returns to the sensor. Then, using the amount of time it takes for the wave to return to the sensor, the distance to the object can be computed.The receiver converts ultrasound waves to electrical signals in mV.
  • The master sends a signal to the module starting to emit a sound wave. After the module receives the returned signal it will will generate a high level indicating the elapsed time and the distance will be calculated by distance = (elapsed time * speed of sound)/2.

2 Hardware Spec

  • Standard 2.0mm pitch 4-Pin BakeBit Interface
  • Range: 5cm - 300cm
  • Accuracy: 1cm
  • PCB dimension(mm): 24 x 42

BakeBit - Ultrasonic_Top BakeBit - Ultrasonic_Bottom

  • Pin Desription:
Pin Description
GND Ground
5V 5V Supply Voltage
NC Not Connected
SIG Signal

3 Code Sample:Ultrasonic Sensor with LED

This code sample shows how to use the ultrasonic sensor module to measure a distance. When the module detects an object in front of itself the LED will be turned on.

3.1 Hardware Setup

Connect the LED module to the NanoHat Hub's D3 and the ultrasonic sensor module to the NanoHat Hub's D4:

Ultrasonic Sensor with LED-1.jpg Ultrasonic Sensor with LED-2.jpg

3.2 Source Code

import bakebit
import time
 
# Connect the BakeBit Ultrasonic Ranger to digital port D4
# SIG,NC,VCC,GND
ultrasonic_ranger = 4
 
# Connect the BakeBit LED to digital port D3
led = 3                                                                      
 
bakebit.pinMode(led,"OUTPUT")
light = 0
 
while True:
    try:
        # Read distance value from Ultrasonic
	distance = bakebit.ultrasonicRead(ultrasonic_ranger)
        print(distance)
	if distance > 0:
		if distance<10: 
			if light == 0:
				print("\ton")
				bakebit.digitalWrite(led,1)
				light = 1
		else:
			if light == 1:
				print("\toff")
				bakebit.digitalWrite(led,0)
				light = 0
	time.sleep(.2)
 
    except KeyboardInterrupt:
	bakebit.digitalWrite(led,0)
        break
 
    except TypeError:
        print ("Error")
    except IOError:
        print ("Error")

Github


3.3 Run Code Sample

Before you run the code sample you need to follow the steps in bakebit tutorial to install the BakeBit package.
Enter the "BakeBit/Software/Python" directory and run the "bakebit_prj_Ultrasonic_Sensor_with_LED.py" program:

cd ~/BakeBit/Software/Python
sudo python bakebit_prj_Ultrasonic_Sensor_with_LED.py

3.4 Observation

When an object is in front of the sensor module within 10 cm the LED will be turned on otherwise the LED will be off.

4 Resources

5 Update Log

5.1 December-15-2016

  • Released English version

5.2 Jan-19-2017

  • Renamed "NEO-Hub" to "NanoHat-Hub"

5.3 Jan-20-2017

  • Renamed "NanoHat-Hub" to "NanoHat Hub"