Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[arduino code examples for A32 Pro]-10 How to test AT command with SIM7600 4G modulde
#1
Code:
/*
  Made by KinCony IoT: https://www.kincony.com
  All rights reserved.

  ESP32-S3 with SIM7600 and RS485 Communication
  This program sends an AT command to the SIM7600 4G module every 3 seconds to query its model number.
  The response from the SIM7600 is then sent out through the RS485 interface.

  Connections:
  SIM7600:
    TXD: GPIO18
    RXD: GPIO17
  RS485:
    TXD: GPIO9
    RXD: GPIO8
*/

#include <HardwareSerial.h>

// Create a hardware serial object for SIM7600 communication using UART2
HardwareSerial sim7600(2); // UART2: TXD on GPIO18, RXD on GPIO17

// Create a hardware serial object for RS485 communication using UART1
HardwareSerial rs485(1);   // UART1: TXD on GPIO9, RXD on GPIO8

void setup() {
  // Initialize the default serial port for debugging (Serial Monitor)
  Serial.begin(115200);        // Baud rate of 115200 for debugging

  // Initialize the SIM7600 serial port with baud rate of 115200
  // Set TX to GPIO18 and RX to GPIO17
  sim7600.begin(115200, SERIAL_8N1, 17, 18);

  // Initialize the RS485 serial port with baud rate of 9600
  // Set TX to GPIO9 and RX to GPIO8
  rs485.begin(9600, SERIAL_8N1, 8, 9);

  // Wait for 3 seconds before starting (optional, can be used for initialization delay)
  delay(3000);
}

void loop() {
  // Send the AT command to query SIM7600 module model number
  // "AT+CGMM" is the command used to get the model of the SIM7600
  sim7600.println("AT+CGMM");

  // Wait for 1 second to allow time for the SIM7600 to respond
  delay(1000);

  // Check if there is any data available from the SIM7600 module
  if (sim7600.available()) {
    // Create a string to store the response from the SIM7600
    String simResponse = "";

    // While data is available from the SIM7600, read it byte by byte
    while (sim7600.available()) {
      // Read one byte from the SIM7600 serial
      char c = sim7600.read();
      // Append the byte to the response string
      simResponse += c;
    }
   
    // Send the SIM7600 response to the RS485 serial port
    rs485.print(simResponse);

    // Also print the response to the Serial Monitor for debugging
    Serial.println(simResponse);
  }

  // Wait for 3 seconds before sending the next query
  delay(3000);
}
arduino ino file download: 
.zip   10-4g-sim7600.zip (Size: 1.04 KB / Downloads: 712)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download: 
.zip   10-4g-sim7600.ino.merged.zip (Size: 182.27 KB / Downloads: 712)
Reply
#2
This is a great example of using the ESP32-S3 with the SIM7600 and RS485 communication! The code is well-structured and easy to follow. I appreciate the detailed comments explaining the connections and functionality. The periodic querying of the SIM7600 for its model number is a practical approach for monitoring.
For anyone looking to implement a similar project, make sure to check the baud rates for both the SIM7600 and RS485 to ensure proper communication. Thanks for sharing this valuable resource!
Reply
#3
Here we see the ESP32-S3 in action with the SIM7600 and RS485 connection. The code is organised and straightforward. The thorough explanations of the links and functions in the comments are much appreciated. The SIM7600 can be practically monitored by periodically querying it for its model number.
If you are planning to execute a project similar to this, you should verify that the SIM7600 and RS485 have compatible baud rates. I appreciate you giving me the link to this helpful tool.
Reply


Forum Jump:


Users browsing this thread:
1 Guest(s)