1

I have recently procured a SIM 900A UART module. I am supplying power to the module with +5 and GND of RPi.

SIM900A interfaced with RPi

import serial

import RPi.GPIO as GPIO   

import os, time

GPIO.setmode(GPIO.BOARD)    

port = serial.Serial("/dev/ttyAMA0", baudrate=9600, timeout=1)

port.flush()

port.write('AT'+'\r\n')

port.write("\x0D\x0A")

rcv = port.read(10)

print rcv

time.sleep(1)

The code above is supposed to print OK on the screen. However, it does not print anything or prints garbage. Can anyone please help me?

KennetRunner
  • 1,050
  • 7
  • 13
Ashwin Pajankar
  • 183
  • 4
  • 9
  • 21

1 Answers1

2

The port /dev/ttyAMA0 on the raspberry pi 3 maps to the bluetooth and to the standard serial port on the others

Assuming you have used the default raspbian image, you will first need to disable the serial console as detailed here

The Broadcom UART appears as /dev/ttyAMA0 under Linux. There are several minor things in the way if you want to have dedicated control of the serial port on a Raspberry Pi. Firstly, the kernel will use the port as controlled by kernel command line contained in /boot/cmdline.txt. The file will look something like this:

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

The console keyword outputs messages during boot, and the kgdboc keyword enables kernel debugging. You will need to remove all references to ttyAMA0. So, for the example above /boot/cmdline.txt, should contain:

dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

You must be root to edit this (e.g. use sudo nano /boot/cmdline.txt). Be careful doing this, as a faulty command line can prevent the system booting.``` Secondly, after booting, a login prompt appears on the serial port. This is controlled by the following lines in /etc/inittab:

#Spawn a getty on Raspberry Pi serial line T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

You will need to edit this file to comment out the second line, i.e.

#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

Shreyas Murali
  • 2,416
  • 1
  • 15
  • 22