Reading serial from Ubuntu

Discussion in 'Troubleshooting' started by ajfisher, Sep 19, 2014.

  1. ajfisher

    ajfisher New Member

    Joined:
    Sep 5, 2014
    Messages:
    5
    Likes Received:
    0
    Hi all.

    Have been pulling my hair out for a few days on this.

    Background - I have built a minimal version of Ubuntu 14.04 that I've build with all the base packages I need, but no desktop. I want to use my Udoo in a robot so have no need for desktop environment and all the extra cruft that comes with the default install. Everything is working as I expect, wired and wireless network, serial console, nodejs, everything absolutely fine.

    The one thing I cannot get to work though is the connection between the i.MX6 and SAM3X.

    For reference. I have programmed the SAM3X using arduino from my PC absolutely no problem (doing the whole remove jumper thing) and I've got a sketch doing this:

    Code:
    int counter = 0;
    void setup() {
    
      Serial.begin(115200);
    }
    
    void loop() {
      Serial.println(counter);
      delay(1000);
    }
    
    When watching this from the Arduino serial monitor I get the expected counter output. If, from my desktop, I do screen /dev/ttyUSB0 115200 - I get the expected counting output.

    Thus, I am happy that my code is running as expected on the SAM3X side.

    So now I replace the serial jumper and connect to Ubuntu on the Udoo in a terminal. I can log in and I can see the SAM3X devices:

    /dev/ttymxc0, /dev/ttymxc1, /dev/ttymxc3

    From the examples, I understand that the device I need to connect to is /dev/ttymxc3

    However if I try to:

    screen /dev/ttymxc3 115200

    then I get nothing - I get a connection but no data. Likewise if I try to do something like:

    cat /dev/ttymxc3

    It will just sit there not outputting anything (again suggesting a connection but not being able to read the data).

    I've read what I can make of the manual and the tutorials but can't see what I'm missing.

    Any help will be hugely appreciated as I feel like this is the only thing stopping me from using the Udoo to do something fun with it and it has been frustrating me for days trying to get this to work.

    Kind regards
    Andrew
     
  2. ajfisher

    ajfisher New Member

    Joined:
    Sep 5, 2014
    Messages:
    5
    Likes Received:
    0
    Bump? No one has seen or has any observations on this issue? Moderators? Designers? Team?
     
  3. nealxgs

    nealxgs New Member

    Joined:
    Sep 6, 2014
    Messages:
    2
    Likes Received:
    0
    Hi, I encountered the similar problem before, but it only happened when I use the built-in arduino IDE to program the SAM3X8E.

    The issue can be avoid when I use the arduino IDE on my Ubuntu x64 to program the chip through CN6.
     
  4. ajfisher

    ajfisher New Member

    Joined:
    Sep 5, 2014
    Messages:
    5
    Likes Received:
    0
    I'm actually not using a graphical desktop at all so don't have arduino IDE installed on the Udoo. I'm just trying to the linux side to talk to the SAM3X side but currently without any luck. It's a pity as I wanted to use this for a robot but seems like that will be a no go.
     
  5. fetcher

    fetcher Member

    Joined:
    Mar 9, 2014
    Messages:
    166
    Likes Received:
    20
    Linux serial devices may need to be initialized by appropriate ioctl()'s before you can talk to them with simple tools like 'cat' or 'screen'. Try installing the terminal program "minicom" on your Udoo (apt-get install minicom), and pointing it to /dev/ttymxc3 at 115200 bps, no hardware handshaking, no DCD/carrier-detect.

    Sample /etc/minicom/minirc.dfl --

    pu port /dev/ttymxc3
    pu hasdcd No
    pu rtscts No

    (all can be configured from the Ctrl-A, P and Ctrl-A, O menus also -- this program is modeled after the old "Telix" for DOS).

    'ckermit' is another one you could use.

    When opened with a simple tool like 'cat' right after boot, the serial driver may default to trying to look for a (nonexistent) carrier-detect signal, or CTS, DSR, etc. before allowing any data to pass, but the full terminal apps should correct these settings if so, after which cat, etc. should work fine.

    If this fixes the issue but you want to avoid using terminal apps, read up on the 'stty' command and its multitude of options for configuring ports. I don't often use stty, and have to look up the magic incantations every time. From C, ioctl() and tcsetattr() functions can be called directly on the port... something like the code below (Q&D paste from another project, may need minor edits to work):

    Code:
    #include <stdio.h>
    #include <stdio_ext.h>
    #include <stdlib.h>
    #include <fcntl.h>
    #include <unistd.h>
    #include <string.h>
    #include <sys/termios.h>
    #include <sys/ioctl.h>
    
    #define LMAX 1024
    
    main()  {
      int rs232, mdlns;
      struct termios rs232_attr;
      FILE *serial_stream;
     
     char line[LMAX];
    
     rs232 = open("/dev/ttymxc3", O_RDWR | O_NOCTTY)
    
     rs232_attr.c_oflag = 0;
     rs232_attr.c_lflag = 0;
     rs232_attr.c_iflag = IGNBRK | IGNPAR;
     rs232_attr.c_cflag = B115200 | CS8 | CREAD | CSTOPB| CLOCAL;
     tcsetattr (rs232, TCSANOW, &rs232_attr);
     ioctl (rs232, TIOCMGET, &mdlns);
    
     serial_stream = fdopen(rs232,"r");
    
     setlinebuf(serial_stream);
     setlinebuf(stdout);
    
     while (1) {
      if ((fgets(line,LMAX,serial_stream)) == 0)
         break;
    
         printf("%s",line);
     }
    
     fclose(serial_stream);
    }
    
     

Share This Page