At the Hackster Hardware Meetup Seattle, we had a bunch of BLE Bot 9000 robots. The problem was that all of the bots exposed the same services and names, so you can't choose the robot you want to control. The solution to controlling your bot is to give it a unique name, so that when you scan for devices you only connect to your device. This tutorial covers how to change the name of your BLE Bot 9000, and how to to connect to a bot by name.The first thing we need to do is install the Firmata library:
Step 1. Start up your Arduino IDE. If you need to install the IDE, you can find the download here: Arduino IDE.
Step 2. From the menu choose "Sketch, Include Library, Manage Libraries".
Step 3. Type in firmata in the filter your search box.
Step 4. Choose "Firmata Built-In by Firmata Developers" and click the Install button.Next we need to change the name the bot will be broadcasting:
Step 1. Navigate to the folder where the StandardFirmataBLE example is stored. On my computer it is at "C:\Program Files (x86)\Arduino\libraries\Firmata\examples\StandardFirmataBLE"
Step 2. Open the bleConfig.h file in a text editor, such as Notepad++. You can install Notepad++ from https://notepad-plus-plus.org/download/v7.3.1.html
Step 3. Change the FIRMATA_BLE_LOCAL_NAME value from "FIRMATA" to the name you want to use (on my computer this was line 27). NOTE: The new name must be 8 characters or less. In this example I use "MYBOT".
#define FIRMATA_BLE_LOCAL_NAME "MYBOT"
Step 4. Save your updated bleConfig.h file. (Make sure you overwrite the existing file. Windows will try to save in a different folder if you aren't running as Admin, since the file is in the "c:\program files (x86)" folder.)Now we need to install FirmataBLE onto our Arduino 101 board:
Step 1. Start up your Arduino IDE.
Step 2. Connect your Arduino 101 to your computer's USB port.
Step 3. From your Arduino IDE menu choose "Tools, Board, Arduino/Genuino 101". (NOTE: If you do not see your Arduino 101 board, then choose "Tools, Board, Board Manager", search for "Intel Curie Boards" and install it.)
Step 4. From your Arduino IDE menu choose "Tools, Port, and the serial port with the Arduino 101".
Step 5. From your Arduino IDE menu choose "File, Examples, Firmata, StandardFirmataBLE".
Step 6. From your Arduino IDE menu choose "Sketch, Upload" to upload the FirmataBLE software into your Arduino.Install software on your phone to scan for the Arduino (optional):
Step 1. Install "nRF Connect for Mobile" on your phone.
Step 2. Start "nRF Connect" and go to the scanner tab.
Step 3. Click "Scan".
You should see your Arduino 101 broadcasting the name you gave it earlier! If you see "FIRMATA" instead, then you need to confirm that the bleConfig.h file contains your changed name.Follow the directions to get Node.js communication to your bot
Step 1. Follow the directions at https://www.hackster.io/29284/ble-bot-9000-c150b8
- Load Arduino Sketch -- you can skip since you already did it above.
- Load Firmata Client -- you need to do these steps so your computer can connect to your bot. If you are running Windows, see the comments section because Phillip Horn has some useful tips.
- Run the code -- this will help make sure it works (but you will connect to the first bot found)
Step 1. If you followed the directions on the ble-bot-9000 you should have a file named "node_modules\ble-serial\index.js". You need to replace it with the file from https://raw.githubusercontent.com/pvanallen/ble-serial/f7ade7ad533d20b3434c6c4fc984d6b764a1661d/index.js
Step 2. You should also have a "control.js" file. You need to replace it with the file from https://raw.githubusercontent.com/jamisonderek/Firmata-BLE-Bot/master/control.js
Step 3. Edit your "control.js" file and replace
'} (or whatever you named your bot).
Step 4. Run the program. NOTE: You can turn on DEBUG to see devices it finds.
set DEBUG=ble-serial node control.js
You should now only connect to bots matching your name. The updated control.js file also makes Z and X keys control the speed of the bot.
Changing the name of your bot from FIRMATA to MYBOTArduino
#define FIRMATA_BLE_LOCAL_NAME "MYBOT"