Difference between revisions of "Matrix - Ultrasonic Ranger"

From FriendlyELEC WiKi
Jump to: navigation, search
(Created page with "==介绍== Ultrasonic Ranger TODO ==特性== * 特性1 * 特性2 ==使用方法== ===连接=== *连接到Tiny4412 SDK (1506) ::GND针脚:...")
 
(连接)
Line 12: Line 12:
 
::GND针脚:    接地
 
::GND针脚:    接地
 
::VCC:  接5V
 
::VCC:  接5V
::TRIG: GPIO PIN1
+
::ECHO: GPIO PIN1
::ECHO: GPIO PIN2
+
::TRIG: GPIO PIN2
  
 
===Linux下的C示例===
 
===Linux下的C示例===

Revision as of 06:43, 31 July 2015

1 介绍

Ultrasonic Ranger

TODO

2 特性

  • 特性1
  • 特性2

3 使用方法

3.1 连接

  • 连接到Tiny4412 SDK (1506)
GND针脚: 接地
VCC: 接5V
ECHO: GPIO PIN1
TRIG: GPIO PIN2

3.2 Linux下的C示例

#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 编译并运行示例

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

将编译生成的hcsr04通过ftp上传到开发板上运行即可测试。

4 相关资料