Here is a sketch to do basic testing for the Arduino UNO and the MLT-BT04.
This BLE module works with IOS (iPhone) and I'll add some details on my IOS testing with an iPhone in a follow-up post.
For now, here is the basic BLE (HM-10) sketch for the Arduino UNO:
/*
Arduino test-code fir BLE MLT-BT04 to the Arduino board.
BLE Version 4.0 Module chipset: CC2541
Schematic: Arduino D7 to MLT-BT04 TX
Schematic: Arduino D8 to MLT-BT04 RX
Schematic: Arduino GRD to MLT-BT04 GRD
Schematic: Arduino 3.3v to MLT-BT04 ACC
Prints Help Menu for the CC2541 and some other sample AT commands.
Neo: www.unix.com version 0.1 January 2020
Modified version of an unattributed CC2541 firmware example sketch.
Use as you wish, with or without attribution.
*/
#include <SoftwareSerial.h>
SoftwareSerial ble_device(7, 8); // RX, TX
String str_ii = "";
int ii_0 = 0;
bool debug = false;
void setup() {
Serial.begin(9600);
delay(1000);
ble_device.begin(9600);
delay(1000);
// First, get all available functions from CC2541 firmware
ble_cmdhelp();
ble_cmdln("AT+LADDR");
ble_cmdln("AT+NAME");
ble_cmdln("AT+CHAR");
ble_cmdln("AT+UUID");
if (debug) Serial.print("\nEND BLE SKETCH\n");
}
void loop() {
}
void ble_cmdhelp() {
ble_device.println("AT+HELP"); // list all AT+ commands
while (true) { // loop to print all AT+ commands
char in_char = ble_device.read();
if (int(in_char) == -1 or int(in_char) == 42) {
continue;
}
str_ii += in_char;
if (in_char == '\n') {
if (str_ii == String('\r') + String('\n')) {
if (ii_0 == 0) {
ii_0 = 1;
continue;
}
break; // break after more than 1 empty carriage return and newline
}
Serial.print(str_ii);
str_ii = "";
}
}
}
void ble_cmdln(String cmd) {
if (debug) Serial.print("\nSTART " + cmd + "\n");
ble_device.println(cmd); // get basic AT+ command
delay(1000);
while (ble_device.available() > 0) {
char in_char = ble_device.read();
if (in_char) {
str_ii += in_char;
}
else {
break;
}
}
Serial.println(str_ii);
if (debug) Serial.print("END " + cmd + "\n");
str_ii = "";
}
Sample serial monitor output:
20:44:41.624 ->
20:44:41.624 -> Command Description
20:44:41.846 -> ----------------------------------------------------------------
20:44:42.061 -> AT Check if the command terminal work normally
20:44:42.247 -> AT+DEFAULT Restore factory default
20:44:42.431 -> AT+BAUD Get/Set baud rate
20:44:42.612 -> AT+RESET Software reboot
20:44:42.836 -> AT+ROLE Get/Set current role.
20:44:43.059 -> AT+DISC Disconnect connection
20:44:43.244 -> AT+ADVEN Broadcast switch
20:44:43.423 -> AT+ADVI Broadcast interval
20:44:43.633 -> AT+NINTERVAL Connection interval
20:44:43.851 -> AT+POWE Get/Set RF transmit power
20:44:44.061 -> AT+NAME Get/Set local device name
20:44:44.250 -> AT+LADDR Get local bluetooth address
20:44:44.432 -> AT+VERSION Get firmware, bluetooth, HCI and LMP version
20:44:44.653 -> AT+TYPE Binding and pairing settings
20:44:44.864 -> AT+PIN Get/Set pin code for pairing
20:44:45.046 -> AT+UUID Get/Set system SERVER_UUID .
20:44:45.231 -> AT+CHAR Get/Set system CHAR_UUID .
20:44:45.447 -> AT+INQ Search from device
20:44:45.632 -> AT+RSLV Read the scan list MAC address
20:44:45.817 -> AT+CONN Connected scan list device
20:44:46.040 -> AT+CONA Connection specified MAC
20:44:46.222 -> AT+BAND Binding from device
20:44:46.443 -> AT+CLRBAND Cancel binding
20:44:46.632 -> AT+GETDCN Number of scanned list devices
20:44:46.852 -> AT+SLEEP Sleep mode
20:44:47.036 -> AT+HELP List all the commands
20:44:47.467 -> ---------------------------------------------------------------
20:44:48.680 ->
20:44:48.680 -> +LADDR=20:C3:8F:8A:54:4A
20:44:48.680 ->
20:44:49.694 -> +NAME=MLT-BT05
20:44:49.694 ->
20:44:50.713 -> +CHAR:FFE1
20:44:50.713 ->
20:44:51.698 -> +UUID:FFE0
20:44:51.698 ->
Simple setup (pinouts in sketch above):