Skip to content

Instantly share code, notes, and snippets.

@sergio1990
Created February 1, 2018 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergio1990/13e9134481ce0d053584b81b2f650d28 to your computer and use it in GitHub Desktop.
Save sergio1990/13e9134481ce0d053584b81b2f650d28 to your computer and use it in GitHub Desktop.
Arduino UNO sketch to configure HM-10 BLE board
#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