Advertisement
mikroavr

test_at_command

Feb 8th, 2022 (edited)
1,526
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define SerialMon Serial
  2. #define SerialAT Serial1
  3.  
  4. #define RXD2 26
  5. #define TXD2 25
  6.  
  7. #define PKEY 14
  8. unsigned long cur_time, old_time;
  9.  
  10. bool hold = 0;
  11.  
  12. void setup() {
  13.   // put your setup code here, to run once:
  14.   SerialMon.begin(115200);
  15.   SerialAT.begin(115200, SERIAL_8N1, RXD2, TXD2);
  16.   delay(1000);
  17.   Serial.println("test at mulai");
  18.   pinMode(PKEY, OUTPUT);
  19.   pinMode(27, OUTPUT);
  20.   digitalWrite(PKEY, HIGH);
  21.   /*
  22.   delay(1100);
  23.  
  24.   digitalWrite(PKEY, LOW);
  25.   delay(1100);
  26.   digitalWrite(PKEY, HIGH);
  27.   */
  28.   wRespon(15000);
  29.   //change_baud();
  30.  
  31. }
  32.  
  33. void loop() {
  34.   // put your main code here, to run repeatedly:
  35.   Serial.println("SEND AT");
  36.   digitalWrite(27,HIGH);
  37.   send_at("AT+IPR?");
  38.   digitalWrite(27,LOW);
  39.   send_at("AT+CPIN?");
  40.   digitalWrite(27,HIGH);
  41.   send_at("AT+COPS?");
  42.   digitalWrite(27,LOW);
  43.   send_at("AT+CSQ");
  44.   digitalWrite(27,HIGH);
  45.   send_at("AT+CREG?");
  46.   digitalWrite(27,LOW);
  47. }
  48.  
  49. void change_baud() {
  50.   send_at("AT");
  51.   send_at("AT+IPR=?");
  52.   Serial.println("change baut rate");
  53.   send_at("AT+IPR=9600");
  54.   send_at("AT&W");
  55.   SerialAT.begin(9600, SERIAL_8N1, RXD2, TXD2);
  56.   while (1) {
  57.     send_at("AT");
  58.     send_at("AT+IPR?");
  59.     //send_at("AT&V");
  60.     delay(1000);
  61.   }
  62. }
  63.  
  64. void send_at(char *_command) {
  65.   SerialAT.println(_command);
  66.   wRespon(1000);
  67. }
  68.  
  69. void wRespon(long waktu) {
  70.   cur_time = millis();
  71.   old_time = cur_time;
  72.   while (cur_time - old_time < waktu ) {
  73.     cur_time = millis();
  74.     while (SerialAT.available() > 0) {
  75.       Serial.print(SerialAT.readString());
  76.     }
  77.   }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement