Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SoftwareSerial BTserial(2, 3); // RX, TX
- #define baud 9600
- void setup()
- {
- // Open serial communications and wait for port to open:
- Serial.begin(baud);
- BTserial.begin(baud);
- at("AT"); // check if working, always returns OK
- at("AT+RENEW"); // select master = central
- at("AT+ROLE1"); // select master = centra
- at("AT+RESET"); // actually more a restart than a reset .. needed after ROLE
- at("AT+SHOW1"); // include Bluetooth name in response
- at("AT+SCAN5"); // set discobery time to 5 seconds
- at("AT+IMME1"); // "work immediately", not sure what this does
- //at("AT+FILT0"); // show all BLE devices, not only HM ones
- delay(1000); // wait a bit, NECESSARY!!
- BTserial.print("AT+DISC?"); // here comes the magic
- while(!BTserial.find("OK+DISCS")) Serial.print(".");
- Serial.println("OK+DISCS");
- }
- void at(char* cmd) {
- BTserial.write(cmd);
- Serial.print(cmd);
- while(!BTserial.find("OK")) Serial.print(".");
- while (BTserial.available()) Serial.write(BTserial.read());
- Serial.println(" .. OK");
- }
- void loop() // run over and over
- {
- if (BTserial.available())
- Serial.write(BTserial.read());
- if (Serial.available())
- BTserial.write(Serial.read());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement