upm  0.4.1
Sensor/Actuator repository for libmraa (v0.8.0)
Public Member Functions | List of all members

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.HM11 ble = new upm_hm11.HM11(0);
// make sure port is initialized properly. 9600 baud is the default.
if (!ble.setupTty()) {
System.err.println("Failed to setup tty port parameters");
System.exit(-1);
}
printUsage();
if (args.length > 0) {
System.out.println("Sending command line argument (" + args[0] + ")...");
sendCommand(ble, args[0].getBytes());
} else {
// query the module address
String addr = "AT+ADDR?";
System.out.println("Querying module address (" + addr + ")...");
sendCommand(ble, addr.getBytes());
Thread.sleep(1000);
// query the module address
String pin = "AT+PASS?";
System.out.println("Querying module pin (" + pin + ")...");
sendCommand(ble, pin.getBytes());
// 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

synchronized void delete ()
 
 HM11 (int uart)
 
boolean dataAvailable (long millis)
 
int readData (byte[] buffer)
 
int writeData (byte[] buffer)
 
boolean setupTty (int baud)
 
boolean setupTty ()
 

Constructor & Destructor Documentation

HM11 ( int  uart)

HM11 object constructor

Parameters
uartDefault UART to use (0 or 1)

Member Function Documentation

boolean dataAvailable ( long  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
boolean setupTty ( int  baud)

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 file: