简体   繁体   English

Raspberry pi 3 B +中的串行通信

[英]Serial Communication in Raspberry pi 3 B+

I want to communicate between Raspberry pi 3 B+ and GSM GPRS A6. 我想在Raspberry pi 3 B +和GSM GPRS A6之间进行通信。 I tried and I am unable to send data to GPRS Module from Raspberry pi. 我尝试过,但无法从Raspberry pi发送数据到GPRS模块。

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

enable_uart=1

Here's my Code: 这是我的代码:

import serial
import time

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

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

This command is supposed to return "OK", but it does not and nothing is printed. 该命令应该返回“ OK”,但不会返回任何内容。 I am using python 2.7. 我正在使用python 2.7。

Some people suggested me to send data using this method, 有人建议我使用这种方法发送数据,

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

I tried but it didn't help. 我尝试过,但是没有帮助。

There is no problem with my GPRS module. 我的GPRS模块没有问题。 It works file with arduino. 它与arduino一起工作。 So, what am I doing wrong here? 那么,我在这里做错了什么?

Thanks in advance! 提前致谢!

, First , be sure to enable the Serial. 首先,请确保启用串行。

sudo raspi-config -> Interfacing Option -> Serial sudo raspi-config- >接口选项->串行

Second , sudo nano /boot/cmdline.txt 其次, sudo nano /boot/cmdline.txt

Delete "console=serial,115200" 删除“ console = serial,115200”

And Then sudo nano /boot/config.txt 然后sudo nano /boot/config.txt

Add the end 添加结尾

dtoverlay=pi3-disable-bt core_freq=250 dtoverlay = pi3-disable-bt core_freq = 250

While you use : Serial(/dev/ ttyAMA0 ,9600) 使用时:串行(/ dev / ttyAMA0,9600

try sending: 尝试发送:

import serial

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

while True:
   comm.write('AT' + '\n\r')
   msg = comm.readline()
   print(msg)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM