1

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?

gre_gor
1,6824 gold badges18 silver badges28 bronze badges
asked Jun 18, 2016 at 21:51
4
  • Can you place your schematic? Are you using the 4V regulation and transistor on RST pin? Maybe this library might help Commented Jun 21, 2016 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 ÿ. Commented Jun 22, 2016 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. Commented Jun 23, 2016 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. Commented Jun 23, 2016 at 21:33

7 Answers 7

0
+100

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

answered Jun 21, 2016 at 13:04
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).

answered Jun 21, 2016 at 15:32
1

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

answered Feb 21, 2018 at 14:30
1

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);

answered Mar 4, 2018 at 19:18
1

IIRC, SIM800 modems are very 1990s, they default to 9600 baud. You will get garbage at 38400.

I successfully used a SIM800 at 9600.

answered Mar 8, 2021 at 0:54
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.

answered Jun 21, 2016 at 23:46
0

Sim800 series free Atcommander software.

http://bayanbox.ir/info/3493267131357723232/ATcenter

answered Jan 10, 2021 at 0:38

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.