Created
February 1, 2018 20:54
-
-
Save sergio1990/13e9134481ce0d053584b81b2f650d28 to your computer and use it in GitHub Desktop.
Arduino UNO sketch to configure HM-10 BLE board
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SoftwareSerial.h> | |
SoftwareSerial mySerial(2, 3); // RX, TX | |
int i = 0; | |
void setup() { | |
mySerial.begin(9600); | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
if (mySerial.available() > 0) { | |
char reply[100]; | |
i = 0; | |
while(mySerial.available() > 0) { | |
reply[i] = (char) mySerial.read(); | |
i += 1; | |
delay(1); | |
} | |
reply[i] = '\0'; | |
Serial.write("Received from BLE board: "); | |
Serial.write(reply); | |
Serial.write("\n"); | |
} | |
if (Serial.available()) { | |
char command[100]; | |
i = 0; | |
while(Serial.available() > 0) { | |
command[i] = (char) Serial.read(); | |
i += 1; | |
delay(1); | |
} | |
command[i] = '\0'; | |
mySerial.write(command); | |
Serial.write("Command is sent: "); | |
Serial.write(command); | |
Serial.write("\n"); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment