The Controller mode provides a variety of ways to control your Bluefruit LE enabled project including Sensor Data, Control Pad, & Color Picker.
This data is sent from the phone/tablet to the Bluefruit device.
Format for Sent Data
For an example of how to parse the data on Arduino, check out the BLE_Controller_Test code on github.
- Each Controller data packet sent is prefixed with single byte char “!” (0x21) followed by a single byte char initial for identification.
- Sensor data values are encoded as floats of 4 byte length.
- Each packet ends with a single byte checksum for validation.
Checksum
The single-byte checksum that appends each Controller data packet is calculated by adding all previous bytes of the packet and then inverting the sum.
An example of how to use the checksum to validate a Controller packet can be found in the BLE_Controller_Test Arduino sketch:
boolean checkCRC(uint8_t *buffer) {
uint8_t len = sizeof(buffer);
uint8_t crc = buffer[len-2];
uint8_t sum = 0;
for (int i = 0; i < (len-1); i++) {
sum += buffer[i];
}
Serial.print("CRC ");
if ((crc & ~sum) == 0) {
Serial.println("PASS");
return true;
}
else {
Serial.println("FAIL");
return false;
}
}
Sensors
The top section of the Controller table lists the available types of sensor data which can be streamed from your iOS device. Tap the button at the right of each sensor row to begin streaming its relevant data.
- All sensor data updates, except for Location, are sent out over BLE ten times per second.
- Location updates are sent whenever GPS data changes, or every 30 seconds if no change occurs.
• Quaternion - sends iOS Device Motion data to describe device attitude. This data is derived from Accelerometer, Gyro, and Magnetometer readings.
Prefix: !Q
Format:
[‘!’] [‘Q’] [float x] [float y] [float z] [float w] [CRC]
• Accelerometer - sends raw accelerometer data.
Prefix: !A
Format:
[‘!’] [‘A’] [float x] [float y] [float z] [CRC]
• Gyro - sends raw gyroscope data.
Prefix: !G
Format:
[‘!’] [‘G’] [float x] [float y] [float z] [CRC]
• Magnetometer - sends raw, uncalibrated magnetometer data.
Prefix: !M
Format:
[‘!’] [‘M’] [float x] [float y] [float z] [CRC]
• Location - sends GPS data, requires user permission before initial use.
Prefix: !L
Format:
[‘!’] [‘L’] [float lat.] [float long.] [float alt.] [CRC]
The Control Pad function provides a familiar momentary button interface for common control scenarios. Data is sent on the press and release of each button. Each packet consists of 4 bytes, each representing a char value. The first two chars identify the packet as a button message, the third specifies a button, and the fourth signifies either a press or release.
Prefix: !B
Examples:
Button 4 pressed: [‘!’] [‘B’] [‘4’] [‘1’] [CRC]
Button 4 released: [‘!’] [‘B’] [‘4’] [‘0’] [CRC]
Button Up pressed: [‘!’] [‘B’] [‘5’] [‘1’] [CRC]
Button Down pressed: [‘!’] [‘B’] [‘6’] [‘1’] [CRC]
Button Left pressed: [‘!’] [‘B’] [‘7’] [‘1’] [CRC]
Button Right pressed: [‘!’] [‘B’] [‘8’] [‘1’] [CRC]
Note: Any activated sensor data streams will continue while using the Control Pad.
The Color Picker sends a color's RGB values to Bluefruit LE. This can be used to control the state of RGB LEDs such as Neopixels.
• Touch the color wheel to choose desired color
• Press Send to send the chosen color's red, green, and blue values to Bluefruit via UART in the following format:
Prefix: !C
Format:
[‘!’] [‘C’] [byte red] [byte green] [byte blue] [CRC]
Note: Any activated sensor data streams will continue while using the Color Picker.
Text editor powered by tinymce.