0

I am working on a project with a Mega 2560 and a Sim800L module.

Everything works fine, however if i don't connect the USB port (at least once) and power only externally (either by Vin unregulated 7-12V or 5V regulated pin) the program will seem not to initialize serial in setup().

I found this which is related to the issue but not a proper workaround: https://forum.arduino.cc/index.php?topic=24642.0

edit: I can confirm using a resistor to short pins 0+1 together (serial) works but it is not a proper solution. This means you have to disassemble your project to access the resistor or add a switch if you want to use USB to debug later or upload new code. Another workaround which i need to test is to remove all Serial code (because i can in my specific project), but again this is not a proper solution. Any ideas please?

edit2: for comments

if(SIM900.available()>0){
// AT command to set SIM900 to SMS mode
SIM900.print("AT+CMGF=1\r"); 
delay(100);
// Set module to send SMS data to serial out upon receipt 
SIM900.print("AT+CNMI=2,2,0,0,0\r");
delay(100);
textMessage = SIM900.readString();
textMessage.toUpperCase();
Serial.print(textMessage);    
delay(10);
} 

if(textMessage.indexOf("SET PHONE")>=0){
// Set phone number to receive notifications
phoneNumber = textMessage.substring(9,21);
Serial.println("Phone number set to: " + phoneNumber);  
String message = "Notification number set to: " + phoneNumber + "\nSend 'Help' for additional commands.\nNote in case of reset number returns to hardcoded default";
sendSMS(message);
Serial.println("Confirmication of phone number change sent");
textMessage = "";   
}
  • so why the softwareserial tag? Sim800 is on Serial1/2/3? do you use some old AVR core version or IDE? – Juraj Dec 24 '19 at 7:45
  • That link is 13 years old and I did not hear about that pin 0/1 trick recently. Do you have such an old Arduino board? Are you sure the USB controller (ATmega16U2 ?) does not get its Vcc HIGH via Vin? – DataFiddler Dec 24 '19 at 10:24
  • You did not provide any code, so we have to guess. Do you print to the Serial Terminal on your PC/Laptop in the Sketch. The if you don't connect the Arduino with the PC you do not establish the serial connection to the terminal. Perhaps you added a blocking command, that waits for the connection. Connecting Pin0 and Pin1 simulates the Terminal connection and the blocking code does not block. If I'm right, a solution would be to remove the blocking code. But I don't know code, so I can't tell you how, – Peter Paul Kiefer Dec 24 '19 at 11:18
  • @juraj Because i use softwareserial to connect to sim800. I converted it to hardware serial as a test and it works but needs some more changes – TnF Dec 24 '19 at 12:13
  • @DataDiffler My board is not old, i can check if that's the case – TnF Dec 24 '19 at 12:14
1

Ok i found the issue and the solution.

For some reason it seems that while the MCU is running Setup(); hardware or software serial don't work properly.

In my case i have code that set the SIM module to SMS mode and to send those messages to the serial port.

For some reason it doesn't send them (or probably the module is not ready to accept them).

Connecting the USB cable reset the arduino and run setup() when opening the serial monitor setting the module in the correct mode.

Adding this code in the main loop solves this issue even though i have them powered both by the same step down converter.

edit: That turns out 1 hour later after debugging more is not exactly a proper solution to the issue. That command to set into SMS mode only works when you are connected to the network.

I have a check for that and a reset function.

So now at Setup() i wait 10s for the module to boot up so it is ready to open a serial port, then i check if it is connected to the network before i send the commands to set into SMS mode.

Example:

// Initializing serial commmunication
Serial.begin(57600); 
delay(10000);

while (ini){
    Serial3.begin(57600);
    delay(1000);
    Serial3.print("AT+CGREG?\r"); 
    delay(100);
    netStatus = Serial3.readString();
    if (netStatus.charAt(22) == '5' || netStatus.charAt(22) == '1') {
         digitalWrite(LED_NET, HIGH);
         ini=false;
         }
    else {  
        digitalWrite(LED_NET, LOW);
        digitalWrite(resetPin, LOW);
        delay(2000);
        digitalWrite(resetPin, HIGH);
        delay(30000);
        }
}
  Serial.print("SIM800 ready...");

  // AT command to set SIM800 to SMS mode
  Serial3.print("AT+CMGF=1\r"); 
  delay(100);
  // Set module to send SMS data to serial out upon receipt 
  Serial3.print("AT+CNMI=2,2,0,0,0\r");
  delay(100);
|improve this answer|||||

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.