8 Channel Relay Board- Serial
/*
* Project name:RELAY SERIAL
* Copyright
(c) Researchdesignlab.com
* Test configuration:
BOARD: RASPBERRY PI & BEAGLEBONE
Software: ECLIPSE
*/
#include <stdio.h>
#include <stddef.h>
#include <termios.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <string.h>
int count,i,flag,k;
int main()
{
FILE *ofp_uart1_tx, *ofp_uart1_rx;
termios uart1;
int fd,f;
int m,n,d,e,a,b,c,q,r,x,y,z,t,u,o;
//IN CASE OF RASPBERRY PI THE FILE NAME IS /dev/AMA0
if((fd = open("/dev/ttyAMA0", O_RDWR | O_NOCTTY )) < 0)
{
printf("Unable to open uart1 access.\n");
}
if(tcgetattr(fd, &uart1) < 0)
{
printf("Could not get attributes of UART1 at ttyO1\n");
}
if(cfsetospeed(&uart1, B9600) < 0)
{
printf("Could not set baud rate \n");
}
else
{
printf("Baud rate: 9600\n");
}
uart1.c_iflag = 0;
uart1.c_oflag = 0;
uart1.c_lflag = 0;
tcsetattr(fd, TCSANOW, &uart1);
tcflush(fd,TCIFLUSH);
printf("RELAY1 ON\r\n");
d = write(fd, "1N", 2);
sleep(1);
printf("RELAY1 OFF\r\n");
x = write(fd, "1F", 2);
sleep(1);
printf("RELAY2 ON\r\n");
d = write(fd, "2N", 2);
sleep(1);
printf("RELAY2 OFF\r\n");
x = write(fd, "2F", 2);
sleep(1);
printf("RELAY3 ON\r\n");
d = write(fd, "3N", 2);
sleep(1);
printf("RELAY3 OFF\r\n");
x = write(fd, "3F", 2);
sleep(1);
printf("RELAY4 ON\r\n");
d = write(fd, "4N", 2);
sleep(1);
printf("RELAY4 OFF\r\n");
x = write(fd, "4F", 2);
sleep(1);
printf("RELAY5 ON\r\n");
d = write(fd, "5N", 2);
sleep(1);
printf("RELAY5 OFF\r\n");
x = write(fd, "5F", 2);
sleep(1);
printf("RELAY6 ON\r\n");
d = write(fd, "6N", 2);
sleep(1);
printf("RELAY6 OFF\r\n");
x = write(fd, "6F", 2);
sleep(1);
printf("RELAY7 ON\r\n");
d = write(fd, "7N", 2);
sleep(1);
printf("RELAY7 OFF\r\n");
x = write(fd, "7F", 2);
sleep(1);
printf("RELAY8 ON\r\n");
d = write(fd, "8N", 2);
sleep(1);
printf("RELAY8 OFF\r\n");
x = write(fd, "8F", 2);
sleep(1);
close(fd);
}