upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Public Member Functions | Protected Member Functions

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:

http://www.seeedstudio.com/wiki/images/c/cd/Bluetooth4_en.pdf

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

hm11.jpg
// Instantiate a HM11 BLE Module on UART 0
upm::HM11 ble(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;
}
printUsage(argv[0]);
if (argc > 1) {
cout << "Sending command line argument (" << argv[1] << ")..." << endl;
sendCommand(ble, argv[1]);
} else {
// query the module address
char addr[] = "AT+ADDR?";
cout << "Querying module address (" << addr << ")..." << endl;
sendCommand(ble, addr);
upm_delay(1);
// 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

Parameters
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

Parameters
millisNumber of milliseconds to wait; 0 means no waiting
Returns
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.

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

Writes the data in the buffer to the device

Parameters
bufferBuffer to hold the data read
lenLength of the buffer
Returns
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).

Parameters
baudDesired baud rate.
Returns
True if successful

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