Bluefruit-LE-Shield-HIDKeyboard
Le croquis HIDKeyboard
The HIDKeyboard example shows you how you can use the built-in HID keyboard AT commands to send keyboard data to any BLE-enabled Android or iOS phone, or other device that supports BLE HID peripherals.
Ouvrir le croquis
To open the ATCommand sketch, click on the File > Examples > Adafruit_BluefruitLE_nRF51 folder in the Arduino IDE and select hidkeyboard:
Crédit: AdaFruit Industries www.adafruit.com
This will open up a new instance of the example in the IDE, as shown below:
Crédit: AdaFruit Industries www.adafruit.com
Configuration
Check the Configuration! page earlier to set up the sketch for Software/Hardware UART or Software/Hardware SPI. The default is hardware SPI
If using software or hardware Serial UART:
- This tutorial does not need to use the MODE pin, make sure you have the mode switch in CMD mode if you do not configure & connect a MODE pin
- Don't forget to also connect the CTS pin on the Bluefruit to ground if you are not using it! (The Flora has this already done)
Exécuter le croquis
Once you upload the sketch to your board (via the arrow-shaped upload icon), and the upload process has finished, open up the Serial Monitor via Tools > Serial Monitor, and make sure that the baud rate in the lower right-hand corner is set to 115200:
Crédit: AdaFruit Industries www.adafruit.com
Streamer les données de senseur
You can take Quaternion (absolute orientation), Accelerometer, Gyroscope, Magnetometer or GPS Location data from your phone and send it directly to your Arduino from the Controller activity.
By enabling the Accelerometer field, for example, you should see accelerometer data update in the app:
Crédit: AdaFruit Industries www.adafruit.com
The data is parsed in the example sketch and output to the Serial Monitor as follows:
Accel 0.20 -0.51 -0.76 Accel 0.22 -0.50 -0.83 Accel 0.25 -0.51 -0.83 Accel 0.21 -0.47 -0.76 Accel 0.27 -0.48 -0.82
{{{2}}}
Crédit: AdaFruit Industries www.adafruit.com
Note that even though we only print 2 decimal points, the values are received from the App as a full 4-byte floating point.
Le pavé de commande
You can also use the Control Pad Module to capture button presses and releases by selecting the appropriate menu item:
{{{2}}}
Crédit: AdaFruit Industries www.adafruit.com
This will bring up the Control Pad panel, shown below:
Crédit: AdaFruit Industries www.adafruit.com
Button presses and releases will all be logged to the Serial Monitor with the ID of the button used:
Button 8 pressed Button 8 released Button 3 pressed Button 3 released
Sélection de couleur
You can also send RGB color data via the Color Picker module, which presents the following color selection dialogue:
{{{2}}}
Crédit: AdaFruit Industries www.adafruit.com
This will give you Hexadecimal color data in the following format:
RGB #A42FFF
{{#Widget:Iframe |url=https://youtu.be/Kym6crZF1Pg |width=560 |height=315 |border=0 }}
You can combine the color picker and controller sample sketches to make color-configurable animations triggered by buttons in the mobile app-- very handy for wearables! Download this combined sample code (configured for Feather but easy to adapt to FLORA, BLE Micro, etc.) to get started:
Configuration
Check the Configuration! page earlier to set up the sketch for Software/Hardware UART or Software/Hardware SPI. The default is hardware SPI
If using software or hardware Serial UART:
- This tutorial does not need to use the MODE pin, make sure you have the mode switch in CMD mode if you do not configure & connect a MODE pin
- Don't forget to also connect the CTS pin on the Bluefruit to ground if you are not using it! (The Flora has this already done)
Exécuter le croquis
Once you upload the sketch to your board (via the arrow-shaped upload icon), and the upload process has finished, open up the Serial Monitor via Tools > Serial Monitor, and make sure that the baud rate in the lower right-hand corner is set to 115200:
Crédit: AdaFruit Industries www.adafruit.com
To send keyboard data, type anything into the textbox at the top of the Serial Monitor and click the Send button.
Lier le clavier HID
Before you can use the HID keyboard, you will need to 'bond' it to your phone or PC. The bonding process establishes a permanent connection between the two devices, meaning that as soon as your phone or PC sees the Bluefruit LE module again it will automatically connect.
The exact procedures for bonding the keyboard will varying from one platform to another.
When you no longer need a bond, or wish to bond the Bluefruit LE module to another device, be sure to delete the bonding information on the phone or PC, otherwise you may not be able to connect on a new device! |
Android
To bond the keyboard on a Bluetooth Low Energy enabled Android device, go to the Settings application and click the Bluetooth icon.
These screenshots are based on Android 5.0 running on a Nexus 7 2013. The exact appearance may vary depending on your device and OS version. |
Crédit: AdaFruit Industries www.adafruit.com
Inside the Bluetooth setting panel you should see the Bluefruit LE module advertising itself as Bluefruit Keyboard under the 'Available devices' list:
Crédit: AdaFruit Industries www.adafruit.com
Tapping the device will start the bonding process, which should end with the Bluefruit Keyboard device being moved to a new 'Paired devices' list with 'Connected' written underneath the device name:
Crédit: AdaFruit Industries www.adafruit.com
To delete the bonding information, click the gear icon to the right of the device name and the click the Forget button:
Crédit: AdaFruit Industries www.adafruit.com
iOS
To bond the keyboard on an iOS device, go to the Settings application on your phone, and click the Bluetooth menu item.
The keyboard should appear under the OTHER DEVICES list:
Crédit: AdaFruit Industries www.adafruit.com
Once the bonding process is complete the device will be moved to the MY DEVICES category, and you can start to use the Bluefruit LE module as a keyboard:
Crédit: AdaFruit Industries www.adafruit.com
To unbond the device, click the 'info' icon and then select the Forget this Device option in the menu:
Crédit: AdaFruit Industries www.adafruit.com
OS X
To bond the keyboard on an OS X device, go to the Bluetooth Preferences window and click the Pair button beside the Bluefruit Keyboard device generated by this example sketch:
Crédit: AdaFruit Industries www.adafruit.com
To unbond the device once it has been paired, click the small 'x' icon beside Bluefruit Keyboard:
Crédit: AdaFruit Industries www.adafruit.com
... and then click the Remove button when the confirmation dialogue box pops up:
Crédit: AdaFruit Industries www.adafruit.com
Basé sur "Bluefruit LE Shield" d'Adafruit Industries, écrit par
Kevin Townsend - Traduit en Français par shop.mchobby.be CC-BY-SA pour la traduction
Toute copie doit contenir ce crédit, lien vers cette page et la section "crédit de traduction".
Based on "Bluefruit LE Shield" from Adafruit Industries, written by
Kevin Townsend - Translated to French by shop.mchobby.be CC-BY-SA for the translation
Copies must includes this credit, link to this page and the section "crédit de traduction" (translation credit).
Traduit avec l'autorisation d'AdaFruit Industries - Translated with the permission from Adafruit Industries - www.adafruit.com