-
1Install Apps
Ensure that the following Bluetooth apps are installed on your mobile phone. These apps will show you the raw data sent by Ameba and allow you to interact with the data.
The recommended application is nRF connect, and is available at the links below:
- Android : https://play.google.com/store/apps/details?id=no.nordicsemi.android.mcp
- iOS :https://apps.apple.com/us/app/nrf-connect/id1054362403
LightBlue is an alternative application that can also be used, but has less features:
-
2Code Edition
Open the example, “Files” -> “Examples” -> “AmebaBLE” -> “BLEBatteryService”
Upload the code and press the reset button on Ameba once the upload is finished.
-
3Connect Mobile Phone
On your mobile phone, open the Bluetooth app and scan for the Bluetooth signal broadcast by Ameba, it should appear as a device named “AMEBA_BLE_DEV”.
Connect to the Ameba Bluetooth device, and a list of available services should appear. Click on the battery service to expand it, and you can see the battery level data value. The arrows highlighted in the box on the right are used to read data and subscribe to notifications. Click on the single arrow to read the battery level value, and a 90% value will appear.
Click on the triple arrow to subscribe to updates on the battery level value, and the battery value will start updating by itself.
The serial monitor will show the sketch increasing the battery level every second. When you click on either of the arrows, the sketch running on the Ameba will be notified, and will print out the action taken.
-
4Code Reference
Code Reference
BLEService and BLECharacteristic classes are used to create and define the battery service to run on the Bluetooth device.
BLE.configAdvert()->setAdvType(GAP_ADTYPE_ADV_IND) is used to set the advertisement type to a general undirected advertisement that allows for connections.
setReadCallback() and setCCCDCallback() is used to register functions that will be called when the battery level data is read, or notification is enabled by the user.
BLE.configServer(1) is used to tell the Bluetooth stack that there will be one service running.
addService() registers the battery service to the Bluetooth stack.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.