How to use BLE Shield based on HM-10 bluetooth module?

后端 未结 3 871
眼角桃花
眼角桃花 2021-02-10 15:19

I\'m a new bie on arduino projects. I would like to ask you for some help. I bought a BLE Shield for Arduino from ( http://imall.iteadstudio.com/development-platform/arduino/shi

3条回答
  •  无人及你
    2021-02-10 15:50

    This is a little late too, but try the following code, if you send it "AT" it should give you back an "OK":

    #include   
    
    int bluetoothTx = 2;  // TX-O pin of bluetooth mate, Arduino D2
    int bluetoothRx = 3;  // RX-I pin of bluetooth mate, Arduino D3
    
    SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
    
    void setup()
    {
      Serial.begin(9600);  // Begin the serial monitor at 9600bps
    
      bluetooth.begin(115200);  // The Bluetooth Mate defaults to 115200bps
      delay(100);  // Short delay, wait for the Mate to send back CMD
      bluetooth.println("U,9600,N");  // Temporarily Change the baudrate to 9600, no parity
      // 115200 can be too fast at times for NewSoftSerial to relay the data reliably
      bluetooth.begin(9600);  // Start bluetooth serial at 9600
    }
    
    void loop()
    {
      if(bluetooth.available())  // If the bluetooth sent any characters
      {
        // Send any characters the bluetooth prints to the serial monitor
        Serial.print((char)bluetooth.read());  
      }
      if(Serial.available())  // If stuff was typed in the serial monitor
      {
        // Send any characters the Serial monitor prints to the bluetooth
        bluetooth.print((char)Serial.read());
      }
      // and loop forever and ever!
    }
    

提交回复
热议问题