[vc_row][vc_column width=”1/1″][vc_column_text]
This demo is used to control relay, when turn on the delay, a LED on the module will light on; when turn off relay, LED will also light off.
[/vc_column_text][vc_tour][vc_tab title=”Hardware list” tab_id=”1450923182-1-52″][vc_column_text]
- 96board
- Liner Base Mezzanine Card
- Relay module of Linker kit
- 4-pin cable x 2
[/vc_column_text][/vc_tab][vc_tab title=”Steps” tab_id=”1450923182-2-69″][vc_column_text]
Connect
Connect relay module to D2 port.
[/vc_column_text][/vc_tab][vc_tab title=”Program ” tab_id=”1450923205563-2-1″][vc_column_text]
#include <stdio.h> #include <stdlib.h> #include "libsoc_gpio.h" #include "libsoc_debug.h" #define GPIO_CS 13 int main() { gpio *gpio_cs; libsoc_set_debug(1); gpio_cs = libsoc_gpio_request(GPIO_CS,LS_SHARED); if(gpio_cs == NULL) { goto fail; } libsoc_gpio_set_direction(gpio_cs,OUTPUT); if(libsoc_gpio_get_direction(gpio_cs) != OUTPUT) { printf("Failed to set direction to OUTPUT\n"); goto fail; } while(1) { libsoc_gpio_set_level(gpio_cs,HIGH); usleep(1000000); libsoc_gpio_set_level(gpio_cs,LOW); usleep(1000000); } fail: if(gpio_cs) { libsoc_gpio_free(gpio_cs); } return EXIT_SUCCESS; }
[/vc_column_text][/vc_tab][vc_tab title=”Program and run” tab_id=”1450923206593-3-1″][vc_column_text]
gcc gpio_test.c -o gpio_test -lsoc sudo ./gpio_test <img class="alignnone" src="http://learn.linksprite.com/wp-content/uploads/2015/12/6-1.png" alt="6-1" />
Every second the relay will change its state, also the LED will blink.
[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row][vc_row][vc_column width=”1/1″][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.