Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define SerialMon Serial
- #define SerialAT Serial1
- #define RXD2 26
- #define TXD2 25
- #define PKEY 14
- unsigned long cur_time, old_time;
- bool hold = 0;
- void setup() {
- // put your setup code here, to run once:
- SerialMon.begin(115200);
- SerialAT.begin(115200, SERIAL_8N1, RXD2, TXD2);
- delay(1000);
- Serial.println("test at mulai");
- pinMode(PKEY, OUTPUT);
- pinMode(27, OUTPUT);
- digitalWrite(PKEY, HIGH);
- /*
- delay(1100);
- digitalWrite(PKEY, LOW);
- delay(1100);
- digitalWrite(PKEY, HIGH);
- */
- wRespon(15000);
- //change_baud();
- }
- void loop() {
- // put your main code here, to run repeatedly:
- Serial.println("SEND AT");
- digitalWrite(27,HIGH);
- send_at("AT+IPR?");
- digitalWrite(27,LOW);
- send_at("AT+CPIN?");
- digitalWrite(27,HIGH);
- send_at("AT+COPS?");
- digitalWrite(27,LOW);
- send_at("AT+CSQ");
- digitalWrite(27,HIGH);
- send_at("AT+CREG?");
- digitalWrite(27,LOW);
- }
- void change_baud() {
- send_at("AT");
- send_at("AT+IPR=?");
- Serial.println("change baut rate");
- send_at("AT+IPR=9600");
- send_at("AT&W");
- SerialAT.begin(9600, SERIAL_8N1, RXD2, TXD2);
- while (1) {
- send_at("AT");
- send_at("AT+IPR?");
- //send_at("AT&V");
- delay(1000);
- }
- }
- void send_at(char *_command) {
- SerialAT.println(_command);
- wRespon(1000);
- }
- void wRespon(long waktu) {
- cur_time = millis();
- old_time = cur_time;
- while (cur_time - old_time < waktu ) {
- cur_time = millis();
- while (SerialAT.available() > 0) {
- Serial.print(SerialAT.readString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement