0 Replies Latest reply on Dec 31, 2014 2:43 AM by haxor

    How to get the UART1 working for Linux beginners

    haxor

      Hi,

       

      I have seen a couple of questions about how to get the dedicated UART1 working on Intel Edison on the Internet. The "mraa", as far as I know, does not support the UART write and send commands now so I decided to write a very simple demonstration tutorial for Linux beginners.

       

      1) Hardware setup

      On the breakout board, the UART1_TX is located at J19, pin 8 and the UART1_RX at J18, pin 13. Connect the scope probe, logic analyser or 1.8 V UART to RS232/USB bridge here.

       

      2) Initialization of the UART interface

      Type these commands to the console:

      stty -F /dev/ttyMFD1 9600

      The 9600 is the baudrate, you can change it to whathever you want.

      A complete documentation of stty commands can be found here: UNIX man pages : stty ()

      The UART1_TX pin on the Edison will go high (1.8 V) as you perform the initialization.


      3) Writing to the UART from console

      Type this to the console:

      echo "text" > /dev/ttyMFD1

      Now you should see a waveform on the scope/logic analyser or "text +CR +LF" in your UART console

      Take a look at the echo command here (how to write special characters etc.): UNIX man pages : echo ()

       

      4a) Reading from the UART to the console

      Type this to the console:

      cat /dev/ttyMFD1

      Now if you send the data through the UART1_RX pin terminated by CR+LF, you will see it in your Edison's console. Please be aware that when using breakout board, the Edison GPIOs are 1.8 V logic! If you use 3.3V or 5V adapters, you will probably damage your Edison when you connect it directly to the Edison. In that case, use a voltage translator. Do not tell this to your high school or university electronics teacher :-), but if you do not want to wait for the 1.8 V hardware to arrive, put a 100k resistor in between your 3V3 or 5V translator and RX pin of Edison. This will limit the current so the protection diodes will limit the voltage about 1V8 and they won't be damaged by the current. I have tested it, it works, but again, I do not encourage you to do it that way. Please also be aware that you will still probably need a voltage translator for the Edison TX pin to translate it to 3V3 or 5V logic to get correct readings from your adapter's RX pin.


      4b) Reading from the UART to the file

      Similar to 4a)

      cat /dev/ttyMFD1 1>uart_rx 2>&1 &

      The process is running in the background so new data will add dynamically as they arrive to the UART1_RX pin. This can be useful for manual logging of data for example from a GPS module.


      4c) Accessing the data from Python script

      Use the subprocess library to do this task, please search the Google, there is a plenty of examples. It is similar to 4b), you will run the cat process "in background" and you can access the data directly from your Python script.



      Hope some of you will find this a bit useful.

      Lot of success with Edison,

      Marek.