This section shows you how to use the Sphero 2 JS APIs to connect and interact with it.
For more information refer to: https://github.com/orbotix
Install NodeJS
This section assumes that you are using the Xubuntu development environment that was built in this document. If using other environment, you will have to adapt the commands/paths accordingly.
- Run the following commands:
sudo apt-get install curl -y
sudo curl -sL https://deb.nodesource.com/setup_4.x |
sudo -E bash –
sudo
apt-get
install -y nodejs
Note: for Enterprise Linux and Fedora Linux distributions (OEL, RH, etc.)
sudo su –
curl –silent –location https://rpm.nodesource.com/setup_4.x |
bash –
sudo yum -y install nodejs
- Confirm Node is installed by typing node –version
For more information refer to https://nodejs.org/en/download/package-manager/
Installation for Sphero 1.0/2.0 & SPRK
The Sphero 1.0/2.0 and the SPRK use a Bluetooth Classic interface, also known as “Bluetooth 2.0/3.0”.
Run the following command:
# Create a folder where you want to download the NPM nodules
mkdir robot && cd robot
npm install sphero serialport
Connect to Sphero.js
On Linux (Ubuntu) to connect to your Sphero 1.0/2.0 or SPRK, you first need to pair it. To make things easy:
- Install Blueman Bluetooth Manager. In Ubuntu this is pretty easy, just open the Ubuntu Software Centre, type the program name and install it from there.
- When the installation is complete, open the program and search for devices. Make sure the Sphero is flashing its color code. Once the Sphero appears in the list of devices, select it, click on setup and follow the instructions.
Note: If Bluetooth is disabled follow the next steps:
sudo apt-get install gksu -y gksudo gedit /etc/rc.local The rc.local fill will open up, although it might ask you to enter the root’s password. Add the following line before the exit 0: rfkill unblock bluetooth Now enter the following line in a terminal: sudo reboot Or simply restart the Bluetooth service: sudo /etc/init.d/bluetooth restart |
- You can connect and disconnect the Sphero from a serialport interface by right clicking on it inside the Blueman list of devices and selecting RN-SPP or disconnect, respectively (after it has been setup and added permanently to the list). Make sure to notice the serialport address Blueman displays after the Sphero connects, as this will be the one used in your code. The serialport address displayed for the Sphero should look something like this:
/dev/rfcomm0
-
You need to add a udev rule in order to properly set permissions for your program to be able to access the Bluetooth interface. For example:
sudo vi /etc/udev/rules.d/55-rfcomm.rules
Then enter the following line:
KERNEL==”rfcomm[0-9]*”, NAME=”%k”, GROUP=”citurria”
à Modify “citurria” by your group name id
The udev rule above will allow any user who is a member of the “citurria” group to access any port that is added by connecting by running the rfcomm command.
Installation for Parrot Mini-drone
The Parrot mini-drone main documentation can be found at https://github.com/voodootikigod/node-rolling-spider
I followed the next command to set it up:
- Create a project directory by running the following command:
# Create a folder where you want to download the Rolling-spider NPM nodules
mkdir s2v-iia-nodejs-parrot-apis && cd s2v-iia-nodejs-parrot-apis
- Install pre-requites (Bluetooth
Noble pre-requites as https://github.com/sandeepmistry/noble#prerequisites ):
sudo apt-get install bluetooth bluez libbluetooth-dev libudev-dev build-essential g++
- Install the Rolling-Spider node module
npm install rolling-spider
If this completes successfully, continue with the supporting modules below:
npm install temporal express
At the end of this step, you should have 3 modules installed:
Note: If you find any missing libraries while installing the previous modules, then go to number 4. Otherwise jump to number 5.
- I don’t think the following is required, but I had to do it as part of debugging the previous error. Please try not to run these commands and go directly to (3) – If you see any trouble, then come back and install these modules.
sudo npm install -g node-gyp
sudo apt-get install nodejs-legacy
sudo apt-get install bluez-hcidump
sudo hcidump -t -x
- As indicated in bug https://github.com/voodootikigod/node-rolling-spider/issues/74 – If you get an error with your peripheral, go into lib/drone.js and add this line to 202
this.ble.stopScanning();
under
this.peripheral = peripheral;
Installation for AR Drone 2 Parrot Mini-drone
The AR Drone 2 Parrot mini-drone main documentation can be found at
https://github.com/felixge/node-ar-drone
I followed the next command to set it up:
- Create a project directory by running the following command:
# Create a folder where you want to download the Rolling-spider NPM nodules
mkdir s2v-iia-nodejs-ardrone2-apis && cd s2v-iia-nodejs-ardrone2-apis
- Install pre-requites (Bluetooth
Noble pre-requites as https://github.com/sandeepmistry/noble#prerequisites ):
sudo apt-get install bluetooth bluez libbluetooth-dev libudev-dev build-essential g++
- Install the Rolling-Spider node module
npm install ar-drone
If this completes successfully, continue with the supporting modules below:
npm install temporal express http
At the end of this step, you should have 3 modules installed (i.e. ar-drone, express, temporal) – Make a ls -l node-modules, to confirm…
That’s it, congratulations, you can start using the examples provided within the ar-drone module.
Note: If you find any missing libraries while installing the previous modules:
I don’t think the following is required, but I had to do it as part of debugging the previous error. Please try not to run these commands and go directly to (3) – If you see any trouble, then come back and install these modules.
sudo npm install -g node-gyp
sudo apt-get install nodejs-legacy
sudo apt-get install bluez-hcidump
sudo hcidump -t -x