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:
Handling electricity carries inherent risks. It’s essential to have the appropriate skills to manage it safely. Proceed at your own risk, as the author disclaims responsibility for any misuse, harm, or errors. All content on this website is unique and copyrighted; please avoid unauthorized copying. While most articles are open-source for your benefit, feel free to use the knowledge provided. If you find our resources helpful, consider purchasing available materials to support our work.
For assistance or guidance, leave a comment below; the author is committed to helping. Some articles may contain affiliate links that support the author with a commission at no additional cost to you. Thank you for your understanding and support.
Table of Contents
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.
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.
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:
- INA219 interfacing with STM32
- Logging Data to Excel from Arduino
- STM32 as USB Device
- Send SMS from Raspberry Pi using the GSM module
- Not Enough ROM/RAM error with micro-controllers
- Read ThingSpeak Channel using ESP8266 and Arduino
- Caller ID detection using Arduino
- Digital Clock with DS3231 & PIC microcontroller
For Professional Designs or Help:
0 Comments