Matrix - Ultrasonic Ranger/zh

From FriendlyELEC WiKi
Revision as of 10:47, 12 August 2015 by Jjm (Talk | contribs) (特性)

Jump to: navigation, search

English

1 介绍

Ultrasonic Ranger

TODO

2 特性

  • 特性1
  • 特性2
  • PCB尺寸(mm):20x40

超声波PCB

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 相关资料