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


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




rcv = port.read(10)

print rcv


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?

1 Answer 1


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

  • I am not using Pi 3. I am using a Pi 2. Sep 20, 2016 at 6:33
  • @AshwinPajankar Disabling the serial port console is applicable even in that case. It is the default setting on the Raspbian OS to create a serial port console and not specific to a particular model of Pi. Sep 20, 2016 at 6:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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