Jump to content
LS-Support-12

How to test serial ports?

Recommended Posts

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?

 

Share this post


Link to post
Share on other sites

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()

Share this post


Link to post
Share on other sites

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...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×