Please select To the mobile version | Continue to access the desktop computer version

OrangePi

 Login            
 Register            
Search
Hot search: orangepi
View: 4752|Reply: 8

[solved] cannot use serial port

[Copy link]

6

Threads

22

Posts

109

Credits

Registered member

Rank: 2

Credits
109
Post time 2017-2-22 19:02:56 | Show all posts |Read mode
Edited by wwwlu at 2017-2-24 17:51

I can't read the serial port of my OPI pc plus with Armbian
My python script (which works fine on lubuntu)
  1. #!/usr/bin/env python
  2. # -*- coding: latin-1 -*-

  3. import serial
  4. import os

  5. ser = serial.Serial('/dev/ttyS0', 9600)

  6. while True :
  7.         data = ser.readline()
  8.         print (data)
  9.         if "stop" in data:
  10.                 os.system('sudo shutdown -h now')
Copy the Code
returns :
  1. Traceback (most recent call last):
  2.   File "off.py", line 10, in <module>
  3.     data = ser.readline()
  4.   File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 453, in read
  5.     buf = os.read(self.fd, size-len(read))
  6. OSError: [Errno 11] Resource temporarily unavailable
Copy the Code

I tried :
  1. sudo minicom -D /dev/ttyS0
Copy the Code
result:
  1. Device /dev/ttyS0 is locked.
Copy the Code

and with:
  1. dmesg | grep tty
Copy the Code
i get :
  1. [    0.000000] Kernel command line: console=tty1 root=/dev/mmcblk0p1 rootwait rootfstype=ext4 cgroup_enable=memory swapaccount=1 panic=10 consoleblank=0 enforcing=0 loglevel=7
  2. [    0.000000] console [tty1] enabled
  3. [    0.460131] uart0: ttyS0 at MMIO 0x1c28000 (irq = 32) is a SUNXI
  4. [    6.252629] systemd[1]: Expecting device dev-ttyS0.device...
  5. [    6.488254] systemd[1]: Starting system-getty.slice.
  6. [    6.497739] systemd[1]: Created slice system-getty.slice.
  7. [    6.502287] systemd[1]: Starting system-serial\x2dgetty.slice.
  8. [    6.511686] systemd[1]: Created slice system-serial\x2dgetty.slice.
Copy the Code

What can I do ?
Thanks!

3

Threads

79

Posts

1038

Credits

Gold member

Rank: 6Rank: 6

Credits
1038
Post time 2017-2-22 23:01:38 | Show all posts
Hi,

I assume that you have tried to execute the python script with "sudo".

Did you try with other read function, like the character read:
ser.read() instead of ser.readline()?

I think ttyS0 correspond to uart0 which is the serial debug port of the orange pi, may It cause the blocked status, not sure...

You can try with other uart, like the uart1 (physichal 38 and 40 gpio pins), device "/dev/ttyS1". It should be necessary to enable It with the script.bin file (in Legacy Kernel):
  1. 1 - Backup file:
  2. sudo cp /boot/script.bin /boot/script.bak

  3. 2 - Convert binary to text (fex) file:
  4. sudo bin2fex /boot/script.bin /boot/script.fex

  5. 3 - Open the file:
  6. sudo nano /boot/script.fex

  7. 4 - Search for the [uart1], and enable It:
  8. uart_used = 1

  9. 5 - Save and close the file:
  10. Ctrl X, Y (Yes), Enter

  11. 6 - Convert the edited fex to binary file:
  12. sudo fex2bin /boot/script.fex /boot/script.bin

  13. 7 - Reboot the system:
  14. sudo reboot
Copy the Code


6

Threads

22

Posts

109

Credits

Registered member

Rank: 2

Credits
109
 Author| Post time 2017-2-22 23:15:53 | Show all posts
I changed the serial config using minicom and now I get :
  1. Traceback (most recent call last):
  2.   File "off.py", line 11, in <module>
  3.     data = ser.readline()
  4.   File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 495, in read
  5.     raise SerialException('device reports readiness to read but returned no data (device disconnected or multiple access on port?)')
  6. serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected or multiple access on port?)
Copy the Code

ps -ef | grep tty:
  1. root       787   780  0 13:44 tty7     00:00:50 /usr/lib/xorg/Xorg :0 -nolisten tcp vt7
  2. root      1260     1  0 13:44 tty1     00:00:00 /sbin/agetty --noclear tty1 linux
  3. root      5347     1  0 15:09 ttyS0    00:00:00 /bin/login --
  4. lu        5360  1572  0 15:09 pts/0    00:00:00 grep --color=auto tty
Copy the Code


Does this mean ttyS0 is already used by root ? what should I do ?
Thanks

6

Threads

22

Posts

109

Credits

Registered member

Rank: 2

Credits
109
 Author| Post time 2017-2-22 23:40:42 | Show all posts
Thanks JRios,

Yes I used Sudo to execute the python script.
ser.read() does not change anything
I modified script.bin but I cannot boot anymore:
stucked on "Hit any key to stop autoboot: 0"
(does not change if I hit a key)
I will burn the image again

9

Threads

630

Posts

4246

Credits

Moderator

Rank: 7Rank: 7Rank: 7

Credits
4246
Post time 2017-2-23 00:28:47 | Show all posts
You can't use ttyS0 since it's in use / enabled by default for serial console. On all our builds.

Use ttyS1 or other.

6

Threads

22

Posts

109

Credits

Registered member

Rank: 2

Credits
109
 Author| Post time 2017-2-23 17:50:41 | Show all posts
It works fine with ttyS1 !!!  

Thanks a lot Igor and JRios for your great help!

3

Threads

79

Posts

1038

Credits

Gold member

Rank: 6Rank: 6

Credits
1038
Post time 2017-2-23 18:35:00 | Show all posts
Glad to hear it!

You're welcome.

2

Threads

12

Posts

71

Credits

Registered member

Rank: 2

Credits
71
Post time 2018-3-24 00:02:02 | Show all posts
I modified script.bin but I cannot boot anymore:
stucked on "Hit any key to stop autoboot: 0"


Do you mean you did that modification or ttyS1 was available from scratch ?

2

Threads

12

Posts

71

Credits

Registered member

Rank: 2

Credits
71
Post time 2018-4-3 04:58:35 | Show all posts
I had to enable ttyS1 with armbian-config first :
then it worked!


This post contains more resources

You have to Login for download or view attachment(s). No Account? Register

x
You have to log in before you can reply Login | Register

Points Rules

Archiver|Mobile edition|Darkroom|OrangePi En ( 粤ICP备14086627号-2

2020-2-21 17:26 GMT+8 , Processed in 0.036482 second(s), 23 queries .

Powered by Discuz! X3.2

© 2014-2015 orangepibbs en.

Quick Reply To Top Return to the list