Sim800l icon indicating copy to clipboard operation
Sim800l copied to clipboard

Using HardwareSerial

Open ntdgo opened this issue 6 years ago • 2 comments

SIM800L module and it run perfectly fine with SoftwareSerial. I need to expand I/O so I need to use HardwareSerial. Please teach me how to use HardwareSerial for this module. Thank you so much.

ntdgo avatar Oct 06 '18 10:10 ntdgo

I have same problem, any news to change from SoftwSerial to HardwareSerial?

sgamoct avatar Jan 06 '20 14:01 sgamoct

I made it work with HardwareSerial with ESP32 NodeMCU. Here is how:

1) You need to change Sim800l.h defines first, like that:

#define RX_PIN 16 // This goes to your RX on UART 2 port, acordding to your hardware (ESP in my case)
#define TX_PIN 17 // This goes to your TX on UART 2 port, acordding to your hardware (ESP in my case)
#define BAUD_RATE 9600

2) Now you need to change Sim800l.cpp global variable SoftwareSerial to HardwareSerial:

 /* This goes in your global scope. Remember, we initialize with HardwareSerial object(2) because we are using UART 2 with pins RX2(GPIO 16) and TX2 (GPIO 17)*/
HardwareSerial SIM(2);

3) Modify Sim800l begin method in Sim900l.cpp:

void Sim800l::begin(){
	SIM.begin(BAUD_RATE, SERIAL_8N1, RX_PIN, TX_PIN, false);
      Serial.begin(9600);
  #if (LED) 
    pinMode(OUTPUT,LED_PIN);
  #endif
  _buffer.reserve(255); //reserve memory to prevent intern fragmention
}

4) In your main.cpp, just use it like usual, e.g:

Sim800l mySIM;
String text = "Testing library";
String number = "+999999999999";

void setup(){
	mySIM.begin(); // initializate the library.
      Serial.begin(9600);
	// error = mySIM.sendSms(number,text);
      mySIM.signalQuality();
}

Hope it helps! Best regards.

stefanooliveira avatar Aug 25 '21 14:08 stefanooliveira