Pages: [1]   Go Down
Author Topic: Arduino router connection problem  (Read 532 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

I am currently doing a project on playing and browse online audio content using the router and I am using the Arduino as the UI. Currently there is a problem when connecting the Arduino to the router. Before stating the problem, I would introduce the structure and the first several testing first.

The hardware structure looks like the following:

The code on the Arduino can do the following:
1. When the user clicks the button, the Arduino will send the corresponding message to the router;
2. When the router is sending the message to Arduino, Arduino will display the message on the LCD screen.

The problem is like the following:
1. When the Arduino received the first button click, it will automatically reboot once.
2. After the reboot, when the Arduino received other button clicks, it will not forward it to the router. Instead, it will display the message directly on the screen. Also, the router does not receive anything.

The C++ programme for Arduino settings, Arduino reading (sending message from keyboard to router) and Arduino writing (sending message from router to LCD) looks like the following (The code was successfully tested on the computer-Arduino combination, but no good on router-Arduino combination):

#include <termios.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <iostream>
#include <sys/signal.h>
#include <cstdlib>
#include <cstring>
#include "arduino_driver.h"

using namespace std;
#define BAUDRATE B9600
#define MODEMDEVICE "/dev/ttyUSB0"
#define _POSIX_SOURCE 1
#define O_BINARY 0x8000
#define FALSE 0
#define TRUE 1
volatile int STOPFLAG=FALSE;

void signal_handler_IO (int status);

int wait_flag=TRUE;
int fd, res;
unsigned char buf[255];
int przer=0;

struct sigaction saio;
struct termios oldtio,newtio;
void arduino_setting() {
  system("stty -F /dev/ttyUSB0 9600 cs8 -parenb -crtscts -hupcl");
  if (fd <0) {

  saio.sa_handler = signal_handler_IO;
  saio.sa_flags = 0;
  saio.sa_flags = SA_NODEFER;
  saio.sa_restorer = NULL;

  fcntl(fd, F_SETOWN, getpid());
  fcntl(fd, F_SETFL, FASYNC);

  newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
  newtio.c_iflag = IGNPAR ;
  newtio.c_oflag = 0;
  newtio.c_lflag = 0;
  newtio.c_cc[VINTR] = 0;
  newtio.c_cc[VQUIT] = 0;
  newtio.c_cc[VERASE] = 0;
  newtio.c_cc[VKILL] = 0;
  newtio.c_cc[VEOF] = 1;
  newtio.c_cc[VTIME] = 0;
  newtio.c_cc[VMIN] = 1;
  newtio.c_cc[VSWTC] = 0;
  newtio.c_cc[VSTART] = 0;
  newtio.c_cc[VSTOP] = 0;
  newtio.c_cc[VSUSP] = 0;
  newtio.c_cc[VEOL] = 0;
  newtio.c_cc[VREPRINT] = 0;
  newtio.c_cc[VDISCARD] = 0;
  newtio.c_cc[VWERASE] = 0;
  newtio.c_cc[VLNEXT] = 0;
  newtio.c_cc[VEOL2] = 0;
  tcflush(fd, TCIFLUSH);

char arduino_reading(){    //TODO sometimes this won't stop sending chars even when the arduino is switched off
  //  while (STOPFLAG==FALSE) {
    res = read(fd,buf,1);
    if (buf[0]>='1'&&buf[0]<='9')
//  }
  char info=buf[0];
  return info;

void signal_handler_IO (int status){

void arduino_writing (char anything[]){

So are there any possibilities that settings for the connection between router and computer would be different?

P.S: I have tested the following:
1.use stty -F /dev/ttyUSB0 9600 cs8 -parenb -crtscts –hupcl
2.use echo helloworld >ttyUSB0 and it will display the “hellloworld” on the screen.

Pages: [1]   Go Up
Jump to: