Created
September 22, 2020 13:50
-
-
Save dehanjl/ec7cef52648e68c887783837c093d560 to your computer and use it in GitHub Desktop.
Change AT settings of the HM-10
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
// Dehan Lamprecht, 2020 | |
// Allows changing the settings of the HM-10 (or MLT-BT05) module | |
// Adapted from http://www.martyncurrey.com/hm-10-bluetooth-4ble-modules/ | |
#include <SoftwareSerial.h> | |
SoftwareSerial BTSerial(2, 3); // RX | TX | |
char c=' '; | |
boolean NL = true; | |
void setup() | |
{ | |
Serial.begin(9600); | |
Serial.print("Sketch: "); Serial.println(__FILE__); | |
Serial.print("Uploaded: "); Serial.println(__DATE__); | |
Serial.println(" "); | |
BTSerial.begin(9600); // default baud rate of HM-10. | |
Serial.println("BTserial started at 9600"); | |
} | |
void loop() | |
{ | |
// Read from the Bluetooth module and send to the Arduino Serial Monitor | |
if (BTSerial.available()) | |
{ | |
c = BTSerial.read(); | |
Serial.write(c); | |
} | |
// Read from the Serial Monitor and send to the Bluetooth module | |
if (Serial.available()) | |
{ | |
c = Serial.read(); | |
// do not send line end characters to the HM-10, or do, these things are nothing if not inconsistent | |
//if (c!=10 & c!=13 ) | |
//{ | |
BTSerial.write(c); | |
//} | |
// Echo the user input to the main window. | |
// If there is a new line print the ">" character. | |
if (NL) { Serial.print("\r\n>"); NL = false; } | |
Serial.write(c); | |
if (c==10) { NL = true; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment