Skillnad mellan versioner av "Grove - BLE v1"

Från Karlskrona Makerspace Wiki
Hoppa till: navigering, sök
 
 
(3 mellanliggande versioner av samma användare visas inte)
Rad 1: Rad 1:
 
+
[[Fil:Grove-BLE.png|200px|thumb|right|Grove - BLE v1]]
 
== Kompatibilitet ==
 
== Kompatibilitet ==
 
* Arduino
 
* Arduino
Rad 8: Rad 8:
 
== Exempelkod ==
 
== Exempelkod ==
 
=== Arduino ===
 
=== Arduino ===
<syntaxhighlight lang="C++" line>
 
 
Demo : BLE Slave
 
Demo : BLE Slave
 
--------------------
 
--------------------
  
 +
<syntaxhighlight lang="C++" line>
 
     #include <SoftwareSerial.h>  //Software Serial Port
 
     #include <SoftwareSerial.h>  //Software Serial Port
 
     #define RxD 2
 
     #define RxD 2
Rad 104: Rad 104:
  
 
[[Category:Grove]]
 
[[Category:Grove]]
 +
[[Category:Grove-Communication]]
 
[[Category:Communication]]
 
[[Category:Communication]]
 +
[[Category:Kna-Wiki]]

Nuvarande version från 4 februari 2021 kl. 07.45

Grove - BLE v1

Kompatibilitet

  • Arduino

Port

  • Digital

Exempelkod

Arduino

Demo : BLE Slave


    #include <SoftwareSerial.h>   //Software Serial Port
    #define RxD 2
    #define TxD 3

    #define DEBUG_ENABLED  1

    SoftwareSerial BLE(RxD,TxD);

    void setup()
    {
      Serial.begin(9600);
      pinMode(RxD, INPUT);
      pinMode(TxD, OUTPUT);
      setupBleConnection();

    }

    void loop()
    {
      char recvChar;
      while(1){
        if(BLE.available()){//check if there's any data sent from the remote BLE
          recvChar = BLE.read();
          Serial.print(recvChar);
        }
        if(Serial.available()){//check if there's any data sent from the local serial terminal, you can add the other applications here
          recvChar  = Serial.read();
          BLE.print(recvChar);
        }
      }
    }

    void setupBleConnection()
    {
      BLE.begin(9600); //Set BLE BaudRate to default baud rate 9600
      BLE.print("AT+CLEAR"); //clear all previous setting
      BLE.print("AT+ROLE0"); //set the bluetooth name as a slaver
      BLE.print("AT+SAVE1");  //don't save the connect information
    }

Demo : BLE Master


    #include <SoftwareSerial.h>   //Software Serial Port
    #define RxD 2
    #define TxD 3

    #define DEBUG_ENABLED  1

    SoftwareSerial BLE(RxD,TxD);

    void setup()
    {
      Serial.begin(9600);
      pinMode(RxD, INPUT);
      pinMode(TxD, OUTPUT);
      setupBleConnection();

    }

    void loop()
    {
      char recvChar;
      while(1){
        if(BLE.available()){//check if there's any data sent from the remote BLE
          recvChar = BLE.read();
          Serial.print(recvChar);
        }
        if(Serial.available()){//check if there's any data sent from the local serial terminal, you can add the other applications here
          recvChar  = Serial.read();
          BLE.print(recvChar);
        }
      }
    }

    void setupBleConnection()
    {
      BLE.begin(9600); //Set BLE BaudRate to default baud rate 9600
      BLE.print("AT+CLEAR"); //clear all previous setting
      BLE.print("AT+ROLE1"); //set the bluetooth name as a master
      BLE.print("AT+SAVE1");  //don't save the connect information
    }

Mer information

http://wiki.seeedstudio.com/Grove-BLE_v1/