ไม่สามารถเปิดพอร์ด ttyAMA0 บนราสเบอรี่พายได้

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: ไม่สามารถเปิดพอร์ด ttyAMA0 บนราสเบอรี่พายได้

Re: ไม่สามารถเปิดพอร์ด ttyAMA0 บนราสเบอรี่พายได้

โดย puopun.p » 13/07/2016 2:53 pm

แก้ไขได้แล้ว
สาเหตุ
-เนื่องจากเวอร์ชั่น raspberry pi 3 จะมีบูทูธฝังมาให้ ทำให้พอร์ต serial port จะเป็น ttyAMA0 และ GPIO serial จะเป็น ttyS0 ทำให้ไม่สามารถติดต่อกับเซ็นเซอร์ได้(ปกติ GPIO serial จะเป็น ttyAMA0 อยู่แล้ว)
วิธีแก้ไข
-ทำการเปลี่ยน Alias name ใหม่ โดยใช้วิธีจาก ที่นี่
-หรือใช้เป็น ttyS0 ได้เลย

ไม่สามารถเปิดพอร์ด ttyAMA0 บนราสเบอรี่พายได้

โดย puopun.p » 13/07/2016 1:37 pm

โค้ด: เลือกทั้งหมด


import serial
import time

def readlineCR(port):
    rv = ""
    while True:
        ch = port.read()
        rv += ch
        if ch=='\r' or ch=='':
            return rv

port = serial.Serial("/dev/ttyAMA0", baudrate=115200, timeout=3.0)

while True:
    port.write("\r\nSay something:")
    port.write("\r\nYou sent:" + repr(rcv))
พอรันแล้วไม่ขึ้นอะไรเลย

ข้างบน