Advertisement
microrobotics

SIM7020E GSM Module

Apr 14th, 2023
2,167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. In this example, I'll provide you with an Arduino code to test the all-round functionality of the SIM7020E module by sending various AT commands and receiving responses. The code will cover basic operations such as checking the module status, registering to the network, getting network information, and sending a UDP packet. Note that this code assumes you are using an Arduino Uno or a similar board.
  3.  
  4. First, connect the SIM7020E module to the Arduino as follows:
  5.  
  6. Vcc to 5V
  7. GND to GND
  8. RX (SIM7020E) to TX (Arduino)
  9. TX (SIM7020E) to RX (Arduino)
  10.  
  11. Upload this code to your Arduino and open the Serial Monitor. The Arduino will send various AT commands to the SIM7020E module and display the received responses in the Serial Monitor. This will help you to test the all-round functionality of the SIM7020E module.
  12.  
  13. Make sure you have a proper power supply for the SIM7020E module, as it may draw a high current during operation. Also, ensure you have an NB-IoT SIM card inserted into the module and that it is registered with the network.
  14.  
  15. Please note that the "IP" and "PORT" placeholders in the "AT+CSOSEND" command should be replaced with the actual IP address and port number of the destination server you want to send the UDP packet to.
  16. */
  17.  
  18. // SIM7020E GSM Module
  19. // Example code for Arduino
  20.  
  21. #include <SoftwareSerial.h>
  22.  
  23. const int simRxPin = 10; // Connect the RX pin of the SIM7020E to Digital Pin 10
  24. const int simTxPin = 11; // Connect the TX pin of the SIM7020E to Digital Pin 11
  25.  
  26. SoftwareSerial simSerial(simRxPin, simTxPin); // Create a SoftwareSerial object for communication with the SIM7020E
  27.  
  28. void setup() {
  29.   Serial.begin(9600); // Initialize the serial communication for debugging
  30.   simSerial.begin(9600); // Initialize the software serial communication with the SIM7020E
  31.  
  32.   delay(5000); // Wait for the SIM7020E to power on and initialize
  33.   Serial.println("SIM7020E Test");
  34. }
  35.  
  36. void loop() {
  37.   // Test AT command
  38.   sendATCommand("AT");
  39.  
  40.   // Check SIM card status
  41.   sendATCommand("AT+CPIN?");
  42.  
  43.   // Query network registration status
  44.   sendATCommand("AT+CEREG?");
  45.  
  46.   // Get network information
  47.   sendATCommand("AT+CGPADDR");
  48.  
  49.   // Set UDP parameters
  50.   sendATCommand("AT+CSOSEND=0,\"IP\",\"PORT\",\"Hello World!\"");
  51.  
  52.   delay(10000); // Wait for 10 seconds before running the test again
  53. }
  54.  
  55. void sendATCommand(const char *command) {
  56.   // Send an AT command to the SIM7020E
  57.   simSerial.println(command);
  58.  
  59.   // Wait for a response from the SIM7020E
  60.   while (!simSerial.available()) {
  61.     delay(100);
  62.   }
  63.  
  64.   // Read the response from the SIM7020E
  65.   String response = simSerial.readStringUntil('\n');
  66.  
  67.   // Print the command and response to the Serial Monitor
  68.   Serial.print("Command: ");
  69.   Serial.println(command);
  70.   Serial.print("Response: ");
  71.   Serial.println(response);
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement