Sponsored Content
Top Forums Programming Basic Arduino UNO Bluetooth Testing with the BLE 4.0 (CC2541, MLT-BT04 IC) Post 303043347 by Neo on Saturday 25th of January 2020 09:06:56 AM
Old 01-25-2020
Basic Arduino UNO Bluetooth Testing with the BLE 4.0 (CC2541, MLT-BT04 IC)

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:

Code:
 /*
  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:

Code:
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):

Basic Arduino UNO Bluetooth Testing with the BLE 4.0 (CC2541, MLT-BT04 IC)-img_9037jpg
This User Gave Thanks to Neo For This Post:
 

7 More Discussions You Might Find Interesting

1. OS X (Apple)

Semi-Automatic Arduino Detection.

I am working on a semi-auto detection idea for Arduino for the Scope project. It does require a little user intervention but minimal. It works by just responding to two on screen prompts to unplug and plug Arduino into a USB port. There are two versions and both work perfectly well and give... (3 Replies)
Discussion started by: wisecracker
3 Replies

2. Programming

Very Basic Arduino Uno Board Testing

A very simple Arduino board test... LOL Here is some very easy code to test a cheap Arduino board I just got from China via Aliexpress. I am still waiting on a about 30 more orders from Aliexpress for more Arduino stuff. This was the first order which made it here. /* Arduino test-code... (18 Replies)
Discussion started by: Neo
18 Replies

3. Programming

Arduino-cli - Uploading to Unknown Chinese Arduino Boards using the Arduino Command Line Interface

In my further exploration of Arduino, today I decided to install the arduino-cli on my mac today. https://github.com/arduino/arduino-cli I followed the instructions for macOS but when I got to this part: arduino-cli board list I got the dreaded "Unknown" Fully Qualified Board Name... (1 Reply)
Discussion started by: Neo
1 Replies

4. Programming

More Arduino Stuff...

HI all... (Apologies for any typos.) To add to Neo's Arduino subject matter I have decided to upload this in ".zip" format. Ignore "*.info" files these are AMIGA icons only and also the "HAM" drawer as these are photos in ancient AMIGA HAM modes. I have noticed that there are current... (6 Replies)
Discussion started by: wisecracker
6 Replies

5. Programming

Chinese Arduino UNO Clones - The Wavgat versus the generic UNO R3 Clone - The Winner Is?

Waiting for more fun Ardunio parts from AliExpress, I decided to test two cheap Chinese Arduino UNO clones. The Arduino UNO R3 (CH340G) MEGA328P The Wavgat UNO R3 (CH340G) MEGA328P Both of these Chinese Ardunio clones sell for about $3 USD, delivered to your door. The bottom line is... (0 Replies)
Discussion started by: Neo
0 Replies

6. Programming

Arduino UNIX Time - Syncing Computer UNIX Time to Arduino Time with Python

Just finished a quick Python script to send the current unix time over to the Arduino from macOS, so in the absence of GPS or some other way to get the unix timestamp (epoch time) to the Arduino, I can get my macOS and Arduino UNO synced to within a second. Normally, when the Arduino starts... (9 Replies)
Discussion started by: Neo
9 Replies

7. Programming

Arduino Project: iPhone to HM-10 BLE to NB-IoT Shield to NB-IoT Network to Internet to Linux Server

This post describes a "work in progress" project I started today. Here is the High Level Overview: Currently, this project sits on my desk as an Arduino UNO (on the bottom), an NB-IoT Shield (sandwiched in the middle), a Sensor Shield (on top) with a HM-10 BLE Module (in the little... (13 Replies)
Discussion started by: Neo
13 Replies
All times are GMT -4. The time now is 02:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy