SIM7600X 4G HAT 模块驱动代码 + ESP32S3 + Arduino IDE 测试(亲测有效)

目录

一、前言

二、SIM7600X 4G HAT简介

三、Arduino例程

(一)SIM7600X的工作方式        

(二)Arduino驱动代码(使用的ESP32S3)

硬件连接:

Source Code/Program:

 三、SIM7600 简单AT指令测试(基于Arduino IDE )

  (一)AT常用指令(效果图略)

 (二)Get GNSS(链接GPS有源天线)

(三)TF卡读写 

​编辑

 四、总结


一、前言

        这两天拿到了一个SIM7600模块,便找到官网查看如何通过Arduino去对他进行驱动,如何发送AT指令,结果遇到了困难:我正确地分配了对应的UART串口,但是依旧无法得到SIM7600的响应,注意:我这里使用的是旧版SIM7600X-4G-HAT模块。

        在本文将分为:一是关于SIM7600X的简介以及相关资料如何跳转,我都将会一一列出;二是对我实测过的AT指令代码进行介绍;三是就我整理的驱动代码进行分享(可能这才是大家来看的原因)。

二、SIM7600X 4G HAT简介

        啥都不说,先上官网链接,里面有很详细的资料,可以收藏起来,先看完我的文章再看它;

链接:SIM7600X 4G & LTE Cat-1 HAT - Waveshare Wiki

        认真的说,详细的功能描述如果你感兴趣的话可以花时间阅读一下官网的资料系统全面很多。

        我这里只简单的说一下我目前实测的过的功能

        1、插上电话卡(我扣的自己手机的),然后利用SIM7600X模块打电话、发短信、上网都可以实现。说的是要插4G天线,但我实验的时候没用天线,也可以,但可能用了天线信号会更好。

        2、可以和GPS的有源天线链接,然后进行定位操作,和我之前用过的ATK1218-BD模块的功能一样。

  感兴趣的话可以点击链接跳转大概游览一下:【ATK1218-BD】北斗/GPS定位模块 + Arduino 测试开发-CSDN博客

         3、我个人感觉它更重要的功能是作为一个物联网系统的组成部分,我是有打算用树莓派连接摄像头进行监控,然后再加上SIM7600X模块实现联网,把树莓派处理视频得到的信息直接上传到云端平台,使得系统更加智能化省去人工成本。(但这个功能涉及到比较多的其他元素,只是略微带过)

三、Arduino例程

        我一开始就是安装官网上的指示,现在安装了Waveshare_SIM7600X_Arduino_Library然后用库里面的示例来进行的测试,但是一直都是没有模块响应,或者是一直输出RDY,很奇怪,所以最后我才会自己去编写一个驱动。(我也想能直接拿来就用的呀)

Waveshare_SIM7600X_Arduino_Library链接:(可以先试试,也许能直接成功)

sim7600/sim7600/Arduino/Waveshare_SIM7600X_Arduino_Library at master · aryaggg/sim7600 (github.com)

(一)SIM7600X的工作方式        

        首先,我们需要了解一下SIM7600X的工作方式,也就是所谓的AT指令。我的建议是先把SIM7600X 4G HAT模块直接通过USB线与电脑连接,用电脑的串口调试助手来手动给SIM7600发送指令,让他来执行。(这一过程是很快的,也能用来排除你的模块本身有没有出问题)

        直接参照官网里面的软件环境里面的步骤,安装好串口调试助手和驱动文件。之后打开串口助手就可以开始发送AT指令了。

         AT指令的发送与SIM7600模块的回应:

       

        上图中的 AT+<> 就是一条AT指令,每一句都有他代表的含义,而模块也会有相应的回复,具体如下:

更多的AT指令可以通过:(官网专门的文件里查找)文件:SIM7500 SIM7600 Series AT Command Manual V3.00.pdf - Waveshare Wiki

******AT Command of SIM7600CE-4g-HAT Module********

  AT+CGMI    // Request manufacturer identification
  AT+CGMM    // Request model identification
  AT+CGSN    // Request product serial number identification
  AT+CSUB    // Request the module version and chip

  AT+CGPS=1      // Start GPS session 
  AT+CGPSINFO    // Get GPS fixed position information
  AT+CGPS=0      // Stop GPS session

  AT+CPIN?     // Request the state of the SIM card
  AT+CICCID    // Read ICCID from SIM card
  AT+CNUM      // Request the subscriber number
  AT+CNMP?     // Preferred mode selection
  AT+COPS?     // Check the current network operator

  AT+IPREX?    // Check local baud rate
  AT+CRESET    // Reset the module 

  AT+CSCA="XXXXXX"       // Set the SMS service centre address
  AT+CMGF=1              // Select SMS message format
  AT+CMGS="xxxxxx"       // Send message to "xxxxxx"(the receiver number).

  AT+CSDVC         // Switch voice channel device
  AT+CSDVC=1       // 1-Handset, 3-Speaker phone
  AT+CLVL=2        // Set loudspeaker volume level to 2, the level range is 0 to 5

  AT+HTTPINIT         // Initialize and start the HTTP
  AT+HTTPPARA="URL","http://www.makerfabs.com"  // Set the URL
  AT+HTTPACTION=0    // Connect the HTTP. (0-get, 1-post, 2-head)
  AT+HTTPHEAD        // Read the response's header.
  AT+HTTPREAD=0,3    // Read the content

  AT+FSCD=D:                    // Select SD card directory as current directory
  AT+FSLS                       // List directories/files in current directory
  AT+CFTRANRX="D: TEST.txt",10  // Transfer a file to EFS
  AT+CFTRANTX="D: TEST.txt"     // Transfer a file from EFS to host

         再通过电脑的串口进行一些基本的操作之后(打电话、发短信之类的),就可以确定自己的模块有没有错,有没有买到盗版,SIM卡有没有插对等等。

(二)Arduino驱动代码(使用的ESP32S3)

硬件连接:

(注意:下表只适用于ESP32S3的引脚

ESP32S3SIM7600X 4G HAT
RX(PIN16)TX
TX(PIN17)RX
PIN18DTR
PIN19RI

        对于如何给模块供电,我直接采用了另一个USB线连接USB口(不是USB转UART那个)给模块供电,且上面的照片中没有拍到!!!(因为DEBUG的时候发现:上文提到的有时候模块会一直回复:RDY,有可能是就是因为ESP32S3的引脚供电不足)除此之外,由于我的是旧版模块,我在PWR和GND之间也连了一根线,作用是让模块上电时自启动。

        在这里补充一下怎么根据模块上的指示灯来判断模块所处状态:(详细内容去官网查看开关机说明:SIM7600X 4G & LTE Cat-1 HAT - Waveshare Wiki

        在这里我再次重复一下我为啥会在PWR和GND直接连一根线:

        至于DTR和RI这两个引脚的作用可以翻看 《SIM7600数据手册》中的《UART应用说明》

数据手册链接:SIM7600数据手册 - Waveshare Wiki

Source Code/Program:

Now open the Arduino IDE and paste the following sketches below.Verify the code and upload.

#include <HardwareSerial.h>

// Define the serial port used to communicate with the SIM7600CE module
HardwareSerial simSerial(2);

// Connect SIM7600 TX to ESP32 pin 16,
//         SIM7600 RX to ESP32 pin 17.
#define ESP_RX  16
#define ESP_TX  17

// Define the DTR and RI pins used for hardware flow control
const int dtrPin = 18;
const int riPin = 19;

char in = '"';

void setup() {
  // Start the serial ports at the appropriate baud rates
  Serial.begin(115200);
  simSerial.begin(115200, SERIAL_8N1, ESP_RX, ESP_TX);

  // Set the DTR and RI pins as outputs and initialize them to HIGH
  pinMode(dtrPin, OUTPUT);
  digitalWrite(dtrPin, HIGH);
  pinMode(riPin, OUTPUT);
  digitalWrite(riPin, HIGH);

  // Wait for the serial ports to initialize
  delay(1000);
  
  // Print a message to the Arduino IDE Serial Monitor to indicate that the program is ready
  Serial.println("AT command program ready");
}

void loop() {
  // Send an AT command to the SIM7672S module and print the response
  simSerial.println("AT");
  delay(1000);
  printResponse();

  // Send a second AT command to the SIM7672S module and print the response
  simSerial.println("AT+CSQ");
  delay(1000);
  printResponse();

  // Send a second AT command to the SIM7672S module and print the response
  simSerial.println("AT+CGMM");
  delay(1000);
  printResponse();

    // Send a second AT command to the SIM7672S module and print the response
  simSerial.println("AT+CGPS");
  delay(1000);
  printResponse();

  // Send a second AT command to the SIM7672S module and print the response
  simSerial.println("AT+CGPS=1");
  delay(1000);
  printResponse();

  // Send a second AT command to the SIM7672S module and print the response
  simSerial.println("AT+CGPS");
  delay(1000);
  printResponse();

  // Send a second AT command to the SIM7672S module and print the response
  simSerial.println("AT+CGPSINFO");
  delay(1000);
  printResponse();

  // Send a second AT command to the SIM7672S module and print the response
  simSerial.println("AT+CGPSINFO");
  delay(1000);
  printResponse();
  simSerial.println("AT+CGPSINFO");
  delay(1000);
  printResponse();
  simSerial.println("AT+CGPSINFO");
  delay(1000);
  printResponse();

    // Send a second AT command to the SIM7672S module and print the response
  simSerial.println("AT+CGPS=0");
  delay(1000);
  printResponse();

  simSerial.println("AT+FSCD=D:");
  delay(1000);
  printResponse();

  simSerial.println("AT+FSLS");
  delay(1000);
  printResponse();

  /* AT+CFTRANRX="File.txt" in commandRX*/
  String commandRX = "AT+CFTRANRX=";
  commandRX += in;
  commandRX += "D:/914TEST/TEXT.txt";
  commandRX += in;
  commandRX += ",14";
  simSerial.println(commandRX);  
  delay(1000);
  printResponse();

  /* test content in commandtest */
  String commandtest =  "hello world.";
  simSerial.println(commandtest);  
  delay(1000);
  printResponse();

  /* AT+CFTRANTX="File.txt" in commandTX*/
  String commandTX = "AT+CFTRANTX=";
  commandTX += in;
  commandTX += "D:/914TEST/TEXT.txt";
  commandTX += in;
  simSerial.println(commandTX);
  delay(1000);
  printResponse();

}

void printResponse() {
  // Set the DTR pin LOW to signal the SIM7672S module to start sending data
  digitalWrite(dtrPin, LOW);

  // Read any available data from the serial port and write it to the Arduino IDE Serial Monitor
  while (simSerial.available()) {
    Serial.write(simSerial.read());
  }

  // Set the RI pin HIGH to signal the SIM7672S module that the data has been received
  digitalWrite(riPin, HIGH);
}

 三、SIM7600 简单AT指令测试(基于Arduino IDE )

  (一)AT常用指令(效果图略)

1

2

3

4

AT+CGMI    // Request manufacturer identification

AT+CGMM    // Request model identification

AT+CGSN    // Request product serial number identification

AT+CSUB    // Request the module version and chip

 (二)Get GNSS(链接GPS有源天线)

1

2

3

AT+CGPS=1      // Start GPS session

AT+CGPSINFO    // Get GPS fixed position information

AT+CGPS=0      // Stop GPS session

(三)TF卡读写 

1

2

3

4

    AT+FSCD=D:                    // Select SD card directory as current directory

    AT+FSLS                       // List directories/files in current directory

    AT+CFTRANRX="D: TEST.txt",10  // Transfer a file to EFS

    AT+CFTRANTX="D: TEST.txt"     // Transfer a file from EFS to host

 四、总结

        上述内容简单的讲述了关于SIM7600的内容,最精彩的联网等内容没有展开描述,但对于文章目的:初步的驱动SIM7600模块,还是可以达标的。

        挖坑:接下来我将会把SIM7600X 4G HAT模块和树莓派联系起来,并和树莓派的摄像头一起去进行一个远程人脸识别系统的搭建,在此过程中关于SIM7600的内容还会持续更新。

        如果对本文的内容有任何改进的建议也欢迎评论\私信告诉我!如果本文对你有帮助的话,不妨点个赞。欢迎留言讨论问题,一起讨论问题、解决问题。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值