Difference between revisions of "Matrix - Sound Sensor"

From FriendlyELEC WiKi
Jump to: navigation, search
(特性)
(使用方法)
Line 9: Line 9:
 
* 2.54mm spacing pin interface
 
* 2.54mm spacing pin interface
  
==使用方法==
+
==How To==
===连接===
+
===Connection===
*连接到Tiny4412 SDK (1506)
+
*Connect Tiny4412 SDK (1506)
::G:   接地
+
::G: Ground
::V:  接5V
+
::V:  5V
 
::S:  GPIO PIN1
 
::S:  GPIO PIN1
  
===Linux下的C示例===
+
===Code Sample in C Under Linux===
 
<syntaxhighlight lang="c">
 
<syntaxhighlight lang="c">
 
#include <stdio.h>
 
#include <stdio.h>
Line 55: Line 55:
 
</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

Revision as of 10:57, 4 August 2015

查看中文

1 Introduction

Sound Sensor

By default this module's output level is high. When it detects sound signals its output level will turn low. When sound signals are not detected its output will turn high again without time delay. There is a variable resistor which you can use to control the threshold value of a sound volume. Only when a sound volume's value is greater than this threshold value the module can detect it. Turning clockwise increases this threshold value. Turning anticlockwise decreases this value.

2 Features

  • Variable threshold value
  • 2.54mm spacing pin interface

3 How To

3.1 Connection

  • Connect Tiny4412 SDK (1506)
G: Ground
V: 5V
S: GPIO PIN1

3.2 Code Sample in C Under Linux

#include <stdio.h>
#include "libfahw.h"
 
static struct sensor sound[] = {
        {
                TINY4412_GPIO_PIN1,
                IRQ_TYPE_EDGE_BOTH,
        }
};
 
int main(void)
{
    int i;
    int retSize = -1;
    char value[ARRAY_SIZE(sound)];
    int devFD = -1;
    if ((devFD =sensorInit(sound, ARRAY_SIZE(sound))) == -1) {
        printf("Fail to init sensor\n");
        return -1;
    }
 
    if (( retSize = sensorRead(devFD, value, ARRAY_SIZE(sound)) ) == -1) {
        printf("Fail to read sensors\n");
    }
    if (retSize > 0) {
        i = 0;
        for(i=0; i<retSize; i++)
        {
            printf("sound[%d]:%d\n", i, value[i]);
        }
        printf("\n");
    }
    sensorDeinit(devFD);
    return 0;
}

3.3 Compile and Run

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

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

4 相关资料