upm  1.3.0
Sensor/Actuator repository for libmraa (v1.7.0)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Public Member Functions | Protected Member Functions
HM11 Class Reference

API for the HM-11 4.0 Bluetooth Low Energy Module. More...

Detailed Description

The driver was tested with the Grove BLE module. It's an HM-11 BLE 4.0 module based on a TI CC2541 chip. It operates using a standard 'AT' command set. See the datasheet for a full list of available commands and their possible responses:


It is connected via a UART at 9,600 baud.

// Instantiate a HM11 BLE Module on UART 0
upm::HM11* ble = new upm::HM11(0);
// make sure port is initialized properly. 9600 baud is the default.
if (!ble->setupTty(B9600))
cerr << "Failed to setup tty port parameters" << endl;
return 1;
if (argc > 1)
cout << "Sending command line argument (" << argv[1] << ")..." << endl;
sendCommand(ble, argv[1]);
// query the module address
char addr[] = "AT+ADDR?";
cout << "Querying module address (" << addr << ")..." << endl;
sendCommand(ble, addr);
// query the module address
char pin[] = "AT+PASS?";
cout << "Querying module PIN (" << pin << ")..." << endl;
sendCommand(ble, pin);
// Other potentially useful commands are:
// AT+VERS? - query module version
// AT+ROLE0 - set as slave
// AT+ROLE1 - set as master
// AT+CLEAR - clear all previous settings
// AT+RESET - restart the device
// A comprehensive list is available from the datasheet at:
// http://www.seeedstudio.com/wiki/images/c/cd/Bluetooth4_en.pdf

Public Member Functions

 HM11 (int uart)
 ~HM11 ()
bool dataAvailable (unsigned int millis)
int readData (char *buffer, int len)
int writeData (char *buffer, int len)
bool setupTty (speed_t baud=B9600)

Protected Member Functions

int ttyFd ()

Constructor & Destructor Documentation

HM11 ( int  uart)

HM11 object constructor

uartDefault UART to use (0 or 1)
~HM11 ( )

HM11 object destructor

Member Function Documentation

bool dataAvailable ( unsigned int  millis)

Checks to see if there is data available for reading

millisNumber of milliseconds to wait; 0 means no waiting
True if there is data available for reading
int readData ( char *  buffer,
int  len 

Reads any available data into a user-supplied buffer. Note: the call blocks until data is available for reading. Use dataAvailable() to determine whether there is data available beforehand, to avoid blocking.

bufferBuffer to hold the data read
lenLength of the buffer
Number of bytes read
int writeData ( char *  buffer,
int  len 

Writes the data in the buffer to the device

bufferBuffer to hold the data read
lenLength of the buffer
Number of bytes written
bool setupTty ( speed_t  baud = B9600)

Sets up proper tty I/O modes and the baud rate. For this device, the default baud rate is 9,600 (B9600).

baudDesired baud rate.
True if successful

The documentation for this class was generated from the following files: