Toll-Free Customer Support 24/7

Digital Soil Moisture Sensor

/*
* Project name:
DIGITAL SOIL MOISTURE SENSOR
* 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>

unsigned char rx_buffer[10];
unsigned char test[64];
unsigned char number[64];
//unsigned char number_check[64]="+918123902188";
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/ttyAMA0

if((fd = open("/dev/ttyO1", 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("SENSOR TEST BOARD");

rx_buffer[0]=0;
while(rx_buffer[0]!='\r')
{
read(fd, rx_buffer, (1));
}
rx_buffer[0]=0;
while(rx_buffer[0]!='\r')
{
read(fd, rx_buffer, (1));
test[i]=rx_buffer[0];
i++;
}
printf("%s\n", test);
}

Back to top