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 – Max 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.. – Max Apr 12 '17 at 17:38
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).

| improve this answer | |
  • 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 2 '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 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 at 18:17
  • @joan thank you so much, this solved my issue :) – Milan Maharjan Jan 28 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)
| improve this answer | |
  • Thanks a lot, but could you show me your .py file ? – Max Apr 28 '17 at 12:32
  • I've added the cde – Manu Apr 29 '17 at 14:23
  • what is the successfull response? – Milan Maharjan Jan 25 at 17:46
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

| improve this answer | |
  • 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 2 '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.

| improve this answer | |

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.