Difference between revisions of "Matrix - Relay"
From FriendlyELEC WiKi
(→介绍) |
|||
Line 10: | Line 10: | ||
* 触点电流可达10A | * 触点电流可达10A | ||
* 2.54mm排针接口,接线方便,通用性强 | * 2.54mm排针接口,接线方便,通用性强 | ||
+ | |||
+ | ==使用方法== | ||
+ | ===连接=== | ||
+ | *连接到Tiny4412 SDK (1506) | ||
+ | ::将配件S针脚连接到GPIO PIN1, V接5V,G接地 | ||
+ | |||
+ | ===Linux下的C示例=== | ||
+ | <syntaxhighlight lang="c"> | ||
+ | #include <stdio.h> | ||
+ | #include <string.h> | ||
+ | #include "libfahw.h" | ||
+ | |||
+ | int main(int argc, char ** argv) | ||
+ | { | ||
+ | char *status = "off"; | ||
+ | if (argc != 2) { | ||
+ | printf("Set relay on\n"); | ||
+ | } else { | ||
+ | status = argv[1]; | ||
+ | printf("Set relay %s\n", argv[1]); | ||
+ | } | ||
+ | |||
+ | int pin = TINY4412_GPIO_PIN1; | ||
+ | int ret = -1; | ||
+ | if ((ret = exportGPIOPin(pin)) != 0) { | ||
+ | printf("exportGPIOPin(%d) failed!", pin); | ||
+ | } | ||
+ | if ((ret = setGPIODirection(pin, GPIO_OUT)) != 0) { | ||
+ | printf("setGPIODirection(%d) failed", pin); | ||
+ | } | ||
+ | |||
+ | if (strcmp(status, "on") == 0) { | ||
+ | ret = setGPIOValue(pin, GPIO_LOW); | ||
+ | } else { | ||
+ | ret = setGPIOValue(pin, GPIO_HIGH); | ||
+ | } | ||
+ | return ret; | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | ===编译并运行示例=== | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | git clone http://github.com/friendlyarm/fa-hardware.git | ||
+ | cd fa-hardware | ||
+ | cd demo | ||
+ | cd matrix-relay | ||
+ | make | ||
+ | </syntaxhighlight> | ||
+ | 将编译生成的relay通过ftp上传到开发板上运行即可测试。 | ||
+ | |||
+ | ==相关资料== |
Revision as of 09:02, 24 July 2015
Contents
1 介绍
这是一个单刀双掷继电器,线圈电压为直流5V,触点电流可达10A,适合驱动直流或交流大功率负载。NO为常开触点,NC为常闭触点,COM为公共触点。当向S引脚施加高电平,继电器线圈导通,此时NO触点断开,NC触点闭合。
2 特性
- 1 Form C
- 5V线圈电压,控制信号为3.3/5V
- 触点电流可达10A
- 2.54mm排针接口,接线方便,通用性强
3 使用方法
3.1 连接
- 连接到Tiny4412 SDK (1506)
- 将配件S针脚连接到GPIO PIN1, V接5V,G接地
3.2 Linux下的C示例
#include <stdio.h> #include <string.h> #include "libfahw.h" int main(int argc, char ** argv) { char *status = "off"; if (argc != 2) { printf("Set relay on\n"); } else { status = argv[1]; printf("Set relay %s\n", argv[1]); } int pin = TINY4412_GPIO_PIN1; int ret = -1; if ((ret = exportGPIOPin(pin)) != 0) { printf("exportGPIOPin(%d) failed!", pin); } if ((ret = setGPIODirection(pin, GPIO_OUT)) != 0) { printf("setGPIODirection(%d) failed", pin); } if (strcmp(status, "on") == 0) { ret = setGPIOValue(pin, GPIO_LOW); } else { ret = setGPIOValue(pin, GPIO_HIGH); } return ret; }
3.3 编译并运行示例
git clone http://github.com/friendlyarm/fa-hardware.git cd fa-hardware cd demo cd matrix-relay make
将编译生成的relay通过ftp上传到开发板上运行即可测试。