Jump to content


Photo

How to test serial ports?

serial gpio tx rx port test linux lubuntu 14

  • Please log in to reply
3 replies to this topic

#1 LS-Support-12

LS-Support-12

    Forum Support

  • Moderators
  • 326 posts

Posted 27 September 2015 - 11:40 AM

I am trying to understand how serial communication works on pcDuino. I am following this tutorial. As I understood it, pcDuino has two accessible serial ports by default. These are 0(rx) and 1(tx). We can access them via /dev/ttyS0 and /dev/ttyS1, respectively.

 

This code is written in the tutorial:

import serial
myPort = serial.Serial('/dev/ttyS1', 115200, timeout = 10)
myPort.write("Hello, world!")
x = myPort.read()
print "You entered " + x
myPort.close()

So, the python script above should read the input from serial port 1 and then output it to the screen.

 

Now, my question is how can I test it? What input I can give to these ports? Can I use other pcDuino and send some signal to these ports via gpio port from other pcDuino? Is that safe or these two ports are intended to be used somehow else?

 



#2 cwilt

cwilt

    Advanced Member

  • Members
  • PipPipPip
  • 1,012 posts

Posted 27 September 2015 - 04:17 PM

That code sends "Hello, World!" out ttyS1 and then reads a return character. 

 

You can test both ports on the pcduino at the same time. If you were to connect the TX or S0 to the RX of S1 and vice versa.

In one terminal screen execute:

import serial
myPort = serial.Serial('/dev/ttyS0', 115200, timeout = 10)
myPort.write("Hello")
myport.close()

In another terminal window execute:

import serial
myPort = serial.Serial('/dev/ttyS0', 115200, timeout = 10)
data = myPort.read()
print data
myPort.close()


#3 cwilt

cwilt

    Advanced Member

  • Members
  • PipPipPip
  • 1,012 posts

Posted 27 September 2015 - 06:35 PM

You do know that ttyS0 is debug port?

 

It can be used but you have to do a few things.



#4 LS-Support-12

LS-Support-12

    Forum Support

  • Moderators
  • 326 posts

Posted 04 October 2015 - 12:04 PM

You do know that ttyS0 is debug port?

It can be used but you have to do a few things.

Yes, I do know that it is debug port. However, I am not sure what things (that should be done) you're talking about.

 

I connected S0 (RX) with S1 (TX) via jumper wire. I have tested the code you posted by placing it into a .py script and then running both of them from different terminals. I have even changed the ports (instead of S0, I tried S1, as well as both of them at the same time).

 

However, I got no output. Probably I am missing something...







Also tagged with one or more of these keywords: serial, gpio, tx, rx, port, test, linux, lubuntu, 14

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users