Advertisement
pleasedontcode

"SIM800L Control" rev_22

Jun 13th, 2024
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "SIM800L Control"
  13.     - Source Code NOT compiled for: Arduino Nano ESP32
  14.     - Source Code created on: 2024-06-13 11:19:54
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* initialize gsm */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <SoftwareSerial.h> //https://github.com/plerup/espsoftwareserial
  25. #include <Sim800L.h> //https://github.com/vittorioexp/Sim800L-Arduino-Library-revised
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30. void updateOutputs(void);
  31.  
  32. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  33. const uint8_t gsm_SIM800L_RING_PIN_D3 = 3;
  34.  
  35. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  36. const uint8_t gsm_SIM800L_RST_PIN_D2 = 2;
  37. const uint8_t gsm_SIM800L_DTR_PIN_D4 = 4;
  38.  
  39. /***** DEFINITION OF Software Serial *****/
  40. const uint8_t gsm_SIM800L_Serial_PIN_SERIAL_TX_A0 = A0;
  41. const uint8_t gsm_SIM800L_Serial_PIN_SERIAL_RX_A1 = A1;
  42. SoftwareSerial gsm_SIM800L_Serial(gsm_SIM800L_Serial_PIN_SERIAL_RX_A1, gsm_SIM800L_Serial_PIN_SERIAL_TX_A0);
  43.  
  44. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  45. /***** used to store raw data *****/
  46. bool gsm_SIM800L_RST_PIN_D2_rawData = 0;
  47. bool gsm_SIM800L_DTR_PIN_D4_rawData = 0;
  48.  
  49. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  50. /***** used to store data after characteristic curve transformation *****/
  51. float gsm_SIM800L_RST_PIN_D2_phyData = 0.0;
  52. float gsm_SIM800L_DTR_PIN_D4_phyData = 0.0;
  53.  
  54. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  55. Sim800L GSM(&gsm_SIM800L_Serial, gsm_SIM800L_RST_PIN_D2, gsm_SIM800L_RING_PIN_D3, gsm_SIM800L_DTR_PIN_D4);
  56.  
  57. void setup(void)
  58. {
  59.   // put your setup code here, to run once:
  60.   pinMode(gsm_SIM800L_RING_PIN_D3, INPUT_PULLUP);
  61.   pinMode(gsm_SIM800L_RST_PIN_D2, OUTPUT);
  62.   pinMode(gsm_SIM800L_DTR_PIN_D4, OUTPUT);
  63.  
  64.   gsm_SIM800L_Serial.begin(9600);
  65.  
  66.   // Initialize GSM module
  67.   GSM.begin(4800);
  68.  
  69.   // Minimum functionality
  70.   if (!GSM.setFunctionalityMode(0)) Serial.println("ERROR");
  71.   else Serial.println("Minimum functionality");
  72.  
  73.   Serial.print("Functionality mode: ");
  74.   Serial.println(GSM.getFunctionalityMode());
  75.   delay(5000);
  76.  
  77.   // Full functionality
  78.   if (!GSM.setFunctionalityMode(1)) Serial.println("ERROR");
  79.   else Serial.println("Full functionality");
  80.  
  81.   Serial.print("Functionality mode: ");
  82.   Serial.println(GSM.getFunctionalityMode());
  83.   delay(5000);
  84.  
  85.   // Flight mode (disable RF function)
  86.   if (!GSM.setFunctionalityMode(4)) Serial.println("ERROR");
  87.   else Serial.println("Flight mode (disable RF function)");
  88.  
  89.   Serial.print("Functionality mode: ");
  90.   Serial.println(GSM.getFunctionalityMode());
  91.   delay(5000);
  92. }
  93.  
  94. void loop(void)
  95. {
  96.   // put your main code here, to run repeatedly:
  97.   updateOutputs(); // Refresh output data
  98. }
  99.  
  100. void updateOutputs()
  101. {
  102.   digitalWrite(gsm_SIM800L_RST_PIN_D2, gsm_SIM800L_RST_PIN_D2_rawData);
  103.   digitalWrite(gsm_SIM800L_DTR_PIN_D4, gsm_SIM800L_DTR_PIN_D4_rawData);
  104. }
  105.  
  106. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement