0

I've recently bought SIM900 with this module.
Connected it to Raspberry Pi - GND, 5V, RX-TX, TX-RX. I'm using following code to test it (found on web):

#! /usr/bin/env python
import argparse
from datetime import datetime
import logging
from serial import Serial
from sim900 import Sim900, SMSReader
from time import sleep


LOG_FILE = 'sensor.log'
LOG_LEVEL = logging.INFO
LOG_FORMAT = '%(levelname)s - %(message)s'


def main():  
    # Parse command line arguments
    #
    # The default settings will work well for the pcDuino. If you
    # are using a laptop or Raspberry Pi, then you will need to set
    # the serial baud rate to 9600 and make sure the shield is running at 
    # 4800. An alternative is to increase buffer size in the Arduino SoftwareSerial
    # library.
    parser = argparse.ArgumentParser(description='Run SMS Data Logger.')
    parser.add_argument('-p', '--port', help='Serial port', default='/dev/ttyAMA0')
    parser.add_argument('-b', '--baudrate', type=int, help='Baudrate of Sim900 GSM shield', default=9600)
    args = parser.parse_args()

    port = args.port
    baudrate = args.baudrate


    # Setup logger
    logging.basicConfig(level=LOG_LEVEL, format=LOG_FORMAT)

    logger = logging.getLogger()
    file_log_handler = logging.FileHandler(LOG_FILE)
    logger.addHandler(file_log_handler)

    formatter = logging.Formatter(LOG_FORMAT)
    file_log_handler.setFormatter(formatter)

    # Creates a serial connection to Sim900 shield
    sim900 = Sim900(Serial(port, baudrate=baudrate, timeout=0), delay=0.5)

    # Listens for incoming SMS
    reader = SMSReader(sim900)

    # For non-pcDuino devices, there looks to be a delay before commands
    # are sent and read correctly. Waiting two seconds seems to work.
    print "Initializing serial connection..."
    sleep(2)

    print ""
    print "Sim900 SMS Data Reader"
    print "----------------------"
    print ""
    print "Press CTRL+C to stop the program."
    print ""

    print reader.init_reader()

    while True:
        text_msg = reader.listen()
        if text_msg is not None:
            logger.info("Text message received at {0}.".format(datetime.now().strftime("%m/%d/%Y %H:%M:%S")))
            logger.info(text_msg)


if __name__ == '__main__':
    main()

Here is sim900.py

According to init_reader method, it should return "Sim900 response to commands." when connected properly, but it returns "No active connection".
Am I missing something with connection or my code? The NET LED should turn on?
I just want to use it to send/receive SMS messages...

2
  • are you running it with sudo ?
    – rob
    Sep 5, 2014 at 7:45
  • yes, if i don't, it says, that he has no access to /dev/ttyAMA0
    – Djent
    Sep 5, 2014 at 14:37

1 Answer 1

-1

OK, I needed to connect PWR on SIM900 to GPIO pin in raspberry. Now it works.

2
  • It is unclear from your question which pin on the Pi you connected to; it would help others if you made that clear. Sep 25, 2014 at 17:46
  • Any GPIO pin, not a special one. In my case GPIO 22 pin.
    – Djent
    Sep 25, 2014 at 19:09

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.