Jump to content
Ali.Challenger

UART PYTHON issue

Recommended Posts

Good afternoon,

 

        I tried to work with UART (GPIO0,GPIO1), and build a simple code via python as shown bellow:

import serial ## Load the serial library

## Select and configure the port
myPort = serial.Serial('/dev/ttyS1', 115200)


while (1):
    myPort.write('a')
    x= myPort.read()
    print "recieved from adk" + x
    myPort.write(x)
    

## Close the port so other applications can use it.
myPort.close()

        But, unfortunately I got nothing. Suddenly when I uploaded an arduino serial sketch and after that the python code works fine!!    

        And then when I reboot the pcDuino, the python code doesn't work again until I upload the serial arduino sketch.

 

 

 

 

Am not sure what is the wrong in the code?, your help please 

 

best regards.

Share this post


Link to post
Share on other sites

Does it give you an error message?

 

Did you install python-serial?

"sudo apt-get install python-serial

 

Enable GPIO-0 or GPIO-1 for input/output?

echo 3 > /sys/devices/virtual/misc/gpio/mode/gpio0

echo 3 > /sys/devices/virtual/misc/gpio/mode/gpio1

 

Looks like you copied code from the old Sparkfun pcDuino 1 tutorial site.

Share this post


Link to post
Share on other sites

Does it give you an error message?

 

Did you install python-serial?

"sudo apt-get install python-serial

 

Enable GPIO-0 or GPIO-1 for input/output?

echo 3 > /sys/devices/virtual/misc/gpio/mode/gpio0

echo 3 > /sys/devices/virtual/misc/gpio/mode/gpio1

 

Looks like you copied code from the old Sparkfun pcDuino 1 tutorial site.

No it doesn't give any errors,

and yes of course I already installed the python-serial  

 

 

The problem is when I try to run this python code it runs without any errors but doesn't work correctly,  then I close it and upload a any serial arduino example and then close the arduino IDE and run this python code again it works correct and fine???

Share this post


Link to post
Share on other sites

Did you enable the pins for uart as I suggested above?

Yes thank you pretty much for your help, that was my mistake, I didnt enable the pins as uart,   

 

Actually I used the following way to enable them is it ok! and are there a better way to do that?

os.system("echo 3 > /sys/devices/virtual/misc/gpio/mode/gpio0")
os.system("echo 3 > /sys/devices/virtual/misc/gpio/mode/gpio1")

thank you

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

×