私はSIM800lモジュールをArduinoに接続していますが、私はこのコードで私のセットアップ機能で初期化しようとしています:
#include
//SIM800 TX is connected to Arduino D8
#define SIM800_TX_PIN 6
//SIM800 RX is connected to Arduino D7
#define SIM800_RX_PIN 7
SoftwareSerial serialSIM800(SIM800_TX_PIN,SIM800_RX_PIN);
void setup()
{
Serial.begin(38400);
while(!Serial);
serialSIM800.begin(38400);
Serial.println("wait for .... it");
delay(10000);
//comments added just for example, both commands return junk
//serialSIM800.write("AT\r\n");
//serialSIM800.write("AT+SAPBR=3,1,\"Contype\",\"GPRS\"\r\n");
Serial.println("command sent");
delay(2500);
Serial.write(serialSIM800.read());
}
しかし、 Serial.write
はjunkを返します。
ループでこのコードを使用すると:
//Read SIM800 output (if available) and print it in Arduino IDE Serial Monitor
if(serialSIM800.available()){
Serial.write(serialSIM800.read());
}
//Read Arduino IDE Serial Monitor inputs (if available) and send them to SIM800
if(Serial.available()){
serialSIM800.write(Serial.read());
}
シリアルモニタで AT + SAPBR = 3,1、 "Contype"、 "GPRS"
コマンドまたは単に AT
コマンドを送信すると、すべて正常に動作します。
誰かがこれを助けることができますか?