问题
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!
回答1:
, 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)
回答2:
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)
来源:https://stackoverflow.com/questions/47968518/serial-communication-in-raspberry-pi-3-b