1
我試圖連接嵌入了Quectel M95模塊的GSM2Click板的Arduino UNO板。 Vcc = 5V已由開關正確設置。我用一個外部直流電源爲電路板供電。 我做了以下連接:Arduino和GSM2Click板(Quectel M95)
ARDUINO pin | GSM pin:
3 (TX) RX
2 (RX) TX
8 STA
7 PWK (always high)
的gsm2click板似乎是積極的,因爲無論是開關電源和網絡上(淨LED閃爍)。 我試圖讓發送AT命令,但總是得到0作爲答案:
#include <SoftwareSerial.h>
const int PWK= 7; // Analog output pin that the LED is attached to
const int STA= 8;
const int RX=2;
const int TX=3;
int STA_value;
SoftwareSerial mySerial(RX,TX); // RX, TX
void setup() {
// initialize the digital pin as an output.
pinMode(PWK, OUTPUT); // questo pin serve per accendere il dispositivo GSM
pinMode(STA, INPUT);
pinMode(RX,INPUT);
pinMode(TX,OUTPUT);
gsmOn();
Serial.begin(9600); //Init seriale sw
Serial.println("Arduino serial initialized!");
delay(10);
mySerial.begin(9600); //init seriale hw
Serial.println("Software serial initialized!");
delay(10);
}
// the loop routine runs over and over again forever:
void loop()
{
sendCommand("AT");
delay(10);
readSerial();
delay(1000);
}
void sendCommand(char* msg)
{
mySerial.print(msg);
Serial.println(msg);
delay(1);
}
void readSerial()
{
while(mySerial.available()>0)
{
Serial.print(mySerial.read());
delay(1);
}
}
void gsmOn()
{
// Takes 30 seconds to complete
digitalWrite(PWK, HIGH); // turn the Phone on
delay(2);
}
什麼建議嗎?
感謝大家提前!
我試過你的代碼,它按預期工作。不過,我有一個評論,你爲什麼要檢查2個可能的答案?也許模塊有時會給出一個不好的答案?對於您決定使用函數strstr()進行比較,是否有特定含義? – divivoma
其實@divivoma這是一個大型代碼(項目)的一部分,我們發送這樣的AT命令,期望兩個答案,這將有助於您日後進一步處理和使用GSM模塊做一些不錯的東西,否則你可以避免1個答案。沒有使用strstr的特殊原因,但這是兩個字符串比較和易於使用的內置函數。如果你的問題得到解決,那麼你應該投票回答這個問題 –
好的。現在很清楚。對不起,但我不能將它作爲答案投票,因爲我的聲望仍然很低。我會盡快做到這一點。 – divivoma