Difference between revisions of "Matrix - Ultrasonic Ranger"

From FriendlyELEC WiKi
Jump to: navigation, search
(使用方法)
Line 9: Line 9:
 
* 特性2
 
* 特性2
  
==使用方法==
+
==How To==
===连接===
+
===Connection===
*连接到Tiny4412 SDK (1506)
+
*Connect to Tiny4412 SDK (1506)
::GND针脚:   接地
+
::GND: Ground
::VCC:  接5V
+
::VCC:  5V
 
::ECHO: GPIO PIN1
 
::ECHO: GPIO PIN1
 
::TRIG: GPIO PIN2
 
::TRIG: GPIO PIN2
  
===Linux下的C示例===
+
===Code Sample in C Under Linux===
 
<syntaxhighlight lang="c">
 
<syntaxhighlight lang="c">
 
#include <stdio.h>
 
#include <stdio.h>
Line 44: Line 44:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
===编译并运行示例===
+
===Compile and Run===
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
git clone http://github.com/friendlyarm/fa-hardware.git
 
git clone http://github.com/friendlyarm/fa-hardware.git
Line 52: Line 52:
 
make
 
make
 
</syntaxhighlight>
 
</syntaxhighlight>
将编译生成的hcsr04通过ftp上传到开发板上运行即可测试。
+
Copy your compiled bin to your board and you are ready to go.
  
 
==相关资料==
 
==相关资料==

Revision as of 08:16, 7 August 2015

查看中文

1 介绍

Ultrasonic Ranger

TODO

2 特性

  • 特性1
  • 特性2

3 How To

3.1 Connection

  • Connect to Tiny4412 SDK (1506)
GND: Ground
VCC: 5V
ECHO: GPIO PIN1
TRIG: GPIO PIN2

3.2 Code Sample in C Under Linux

#include <stdio.h>
#include <unistd.h>
#include "libfahw.h"
 
int main(int argc, char ** argv)
{
    int distance = -1;
 
    int echoPin = TINY4412_GPIO_PIN1;
    int triggerPin = TINY4412_GPIO_PIN2;
 
    if (Hcsr04Init(echoPin, triggerPin) == -1) {
        printf("Fail to init hcsr04\n");
    }
 
    if (Hcsr04Read(&distance)==0 && distance != -1) {
        printf("Get distance: %3d cm\n", distance);
    } else {
        printf("Faid to get distance\n");
    }
    Hcsr04DeInit();
    return 0;
}

3.3 Compile and Run

git clone http://github.com/friendlyarm/fa-hardware.git
cd fa-hardware
cd demo
cd matrix-ultrasonic_ranger
make

Copy your compiled bin to your board and you are ready to go.

4 相关资料