We (Senic YC S13) have been developing our hardware product nuimo — a freely programmable, wireless controller for connected devices.
We wanted to share our experience of using Bluetooth Low Energy including how a BLE connection works, an intro to our GATT profile, and ways you can advantage of the sensory inputs and LED matrix output of the nuimo.
We have also provided code examples of how to do an API call, keyboard shortcuts and AppleScript to program your nuimo. Nuimo is available for presale through Kickstarter.
Input and Output for Nuimo
The nuimo controller offers a number inputs that are easily mappable to computer applications or connected devices.
The four main sensor inputs include an analog ring that runs around the circumference of the device, capacitive touch, haptic click and a gesture sensor that allow a sweep motion over the device or upwards from the device. The nuimo also features an 11x11 LED matrix that can show simple graphics through the face of the device.
Input: Click
Input: Turn of the High-Precision Ring (Rotate left and Rotate right)
Input: Capacitive Touch (4 different swipes: top-bottom, bottom-top, left-right and right-left)
Input: Gesture Control (Gesture up, Gesture down, Fly-over left and Fly-over right)
Output: LED Matrix Output
Understanding Bluetooth Low Energy
Nuimo connects via Bluetooth Low Energy (aka Bluetooth 4.0, BLE or Bluetooth Smart). Bluetooth Low Energy is a relatively new standard introduced in 2010. In contrast to other low power connection standards like Zigbee or 6LoWPAN, BLE is built into most smartphones, computers and smart hubs.
BLE is designed for the periodic transfer of small amounts of sensor data, requiring extremely low power consumption. BLE devices maintain a sleep mode most of the time until a connection has been initiated with a peripheral device. This makes BLE an excellent choice for wearables and other mobile hardware devices that rely on battery power.
Depending on the module, the peak current while sending data is about 10 mA. Due to very short initial connection times, the average current is as low as just a few uA. This makes it possible for devices to run on the power of just a coin cell battery for up to a few years.
Likewise, for a high-throughput stream of data (> 100 kbps), classic Bluetooth or Wifi may be better options — although they require more power than BLE.
How Bluetooth Low Energy Works
The BLE connection is created between two devices:
- A Central Device acting as the client that scans for and establishes the connection.
- A Peripheral Device acting as the server that ‘advertises’ for and accepts incoming connections.
The connection happens when the peripheral device sends out an advertising package that denotes it is prepared to accept data. The central device picks up this package and requests an exclusive connection with the peripheral device. The peripheral device stops advertising, accepts the connection and data can then be exchanged.
Nuimo is a peripheral device and acts as the server which can be paired with either your smartphone or computer as the central device. Additionally, our integration with Logitech and subsequent integrations allow the nuimo access to smart hub APIs such as the Logitech Harmony Home Hub.
Over the next months, we will be adding more direct integrations with the major smart home hubs. At the moment, 30+ applications and integrations are supported including Philips Hue, LIFX to Spotify and Sonos.
Advertising and Scanning
The advertising package from the peripheral device (in this case nuimo) has a data payload of up to 31 bytes and includes the basic header information. Header information can include things like name, service UUID or similar info to be transmitted. This means that data can already be received from the advertising device even without establishing a connection. Each package is sent at an interval ranging from 20ms to around 10 seconds — the shorter the interval, the faster the connection is established and the higher the power consumption.
GATT
A GATT Profile (or Generic Attribute Profile) defines the exchange model between devices connected with BLE. This GATT profile governs the connection and allows the devices to discover, read, write and push data. The data being pushed is encapsulated in a service which consists of one or more characteristics. There are a number of predefined GATT profiles and characteristics by the Bluetooth SIG. In the case of nuimo we have created a custom profile for nuimo.
The input for the four sensors in nuimo are evaluated by a microcontroller which detects the type of gesture or input performed by the user (a turn left of the aluminum ring or swipe movement on the top surface for example).
The input gesture is converted into a GATT-based characteristic (to optimize the communication for low throughput)and is then transferred by BLE radio. In the reverse, the central device can send writable bits that controls the LED matrix display as an output.
Examples
For those who receive a developer edition of nuimo through our kickstarter campaign, we will also open access to our github repo that includes two example applications — one for native OSX and a Ruby app. Below are some examples of how applications and integrations are built and show the ease of mapping nuimo inputs to shortcuts, API calls and AppleScript.
1. Keyboard Shortcuts
It is very simple to map keyboard shortcuts to one of nuimo’s inputs. Mac and Adobe Photoshop support a number of keyboard shortcuts already. With the simple code below you can undo an action in Photoshop using nuimo’s capacitive touch surface, just one of many examples.
SWIPE_LEFT: {
tell application "System Events" to tell process "Adobe Photohop"
keystroke "z" using {option down, command down}
end tell
break;
}
2. API Calls
API’s are UX for developers and most of the smart devices give you plenty of them. Here are two examples with Sonos and LIFX using their APIs. In the first example when the click button is pressed and the music will play or pause on your Sonos. This is done by implementing Nathan Borror’s Sonos controller.
case BUTTON_PRESS: {
if (self.isPlaying) {
[controller pause:^(NSDictionary *response, NSError *error) {
NSLog(@"paused");
}];
} else {
[controller play:nil completion:^(NSDictionary *response, NSError *error) {
NSLog(@"Playing");
}];
}
self.isPlaying = !self.isPlaying;
break;
}
In the second example when the click button is pressed the light of LIFX switches on or off. This is done by using the LIFXKit, the LIFX SDK for iOS and OSX.
case BUTTON_PRESS: {
if (light.powerState == LFXPowerStateOn) {
[localNetworkContext.allLightsCollection setPowerState:LFXPowerStateOff];
} else {
[localNetworkContext.allLightsCollection setPowerState:LFXPowerStateOn];
}
break;
}
3. AppleScript
Apple’s Scripting Bridge gives us easy control and communication with scriptable applications. Objective-C messages can be sent to any application with a scripting interface. These range from Spotify, iTunes to Chrome.
Below are two examples of how to map one of nuimo’s gestures to an action within an application.
- Here we map the gesture sensors to Keynote. This gives you the possibility to skip through your presentation with left/right fly over swipes above nuimo.
case FLY_RIGHT:
[keynote showNext];
break;
case FLY_LEFT: {
[keynote showPrevious];
break;
}
2. Precisely changing the volume on the nuimo ring maps to raising or lowering the volume of your music through Spotify.
case TURN_LEFT: {
spotify.soundVolume = MAX(0, spotify.soundVolume - 1);
break;
}
case TURN_RIGHT: {
spotify.soundVolume = MIN(100, spotify.soundVolume + 1);
break;
}
Conclusion
In order to grow our community of developers interested in the nuimo, we will open the access to our git repo and provide anyone with two sample applications; one native OSX app and a ruby application to start development. We will continue to add further examples, support and operating systems over the next months.
To read more on the hardware development of nuimo see our blog post “How we built the nuimo.” If you would like to develop for the nuimo controller, you check out our kickstarter campaign and share it with your friends — limited edition developer kits are available.
You can always find us to ask questions or share great ideas at hi@senic.com.