Those who worked with Arduino and built any GPRS or IoT project, are familiar with Adafruit_FONA Library. This library is handy for the Arduino platform to build any GSM, GPRS, or related project. But unfortunately, this library doesn’t work with ESP32 directly. And I had awful experiences with this issue. Here is my solution, which you can follow.

Disclaimer:

Advertisements

Configure your IDE for ESP32:

Adafruit_FONA library is very useful and there are many features included in it. But this works fine with Arduino UNO, Mega, etc., not with ESP32 ICs. So, if you really want to use this library, then you must configure your ESP in the right way.

First, select the right ESP board. And if you do not have the board installed, then copy this link “https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json” into preference and search for the ESP32 board and install the ESP board.

After installation, select the right board. In my case, it was the ESP32 wrover module.

Adafruit_FONA Library with ESP32

Start code:

Now, use the following code:

//Easy wash data logging part with the board named 'ESP32 wrover module'

#include"Arduino.h" // as you are using arduino libraries, so its important to include
#include "Adafruit_FONA.h"

//if you use Software Serial
#include <SoftwareSerial.h>
SoftwareSerial fonaSS;
SoftwareSerial *fonaSerial = &fonaSS;

//if you want to use hardware serial
//HardwareSerial fonaSS(1);
//HardwareSerial *fonaSerial = &fonaSS;

#define FONA_RST 32

char replybuffer[255];
Adafruit_FONA fona = Adafruit_FONA(~FONA_RST);

//for 3G
//Adafruit_FONA_3G fona = Adafruit_FONA_3G(FONA_RST);

void setup()
{
  Serial.begin(115200);
  Serial.println("Hano?");//as my kid called hello...
  dly(1000);
  Serial.println(F("Initializing GSM"));
  fonaSerial->begin(4800, SWSERIAL_8N1, 33, 25, false);//for hardware serial use: fonaSerial->begin(115200,SERIAL_8N1,16,17, false);
  if (! fona.begin(*fonaSerial))
  {
    Serial.println(F("Couldn't find FONA"));
    while (1);
  }
  Serial.println(F("FONA is OK"));
  fonaSerial->print("AT+CNMI=2,1\r\n");  //set up the FONA to send a +CMTI notification when an SMS is received
  Serial.println("FONA Ready");
  GSM_ON();

}

void loop()
{


}


int net_status;
uint16_t statuscode;

void GSM_ON()
{
  // make it slow so its easy to read!
again:
  delay(1);
  fonaSerial->begin(4800, SWSERIAL_8N1, 33, 25, false);
  if (! fona.begin(*fonaSerial))
  {
    Serial.println(F("Couldn't find FONA"));
    digitalWrite(FONA_RST, LOW); delay(100);
    digitalWrite(FONA_RST, HIGH); delay(300);
    goto again;
    while (1);
  }
  Serial.println(F("FONA is OK"));
  delay(1000);
  net_status = fona.getNetworkStatus();
  while (net_status != 1)
  {
    net_status = fona.getNetworkStatus();
    delay(1000);
  }
  Serial.println(F("Registered ok"));
  delay(1000);
}


//

Here, the only important and different thing is the

“fonaSerial->begin(4800, SWSERIAL_8N1, 33, 25, false);” line. Unlike Arduino UNO or mega, we need to configure the serial port in detail like this for ESP32.

Now, you can use your fona library as you need. If anywhere, there is any initialization, you need to replace it with the detail one. That’s it.

My result:

My result was satisfactory and worked immediately.

Adafruit_FONA Library with ESP32

Adafruit_FONA Library with ESP32

After this, I used the code for GPRS data posting which worked fine. Just like Arduino. No restarting or failure. I think you can use it now for your project.

Conclusion:

I had been having trouble configuring the ESP32 for fona library and ESP was restarting. Now it’s all solved and works smoothly. I Hope, your’s one will also work fine. See you in the next article, thanks!

You can read my other articles here:

For Professional Designs or Help:

Loading

MKDas

Mithun K. Das. B.Sc. in Electrical and Electronic Engineering (EEE) from KUET. Senior Embedded Systems Designer at a leading international company. Welcome to my personal blog! I share articles on various electronics topics, breaking them down into simple and easy-to-understand explanations, especially for beginners. My goal is to make learning electronics accessible and enjoyable for everyone. If you have any questions or need further assistance, feel free to reach out through the Contact Us page. Thank you for visiting, and happy learning!

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *