1 2 3 Previous Next 30 Replies Latest reply on May 6, 2016 7:55 AM by mhahn

    Using Serialx on Edison


      [Note: This post has been edited to reflect updates in recent software drops.]

      This is a description of the various types of serial ports the Edison provides in conjunction with the breakout boards.



      Name: “Multi-gadget” or “Firmware Programming” or "Serial console" or "OTG" port.
      Location: USB-micro connector near center of Arduino board.

      Arduino SW name: Serial

      Linux name: /dev/ttyGS0


      This is the port you use to program your Edison/Arduino, and also the default port for the Serial console inside the Arduino IDE.  If the correct drivers are installed, this port also provides access to a USB storage partition and an RNDIS network interface (hence the name “multi-gadget”). When using the Arduino adapter board, this port is only active when SW1 is set to “device” mode, that is, the position closest to the multi-gadget port connector.


      Name: UART1, the general-purpose TTL-level port (Arduino shield compatibility).
      Location: Pins 0 (RX) and 1 (TX) on the Arduino shield interface headers.
      Arduino SW name: Serial1
      Linux name: /dev/ttyMFD1


      This is the port that is exposed to an Arduino shield on pins 0 and 1, creating a simple 5V TTL interface to an external device.


      Name: UART2, “Linux kernel debug” or “debug spew” port.
      Location: USB-micro connector near edge of Arduino board.
      Arduino SW name: Serial2
      Linux name: /dev/ttyMFD2


      This is a very useful port to connect to for debugging, especially when trying to isolate boot problems.  The kernel generates its debug “spew” to this port at 115,200 baud.  I find it useful to always have a PuTTY terminal console connected to this.  When the Serial2 object is initialized with Serial2.begin(), the kernel's access to the port is removed, and the sketch is given control until it calls Serial2.end().


      Virtual ports

      Name: VCP or “Virtual communications port”.  (Appears only when Serial-over-USB device connected.)
      Location: Big type “A” USB port nearest the Arduino power connector.
      Arduino SW name: not supported by default but see below*
      Linux name: /dev/ttyACMx or /dev/ttyUSBx or ?


      On the Arduino adapter this port appears only when a suitable device is plugged into the “A” USB port and the appropriate drivers are loaded and SW1 is set to “host” mode, that is, the position closest that port.  If you have a USB hub attached here, you can plug in multiple serial-over-usb devices to get multiple ports.


      *Serial, Serial1, and Serial2 are supported in the official Edison/Arduino software release [as of October 2014], but it is quite easy to make use of the excellent TTYUARTClass to get similar support for virtual ports as well.  For example, to access both the Linux debug port and the virtual serial GPS device, we simply add code like this:


      RingBuffer rx_buffer_GPS;

      TTYUARTClass SerialGPS(&rx_buffer_GPS, 3, false); // USB GPS device


      SerialGPS.init_tty("/dev/ttyACM0"); // bind to GPS device

      SerialGPS.begin(9600); // our GPS operates at 9600 baud.


      Now SerialGPS acts just the same as Serial, Serial1, and Serial2.


      Hope this helps!



        • 1. Re: Using Serialx on Edison

          Is there any linux libraries similar to TTYUARTClass to get similar support of the rest of UART interfaces without Arduino sketches?

          • 2. Re: Using Serialx on Edison



            I would also like to know how to read serial input under linux.

            • 3. Re: Using Serialx on Edison

              I have not tried it yet, but with the Intel release of 1.0.4 they added the Serial2 object which maps to the ttyMFD2 object.  I believe it removes the kernel debugger from this port while the Serial2 object is used.


              As for doing stuff like Serial1.print(...), or Serial1.read()... I don't know if there are any official libraries to do this, but I have my own that are part of my Raspberry_Pi project (KurtE/Raspberry_Pi · GitHub)

              This is a bad name for the project as I started off on a RPI, but have adapted it to Beaglebone Black and Odroid U2/U3 and now to Edison.  Note: I should have made a new branch for the Edison, and may still and see what it takes to move the Edison specific commits to that branch...


              Also this project is a collection of all of the different things that I have played with on linux.  Things like porting the Hexapod/Quad Phoenix code base to linux.  There is also a couple different versions of it where I  have done work to convert to floating point... Also code for Trossen Phantom Arm, A Rover, ...


              But there are a few Interesting sub-folders,

                  library: the main code base for porting my Arduino code, includes ports, of Stream, Serial, ... Also has a simple Serial wrapper class, which I use for example to create a wrapper around stdout, stdin.

                  BoiloidEx and BioloidEx_Usb2Ax: support for Bioloid AX-12 and other other servos using Xevelabs USB2AX adapter - one uses my own firmware extensions

                  Adafruit_ILI9341C - My port of the Adafruit ILI9341 driver (example their 2.8" tft display) including some speed ups.  This is Edison specific using MRAA

                 (several different test programs) like testAdafruit-ilI9341C - port of graphictest, a read pixel test...  Specific to Edison shows using WrapperSerial to get output to debug window...


              Side note in library folder, is my support for using the Arbotix Commander, which is a remote control sold by Trossen Robotics which uses XBees.  The files (commanderEx.h and CommanderEx.cpp) is my code base to talk to the XBee.   This code is structured a lot like the default Serial1 code base under Arduino.  It creates a thread that waits for input and it configures the underlying terminal control to work again similar to what the Arduino code base does for Serialx objects.  The main difference is that this code base simply reads the data from the XBee, which have very specific format, and as it gets a valid packet it keeps it.  It only keeps the last valid packet.  The create the more generic SerialX object, the code would instead create a set of pipes (pipe2), that when the secondary thread received a byte it would place it into one pipe, and the the Print code on the other side would write date into the other pipe, which the 2nd thread would need to add to it's wakeup code and then output to underlying terminal hardware.  Note:  some of my recent updates to this included a call out to MRAA to initialize the IO pins associated with the logical Serial1 object.  I still need to add code to somehow check to see if I am using the logical Serial1 object or not as to only call MRAA when necessary.  (My code uses a logical device /dev/ttyXBEE, which could be to that device or could be to a USB to serial device),  This code also requires the most recent version of MRAA to work.  Not sure if you need to build yourself or if the updates have propagated.

              • 4. Re: Using Serialx on Edison

                Excellent post KurtE ! Thanks a lot !


                I will download your library right away and try to use it under Linux (the serial part of it) on my Edison.


                I will post here if I have any doubts or run into trouble



                • 5. Re: Using Serialx on Edison

                  Yes, thanks KurtE!  I was just about to create a lengthy post asking if it is possible to disable the kernel's attachment to UART2.  I'll go try it.  Thanks!

                  • 6. Re: Using Serialx on Edison

                    Hi again KurtE! - managed to use your Serial Wrapper without problems under Edison! Great! Thanks!


                    One question: how is your workflow to develop on the Edison (without Intel's IDE) ?


                    Do you develop right on the Edison (using ssh or the USB cable) or do you do it remotely ?


                    I am currently doing right on the Edison using the USB cable but I would like to be able to use another text editor apart from vi


                    Thanks for any insights,

                    • 7. Re: Using Serialx on Edison

                      You could e.g. sshfs mount Edison from a Linux host. Then you can use whatever editor you like on the target files.

                      • 8. Re: Using Serialx on Edison

                        You are welcome,  they come in handy for me.  Makes it easier for me to port over Arduino code.  May also hack up a version of pinMode and digitalWrite that goes through mraa...


                        As for workflow on windows I use WinSCP to transfer files back and forth and PuTTY for terminal windows. (I believe I have download links in that projects readme.md file).  On Linux I fumble along when I need to.  For real quick changes I somtimes use vi in a putty window.  With WinSCP you can configure which editor you wish to use.  Most of the time I have used Programmers Notepad, but other times I use Geany as there are versions of Geany on many of linux platforms as well (but I still prefer PN)

                        • 9. Re: Using Serialx on Edison

                          Thanks mhahn - I will try that!

                          • 10. Re: Using Serialx on Edison

                            Thanks KurtE ; I was looking at a more straightforward way to do that;


                            For instance, instead of copying over files at every modification (and then moving to the terminal tab of the Edison to compile) just edit the files directly over a mounted folder.


                            I will try mhahn suggestion and see if that works.


                            Thanks again guys,

                            • 11. Re: Using Serialx on Edison

                              Straight foreword would be nice.


                              I don't mind my process right now.  I simply open winscp, browse to the directory with the stuff I am working on.  I then double click on a file, which winscp copies over to my dev machine (temp directory) and opens up an editor.  When you modify the file, winscp notices that and then downloads it back to the edison (or RPI or ...), where I then click on my putty window and do a make or the like.


                              When I have stuff working like I want it, or wish to back stuff up, I simply have the remote and local sides of WinSCP pointing to same directories and can copy back and forth.  Often I will use the checkbox that says only copy updated files. 


                              Again maybe not perfect, but gets the job done.

                              • 12. Re: Using Serialx on Edison

                                I guess I misunderstood your worflow - this seems straightforward to me


                                I thought you had to do a command line scp * every time;


                                thanks again!

                                • 13. Re: Using Serialx on Edison

                                  Nope. Directly mounting in the file system and working on remote files. sshfs is quite convenient for that. Btw: Using ipv6 address for the usb ethics dongle I do have the same address whatever network I'm in.

                                  • 14. Re: Using Serialx on Edison

                                    @mikalhart.  We are trying to do exactly what you say but with the Mini Breakout board using an OTG cable.  I have tested the board and with the OTG cable it should be identical to the A-USB you are using.  We want to connect a GPS to this A-USB port.  The fellow doing the programming reports this:


                                    When I try to open this port programmatically by

                                    tty_fd = open("/dev/ttyACM0", O_RDWR | O_NONBLOCK);


                                    that I have the return error code of -1.

                                    Do you have it working?  Can you share how to get past our error message?

                                    1 2 3 Previous Next