Created
May 15, 2023 15:28
-
-
Save woodif/3a09bbaeec9cd53eaf094b036c07bc7b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Description: input AT commands via serial monitor to learn how to use 4G module | |
// version:v1.0 | |
// Author:Vincent | |
// web: http://www.makerfabs.com | |
// This version is modify for SIM7600 | |
// If define MODE_1A | |
// When "1A" or "1A" is entered, 0x1A is sent to the module. | |
// When sending SNS information, you need to send 0x1A to end the input. | |
#include <stdio.h> | |
#include <string.h> | |
#define DEBUG true | |
#define MODE_1A | |
#define DTR_PIN 9 | |
#define RI_PIN 8 | |
#define LTE_PWRKEY_PIN 5 | |
#define LTE_RESET_PIN PA10 | |
#define LTE_FLIGHT_PIN 7 | |
String from_usb = ""; | |
void setup() | |
{ | |
Serial.begin(115200); | |
//while (!SerialUSB) | |
{ | |
; // wait for Arduino serial Monitor port to connect | |
} | |
delay(100); | |
Serial2.begin(115200); | |
//Serial1.begin(UART_BAUD, SERIAL_8N1, MODEM_RXD, MODEM_TXD); | |
pinMode(LTE_RESET_PIN, OUTPUT); | |
digitalWrite(LTE_RESET_PIN, LOW); | |
pinMode(LTE_PWRKEY_PIN, OUTPUT); | |
digitalWrite(LTE_RESET_PIN, LOW); | |
delay(100); | |
digitalWrite(LTE_PWRKEY_PIN, HIGH); | |
delay(2000); | |
digitalWrite(LTE_PWRKEY_PIN, LOW); | |
pinMode(LTE_FLIGHT_PIN, OUTPUT); | |
digitalWrite(LTE_FLIGHT_PIN, LOW); //Normal Mode | |
// digitalWrite(LTE_FLIGHT_PIN, HIGH);//Flight Mode | |
Serial.println("Maduino Zero 4G Test Start!"); | |
sendData("AT+CGMM", 3000, DEBUG); | |
} | |
void loop() | |
{ | |
while (Serial2.available() > 0) | |
{ | |
Serial.write(Serial2.read()); | |
yield(); | |
} | |
while (Serial.available() > 0) | |
{ | |
#ifdef MODE_1A | |
int c = -1; | |
c = Serial.read(); | |
if (c != '\n' && c != '\r') | |
{ | |
from_usb += (char)c; | |
} | |
else | |
{ | |
if (!from_usb.equals("")) | |
{ | |
sendData(from_usb, 0, DEBUG); | |
from_usb = ""; | |
} | |
} | |
#else | |
Serial2.write(Serial.read()); | |
yield(); | |
#endif | |
} | |
} | |
bool moduleStateCheck() | |
{ | |
int i = 0; | |
bool moduleState = false; | |
for (i = 0; i < 5; i++) | |
{ | |
String msg = String(""); | |
msg = sendData("AT", 1000, DEBUG); | |
if (msg.indexOf("OK") >= 0) | |
{ | |
Serial.println("SIM7600 Module had turned on."); | |
moduleState = true; | |
return moduleState; | |
} | |
delay(1000); | |
} | |
return moduleState; | |
} | |
String sendData(String command, const int timeout, boolean debug) | |
{ | |
String response = ""; | |
if (command.equals("1A") || command.equals("1a")) | |
{ | |
Serial.println(); | |
Serial.println("Get a 1A, input a 0x1A"); | |
//Serial1.write(0x1A); | |
Serial2.write(26); | |
Serial2.println(); | |
return ""; | |
} | |
else | |
{ | |
Serial2.println(command); | |
} | |
long int time = millis(); | |
while ((time + timeout) > millis()) | |
{ | |
while (Serial2.available()) | |
{ | |
char c = Serial2.read(); | |
response += c; | |
} | |
} | |
if (debug) | |
{ | |
Serial.print(response); | |
} | |
return response; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment