Community
cancel
Showing results for 
Search instead for 
Did you mean: 
GGary2
Beginner
1,874 Views

Serial port only sees some of the characters typed into Edison serial port

Hello. I am trying to have a general program for reading and writing to the Edison serial port.

I'm using the program from the Intel mraa documentation on how to use the mraa uart (see below)

I have a terminal emulator (Teraterm) connected to COM5, the virtual port from the Edison.

The program supposed to write a string ("hello there") to the Teraterm console, then echo on the originating window everything typed in on the Teraterm console.

When I run it, the writing works fine - "hello there" appears on the Teraterm window.

But when I type in characters from the Teraterm console, the program recognizes only about one in 10. Most times my typed characters are ignored.

What's going on? Why doesn't it read every character typed in?

Thanks

======================================

import mraa

u = mraa.Uart("/dev/ttyGS0")

print u.getDevicePath()

# Initialize UART

x=mraa.Uart(0)

# Set UART parameters

u.setBaudRate(9600)

u.setMode(8, mraa.UART_PARITY_NONE, 1)

u.setFlowcontrol(False, False)

u.SetNonBlocking(True)

u.writeStr("hello there\n")

# Start a neverending loop waiting for data to arrive.

# Press CtrlC to get out of it.

while True:

if u.dataAvailable():

# We are doing 1-byte reads here

data_byte = u.readStr(1)

print(data_byte)

# Just a two-way half-duplex communication example, "X" is a flag

if data_byte == "X":

u.writeStr("Yes, master!\n")

0 Kudos
11 Replies
idata
Community Manager
140 Views

Hello garymq,

 

 

I'll try to help you with this. Could you please let us know the exact messages you are sending to the Edison? What I'd like to check is the format in which the data is being sent. This is because in the past I have noticed that Edison has issues detecting data if the carriage return and the new line signals are not sent to it.

 

 

I will be waiting for your response.

 

-Peter.
GGary2
Beginner
140 Views

hello Peter

Thanks for your response.

I am not sending any particular message, I am simply typing characters onto the keyboard of the TeraTerm terminal.

As you can see from the program running on the Edison (see original post), the program should simply echo whatever characters I type in.

But it only catches about 1 in 10 characters.

Note that the writing part of the program works. "Hello there" appears correctly on the Teraterm window. This means that all the basic things like, COM port selection, COM name, baud rate, etc are correct.

Note also that this program is taken directly from the Intel documentation at github.com/intel-iot-devkit/mraa/commit/f9a31956ab070fb2b7440841ab05c9cdff194a5f.

There is nothing fancy here, it should just echo every character I type in, but it doesn't.

Hope someone can make some suggestions as to why this simple program doesn't work.

Gary

IIstv
New Contributor I
140 Views

Something may be picking your characters. /dev/ttyGS0 is the OTG or "multigaget" port. Why don't you test your program with uart(0)? It is

Pins 0 (RX) and 1 (TX) on the Arduino shield interface headers

J18/13(RX) and J19/8(TX) on the mini breakout board.

Istvan

GGary2
Beginner
140 Views

Hello Istvan

The reason I am using /dev/ttyGS0 is because that's the port that the Edison connects to the "Edison Virtual Com Port" which, thru the USB, links to COM5 on my computer.

I guess I could use uart(0) but if this is on the Arduino Shield interface then I would have to use level translators to connect to my standard computer RS232 port.

But I would really like to work with the Edison Virtual Com Port, as the Intel documentation imply I should be able to with their example... because I want to use the Virtual Port for other applications.

Gary

IIstv
New Contributor I
140 Views

I have never used ttyGS0 for serial communication, but I had a look at it now. It seems it is held by a process:

/opt/edison/clloader --escape --binary --zmodem --di

AFAIK it is the service responsible to download Arduino sketches. Another thing I have never touched in my life.

I think the service could be eliminated.

Istvan

P.s. the github script uses uart(0).

idata
Community Manager
140 Views

You could use a standard FTDI cable to connect to your PC, that way you wouldn't need a level translator. You would simply need to connect the Rx and Tx pins of your board to the Rx and Tx pins of the FTDI cable.

 

 

If you use this configuration you could also connect your PC's COM ports and use Teraterm. However, if this isn't an option, I'd suggest you to send the carriage return and new line signal along with each message send to Edison. Also, you might be interested in reporting an issue on mraa ( https://github.com/intel-iot-devkit/mraa/issues) about this behavior, they might be able to help you as this behavior might be related to the library.

 

 

We'll be waiting for your reply.

 

-Peter.
IIstv
New Contributor I
140 Views

Hi Gary,

I did some tests, and I am quite convinced, the problem is not in the script. (By the way, the github script uses uart(0)).

It seems, you use Arduino studio, which I have never used with Edison, so I chose another method to reproduce the error.

I connected the host computer to the OTG connector of the Edison. On the host I started a serial terminal (I usually use minicom) on /dev/ttyACM0, which should be the virtual com port on my Ubuntu desktop.

Logged on the edison via the operator console, and copied a random text file to /dev/ttyGS0

cp /etc/wpa_supplicant/wpa_supplicant.conf /dev/ttyGS0

It all appeared in the host terminal window verbatime.

Reverse direction: on the Edison:

cat /dev/ttyGS0

I started typing in the terminal on the host. Found exactly what your script performed: only a fraction of the characters is shown on the Edison.

I checked if another process holds /dev/ttyGS0 and found:

/opt/edison/clloader --escape --binary --zmodem --di

which afaik is the service to download Arduino sketches. Not sure what it means, but I think this is what steals part of the characters. At the moment I have no idea how to use the virtual terminal from a python scrípt.

GGary2
Beginner
140 Views

Hello Istvan.

I noted your comment that the process

/opt/edison/clloader --escape --binary --zmodem --di

was running and stealing characters from /dev/ttyGS0

When you suggested terminating this process, how do I do that? I can't find the above process using 'top'...

Normally I find a process in 'top', then kill the process number, but since I can't find the process running, how do I terminate it?

BTW - I am interested to know how you found that this process was using /dev/ttyGS0..?

PS - I am not using Arduino Studio. I just wrote the Python script in an editor and ran it from the command line using python.

Thanks

 

Gary
GGary2
Beginner
140 Views

Hello

Good news! - I can now get the /dev/ttyGS0 Virtual terminal port working!

First of all, sorry about my comments about "top" in the last post,,.. I should have been using "ps" not "top"

Using "ps" I can find the process which Istvan suggested was taking characters from /dev/ttyGS0:

root@EdiArdu1:~# ps | grep clloader

1556 root 1920 S /opt/edison/clloader --escape --binary --zmodem --disable-timeouts

2100 root 2656 S grep clloader

When I tried to simply kill the above clloader process (1556), it immediately starts up again with a different process number.

So after a bit of searching I could kill the clloader permanently by using

systemctl stop clloader

As Istvan suggested, clloader is used to download Arduino scripts, and it looks at /dev/ttyGS0, taking characters. So when one tries to read from /dev/ttyGS0 using a python program, most of the characters have already been taken.

By permanently stopping ccloader, I can run the original python program (see initial post).. all the characters are read, as expected!

Gary

IIstv
New Contributor I
140 Views

Hi Gary,

Good to hear it works now

BTW I have used fuser as you probably found out by now. Sorry for being vague.

Istvan

GGary2
Beginner
140 Views

hi Istvan

Thanks very much for your help.

I'm just starting on the Edison. Good to get a nice clear solution to this problem.

Also thanks for the tip on fuser, that's a simple way to find what's using the tty ports.

Gary

Reply