5

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
# '\r\n' indicates the Enter key

port.write('AT'+'\r\n')
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?

Max
  • 51
  • 1
  • 1
  • 5

4 Answers4

4

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

joan
  • 71,024
  • 5
  • 73
  • 106
  • 2
    Yes you are right, thanks, I forgotten to draw a Pi ground to the battery ground. do you have other answers to help me resolve this ? :) – Max Apr 02 '17 at 17:44
  • why do we need to common the ground when we have a independent power source for both? – Milan Maharjan Jan 25 '20 at 17:47
  • 1
    @MilanMaharjan You only need a common ground when you are trying to communicate with the other device via the GPIO. Without a common ground neither side would know the voltage level of the other's signals, i.e. they wouldn't be able to tell a digital high from a digital low (and vice versa). – joan Jan 25 '20 at 18:17
  • @joan thank you so much, this solved my issue :) – Milan Maharjan Jan 28 '20 at 14:31
4

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'+'\r\n')
    rcv = port.read(10)
    print rcv
    time.sleep(1)
Manu
  • 41
  • 3
1

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
# '\r\n' indicates the Enter key

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

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

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

port.write('AT+CNMI=2,1,0,0,0'+'\r\n')   # 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"'+'\r\n')
rcv = port.read(10)
print rcv
time.sleep(1)

port.write('Hello User'+'\r\n')  # 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

Liam
  • 661
  • 2
  • 9
  • 20
  • Thanks it will be helpful, but it seems that the guy is one step further than me.. I'm still trying to "ping" the sim800. – Max Apr 02 '17 at 13:25
0

Please read manuals. There is no 'AT' + '\r\n', use "AT\r" 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 "AT\r" + "AT+IPR=9600\r" or any other baudrate is a MUST been sent to it.