Jump to content


Photo

UART PYTHON issue

UART python rxtx

  • Please log in to reply
5 replies to this topic

#1 Ali.Challenger

Ali.Challenger

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts

Posted 14 June 2015 - 09:34 AM

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.


Ali.Challenger


#2 cwilt

cwilt

    Advanced Member

  • Members
  • PipPipPip
  • 1,012 posts

Posted 14 June 2015 - 01:22 PM

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.


  • Ali.Challenger likes this

#3 Ali.Challenger

Ali.Challenger

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts

Posted 14 June 2015 - 03:25 PM

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


Ali.Challenger


#4 cwilt

cwilt

    Advanced Member

  • Members
  • PipPipPip
  • 1,012 posts

Posted 14 June 2015 - 05:12 PM

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



#5 Ali.Challenger

Ali.Challenger

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts

Posted 15 June 2015 - 04:55 PM

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


Ali.Challenger


#6 cwilt

cwilt

    Advanced Member

  • Members
  • PipPipPip
  • 1,012 posts

Posted 15 June 2015 - 05:25 PM

Nothing wrong with the way you did it.





Also tagged with one or more of these keywords: UART, python, rxtx

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users