Quantcast
Viewing all articles
Browse latest Browse all 20046

Re: Garbage on /dev/ttyMFD1 (Edison + Arduino Breakout)

I am not sure how much this will help, but...

 

I know when I started playing around with using an XBee connected to an XBee shield using this IO port, that I had to play around with the code for awhile to get it to work right for me.   The first set of code I got working is my Robot (Arm or Hex or) controlled by Edison talking to Arbotix Commander Remote control.

 

Note: My c/c++ code creates a thread to actually process the IO.  I also open it as device /dev/ttyXBEE where I create an alias to this port.  I am also using the port at the speed 38400...  This code earlier worked on BBBk, ODroid U2/U3, RPI...  But I modified it to be closer to the init code that the Arduino IDE does for the Serial1 object.

 

The initial Init code looks like:

bool Commander::begin(char *pszDevice,  speed_t baud)
{    int err;    // Create our lock to make sure we can do stuff safely    if (pthread_mutex_init(&lock, NULL) != 0)        return false;    _fCancel = false;    // Flag to let our thread(s) know to abort.
#ifdef CMDR_USE_XBEE    _pszDevice = pszDevice;    _baud = baud;       // Lets do our init of the xbee here.    // We will do all of the stuff to intialize the serial port plus we will spawn off our thread.    struct termios tc, tcNew;    if ((fdXBee = open(_pszDevice, O_RDWR | O_NONBLOCK)) == -1)    {        printf("Open Failed\n");        return 0;    }    if (tcgetattr(fdXBee, &tc))    {        perror("tcgetattr()");        return 0;    }    // build new version       bzero(&tcNew, sizeof(tcNew));    //newtios.c_cflag |= _dwBaudRate | CRTSCTS | CS8 | CLOCAL | CREAD;    tcNew.c_cflag = tc.c_cflag;    tcNew.c_cflag &= ~CBAUD;    tcNew.c_cflag |= _baud;    tcNew.c_iflag = IGNPAR;    tcNew.c_oflag = 0;    /* set input mode (non-canonical, no echo,...) */    tcNew.c_lflag = 0;    tcNew.c_cc[VTIME]    = 0;   /* inter-character timer unused */    tcNew.c_cc[VMIN]     = 1;   /* blocking read until 1 chars received */    tcflush(fdXBee, TCIFLUSH);    tcsetattr(fdXBee, TCSANOW, &tcNew);    // Now we need to create our thread for doing the reading from the Xbee    pthread_barrier_init(&_barrier, 0, 2);    err = pthread_create(&tidXBee, NULL, &XBeeThreadProc, this);    if (err != 0)        return false;      // sync startup    pthread_barrier_wait(&_barrier);   

#endif
#ifdef CMDR_USE_SOCKET
    // Now we need to create our thread for doing the reading from the Xbee    err = pthread_create(&tidSocket, NULL, &SocketThreadProc, this);    if (err != 0)        return false;

#endif


    return true;
}

 

If looking at the code would help, my code is up on github (kurte/raspberry_Pi) project in the library/commanderEx.cpp file.  Again it is modified to be similar to what the Edison Arduino system does for Serial1 in the function void TTYUARTClass::begin( const uint32_t dwBaudRate ) in the file TTYUART.cpp.

 

good luck


Viewing all articles
Browse latest Browse all 20046

Trending Articles