TransWikia.com

Connect sim800 to Raspberry PI (RX, TX)

Raspberry Pi Asked by Max on September 15, 2020

I’ve been trying to connect my sim800L to my Raspberry pi 3 model B (rasbian) but without success…

I’m at the very first step, and since I’m new to Raspberry pi, I don’t understand very well how it works.

Here is how I’m trying to connect it:

montage

After some research, I’ve found that I needed to add some things to the /boot/config.txt file in order to enable the UART, so I’ve added this :

core_freq=250
enable_uart

Edit : my version is My version is 4.4.50-v7+ so I don’t need enable_uart

After, I found out a code that matched what I’m trying to do, here it is:

import serial   
import os, time

# Enable Serial Communication
port = serial.Serial('/dev/ttyS0', baudrate=9600, timeout=1)

# Transmitting AT Commands to the Modem
# 'rn' indicates the Enter key

port.write('AT'+'rn')
rcv = port.read(10)
print rcv

But nothing is working in the Python Shell, no matter if I’m using ttyS0 or Serial0, when I try the AT command, which is supposed to answer OK if the sim800L is successfully connected.
I’m getting some basic error (after typing AT):

>>> AT
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    AT
NameError: name 'AT' is not defined

How can I resolve this error?

4 Answers

Please read manuals. There is no 'AT' + 'rn', use "ATr" instead. No need for New Line 'n', only Carriage Return 'r'. Also, before any other commands, SIM800 is by default working at 115200 baudrate, so "ATr" + "AT+IPR=9600r" or any other baudrate is a MUST been sent to it.

Answered by user122570 on September 15, 2020

Just yesterday I managed to make my assembly respond. Here are my steps:

  1. Disable Serial Console sudo raspi-config --> Interfaces --> Serial --> No to 1st prompt; Yes for the 2nd

  2. Use "serial0" instead of "ttyAMA0" or "ttyS0"

*Edit: Appended working code

    import serial
    import RPi.GPIO as GPIO
    import os, time
    GPIO.setmode(GPIO.BOARD)
    port = serial.Serial("/dev/serial0", baudrate=9600, timeout=1)
    port.flush()
    port.write('AT'+'rn')
    rcv = port.read(10)
    print rcv
    time.sleep(1)

Answered by Manu on September 15, 2020

The circuit as shown will not work as there is no common voltage reference between the SIM and the Pi.

You need to connect a Pi ground to either the SIM ground or to the battery ground (-ve terminal).

Answered by joan on September 15, 2020

that's probably the code you are looking for:

import serial
import RPi.GPIO as GPIO     
import os, time

GPIO.setmode(GPIO.BOARD)   

# Enable Serial Communication
port = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=1)

# Transmitting AT Commands to the Modem
# 'rn' indicates the Enter key

port.write('AT'+'rn')
rcv = port.read(10)
print rcv
time.sleep(1)

port.write('ATE0'+'rn')      # Disable the Echo
rcv = port.read(10)
print rcv
time.sleep(1)

port.write('AT+CMGF=1'+'rn')  # Select Message format as Text mode
rcv = port.read(10)
print rcv
time.sleep(1)

port.write('AT+CNMI=2,1,0,0,0'+'rn')   # New SMS Message Indications
rcv = port.read(10)
print rcv
time.sleep(1)

# Sending a message to a particular Number

port.write('AT+CMGS="XXXXXXXXXX"'+'rn')
rcv = port.read(10)
print rcv
time.sleep(1)

port.write('Hello User'+'rn')  # Message
rcv = port.read(10)
print rcv

port.write("x1A") # Enable to send SMS
for i in range(10):
    rcv = port.read(10)
    print rcv

for more information have a look at this page

Answered by Liam on September 15, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP