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?

  • can you upload the error please? – Liam Apr 2 '17 at 13:02
  • ok liam, i've edited – Jonathan199 Apr 2 '17 at 13:19
  • it probably is because you didn't defined AT: try to write rcv instead of AT – Liam Apr 2 '17 at 14:25
  • I don't know where you did your research, but what you used is incorrect, and out of date. See How-do-i-make-serial-work-on-the-raspberry-pi3 - the easiest solution is just to enable serial in raspi-config. You should use /dev/serial0. You also need a ground connection. – Milliways Apr 3 '17 at 0:05
  • After following your steps : *My version is 4.4.50-v7+ so I don't need to enable_uart=1 *Added core_freq=250 *Reboot *Using ttyS0 or serial0 doesn't change anything Now I guess the problem is in my code.. – Jonathan199 Apr 12 '17 at 17:38
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)
  • Thanks a lot, but could you show me your .py file ? – Jonathan199 Apr 28 '17 at 12:32
  • I've added the cde – Manu Apr 29 '17 at 14:23
3

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

  • 1
    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 ? :) – Jonathan199 Apr 2 '17 at 17:44
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

  • 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. – Jonathan199 Apr 2 '17 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.