简体   繁体   中英

Serial Communication in Raspberry pi 3 B+

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.

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

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. 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.

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

Thanks in advance!

, First , be sure to enable the Serial.

sudo raspi-config -> Interfacing Option -> Serial

Second , sudo nano /boot/cmdline.txt

Delete "console=serial,115200"

And Then sudo nano /boot/config.txt

Add the end

dtoverlay=pi3-disable-bt core_freq=250

While you use : Serial(/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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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