• Arduino 3G shield using SoftwareSerial to control


    On the 3G shield, by default the power pin is on D8 and reset pin is on D9. Make it HIGH then it works.

    if you want to play this 3G shield using SoftwareSerial on Arduino, 

    Try this code:

    /*
    
    Change UART control ports from Tx0 / Rx1 to Tx2 / Rx3  using SoftwareSerial
    And reserve Tx0 / Rx1 for debugging
    
    */
    
    #include <SoftwareSerial.h>
    
    
    #define rxPin 6
    #define txPin 7
    
    #define power_pin 8
    #define reset_pin 9
    
    SoftwareSerial mySerial(rxPin, txPin); // RX, TX
    
    char AtCommand[] = "ATI
    ";
    void setup()  
    {
     // Open serial communications and wait for port to open:
     Serial.begin(115200);
     while (!Serial) {
       ; // wait for serial port to connect. Needed for Leonardo only
     }
      pinMode(rxPin, INPUT);
      pinMode(txPin, OUTPUT);
      
       // power on 3G module automatically
      pinMode(power_pin, OUTPUT);
      digitalWrite(power_pin, HIGH);  
      
      delay(5000);
      
      Serial.println(AtCommand);
    
     
      // set the data rate for the SoftwareSerial port
      mySerial.begin(115200);
      mySerial.println(AtCommand);
      //mySerial.write(AtCommand);
    }
    
    
    
    void loop() // run over and over
    {
      if (mySerial.available())
      {
        Serial.write(mySerial.read());
      }
      if (Serial.available())
      {
        mySerial.write(Serial.read());
      }
    }

    if you play with this 3G shield, and you want to enable power at the setup, and change the baud rate from 115200 to 9600 on your arduino when communicating with chip SIM5126E.

    Try this code:

    /*
    
    Change UART control ports from Tx0 / Rx1 to Tx2 / Rx3  using SoftwareSerial
    And reserve Tx0 / Rx1 for debugging
    
    */
    #include <SoftwareSerial.h>
    
    #define rxPin 6
    #define txPin 7
    #define baudrate 9600
    
    #define power_pin 8
    #define reset_pin 9
    
    
    SoftwareSerial mySerial(rxPin, txPin); // RX, TX
    
    char AtCommand[] = "ATI
    ";
    void setup()  
    {
      // Open serial communications and wait for port to open:
      Serial.begin(baudrate);
      while (!Serial) {
        ; // wait for serial port to connect. Needed for Leonardo only
      }
      pinMode(rxPin, INPUT);
      pinMode(txPin, OUTPUT);
      
      Serial.println(AtCommand);
    
      // set the data rate for the SoftwareSerial port
      Serial.println("wait 5s for modem to wake up");
      
      // power on 3G module automatically
      pinMode(power_pin, OUTPUT);
      digitalWrite(power_pin, HIGH);
      
      delay(5000);
      mySerial.begin(115200);
      mySerial.println("AT+IPR=9600
    "); // chnage baudrate to 9600 baud
      
      Serial.println("Changing baudrate");
      mySerial.begin(baudrate);
      mySerial.println(AtCommand);
    }
    
    void loop() // run over and over
    {
      if (mySerial.available())
      {
        Serial.write(mySerial.read());
      }
      if (Serial.available())
      {
        mySerial.write(Serial.read());
      }
    }
  • 相关阅读:
    Java多线程系列--“基础篇”11之 生产消费者问题
    Java多线程系列--“基础篇”10之 线程优先级和守护线程
    Java多线程系列--“基础篇”09之 interrupt()和线程终止方式
    Java多线程系列--“基础篇”08之 join()
    Java四种线程池的使用
    数据库索引的实现原理
    Java多线程系列--“基础篇”07之 线程休眠
    Java多线程系列--“基础篇”06之 线程让步
    Java多线程系列--“基础篇”05之 线程等待与唤醒
    Java多线程系列--“基础篇”04之 synchronized关键字
  • 原文地址:https://www.cnblogs.com/spaceship9/p/4770196.html
Copyright © 2020-2023  润新知