Raspberry pi 3 B +中的串行通信 [英] Serial Communication in Raspberry pi 3 B+

查看:171
本文介绍了Raspberry pi 3 B +中的串行通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Raspberry pi 3 B +和GSM GPRS A6之间进行通信.我尝试过,但无法从Raspberry pi向GPRS模块发送数据.

I want to communicate between Raspberry pi 3 B+ and GSM GPRS A6. I tried and I am unable to send data to GPRS Module from Raspberry pi.

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

Now, I know that GPIO serial port is disabled by default in newer Operating Systems (in my case Raspbian Stretch), so I have enabled it by adding following line in config.txt file,

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.

This command is supposed to return "OK", but it does not and nothing is printed. I am using python 2.7.

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

Some people suggested me to send data using this method,

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

我尝试过,但是没有帮助.

I tried but it didn't help.

我的GPRS模块没有问题.它与arduino一起工作. 那么,我在这里做错了什么?

There is no problem with my GPRS module. It works file with arduino. So, what am I doing wrong here?

提前谢谢!

推荐答案

, 首先,请确保启用序列号.

, First , be sure to enable the Serial.

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

sudo raspi-config -> Interfacing Option -> Serial

第二, sudo nano/boot/cmdline.txt

删除"console = serial,115200"

Delete "console=serial,115200"

然后 sudo nano/boot/config.txt

添加结尾

dtoverlay = pi3-disable-bt core_freq = 250

dtoverlay=pi3-disable-bt core_freq=250

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

While you use : Serial(/dev/ttyAMA0,9600)

这篇关于Raspberry pi 3 B +中的串行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆