0

I have SIM800l module connected to Arduino and I'm trying to initialize it in my setup function with this code:

#include <SoftwareSerial.h>

//SIM800 TX is connected to Arduino D8
#define SIM800_TX_PIN 6
//SIM800 RX is connected to Arduino D7
#define SIM800_RX_PIN 7
SoftwareSerial serialSIM800(SIM800_TX_PIN,SIM800_RX_PIN);

void setup()
{
  Serial.begin(38400);
  while(!Serial);
  serialSIM800.begin(38400);
  Serial.println("wait for .... it");
  delay(10000);


  // comments added just for example, both commands return junk
  //serialSIM800.write("AT\r\n"); 
  //serialSIM800.write("AT+SAPBR=3,1,\"Contype\",\"GPRS\"\r\n");

  Serial.println("command sent");
  delay(2500);

  Serial.write(serialSIM800.read());
}

But Serial.write returns junk.

When I use this code in loop:

  //Read SIM800 output (if available) and print it in Arduino IDE Serial Monitor
  if(serialSIM800.available()){
    Serial.write(serialSIM800.read());
  }
  //Read Arduino IDE Serial Monitor inputs (if available) and send them to SIM800
  if(Serial.available()){    
    serialSIM800.write(Serial.read());
  }

and send AT+SAPBR=3,1,"Contype","GPRS" or just AT command with serial monitor, everything works fine.

Can someone help with this?

  • Can you place your schematic? Are you using the 4V regulation and transistor on RST pin? Maybe this library might help – brtiberio Jun 21 '16 at 10:36
  • What sort of junk? Copy and paste please. Also writing the output from a read, without testing for available is likely to return "junk" or at least ÿ. – Nick Gammon Jun 22 '16 at 3:55
  • You're reading only a byte like others have noted. Also, you seem to be sending 2 commands, one immediately after the other. This could result in gibberish. Though it would be nice to see exactly what your 'junk' results are. – TisteAndii Jun 23 '16 at 3:26
  • 1
    I'm a bit surprised you have put a bounty of +100 rep on this question, but are not answering queries like the comments above, that might help resolve it. – Nick Gammon Jun 23 '16 at 21:33
0
+100

You can try to use serialSIM800.println("AT") instead of write. Here some examples https://github.com/stanleyhuangyc/Freematics/issues/17

1

NeoSWSerial would be better for this. It can read and write at the same time, unlike SoftwareSerial, and it doesn't disable interrupts for the entire character receive time (~1ms!). AltSoftSerial would be even better, but you can only use it on pins 8 & 9 (on an UNO, different pins on other Arduinos).

0

My SIM808 returns a bit of junk right from the get-go, so that might be influencing things.

Also, it's conceivable you are retrieving a -1 from your initial serialSIM800.read() call - it's a nonblocking call and returns -1 when no data is available. That would almost definitely appear as junk.

0

Somewhere you said that ...but Serial.write return's junk.... Make sure that serial print is Both NL & CR

0

You are getting junk because of baud rate, set as 9600.

Serial.begin(9600); while(!Serial); serialSIM800.begin(9600); Serial.println("wait for .... it"); delay(10000);

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.