【问题标题】:Serial Communication in Raspberry pi 3 B+Raspberry pi 3 B+ 中的串行通信
【发布时间】:2017-12-25 12:15:19
【问题描述】:

我想在 Raspberry pi 3 B+ 和 GSM GPRS A6 之间进行通信。我试过了,我无法从树莓派向 GPRS 模块发送数据。

现在,我知道 GPIO 串行端口在较新的操作系统(在我的情况下为 Raspbian Stretch)中默认禁用,因此我通过在 config.txt 文件中添加以下行来启用它,

enable_uart=1

这是我的代码:

import serial
import time

port = "/dev/ttyS0"
COMM = serial.Serial(port, baudrate=115200)

while(1):
    COMM.write("AT\r")
    print (COMM.read(5))

这个命令应该返回“OK”,但它没有,并且没有打印任何内容。我正在使用 python 2.7。

有人建议我用这种方法发送数据,

COMM.write('AT' + '\r')

我试过了,但没有用。

我的 GPRS 模块没有问题。它适用于 arduino 文件。 那么,我在这里做错了什么?

提前致谢!

【问题讨论】:

  • 也许pi 用户没有写权限,试试sudo python yourScript.py。如果可行,请将pi 用户添加到dialoutsudo usermod -a -G dialout pi
  • 不,那没用。

标签: python-2.7 raspberry-pi gsm serial-communication gprs


【解决方案1】:

, 首先,请务必启用 Serial。

sudo raspi-config -> 接口选项 -> 串行

第二,sudo nano /boot/cmdline.txt

删除“console=serial,115200”

然后 sudo nano /boot/config.txt

添加结尾

dtoverlay=pi3-disable-bt core_freq=250

当你使用时:Serial(/dev/ttyAMA0,9600)

【讨论】:

    【解决方案2】:

    尝试发送:

    import serial
    
    port = "/dev/ttyS0"
    comm = serial.Serial(port, baudrate=115200)
    
    while True:
       comm.write('AT' + '\n\r')
       msg = comm.readline()
       print(msg)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-16
      • 1970-01-01
      • 2019-05-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多