This Instructable explains how to setup a four motor Robot-Rover with an Arduino 101, Adafruit Motor/Stepper/Servo Shield for Arduino v2 Kit - v2.3 and control it with the Blynk BLE (Bluetooth Low Energy) mobile phone app using the Joystick widget. The sketch included with this Instructable can be easily modified for a two motor Robot-Rover.
(this solution was inspired by Intel Arduino 101 BLE Blynk Tank posted on Electron Hacks Thanks!)
Step 1: Assembling Your Rover
Assemble your Rover chassis, motors and wheels as per the instructions in the package. You may need to solder wires to the motors before installation. Make sure to keep the polarity consistent with colored wires, preferably red and black so that you can identify them when connecting them to the motor controller board. After mounting the Arduino and Adafruit Motor-Servo Controller board to the chassis, wire the motors as per the diagram above.
Step 2: Blynk Joystick Mobile Phone App Setup
Install Blynk on your mobile phone device. The website has all of the instructions in the documents section. After installing the app on your phone Blynk will issue an Auth Token that will give your device a unique address. The token will be emailed to you.
Following the instructions on the Blynk website install a Joystick widget and a SliderL (long slider) on your screen. Setup the joystick parameters as per the photo above. Select Merge on the output switch and select V(0) as the virtual pin. This will set up two pins V(0) and V(1) for the communication the x and y position values. The slider switch will be used to set the motor speed. Set it to virtual pin 2 V(2).
Step 3: Arduino Sketch
You can find and download the Arduino sketch here.
Insert your Auth Token on line 39 of the sketch.
You also need to install the Blynk library as well as the Adafruit Motor/Stepper/Servo Shield library
in your Arduino folder. You may also need to install the CurieBLE library if this is the first time you are using the Arduino 101 controller (Arduino>Sketch>Include Library>Manage Libraries>CurieBLE)
The sketch follows a joystick controller method described by SparkFun here.
It assumes there are eight directions of travel for the joystick to designate. It translates the joystick movement into a Rover direction as follows. The Blynk joystick widget travels along an x and y axis that are 255 units in length, making the midpoints 128. The direction of the joystick movement can be determined by comparing the joystick x and y value to 128. If x is less than 128 (left relative to the center) it is assigned a value of -1. If it is greater than 128 (right relative to the center) it is assigned a value of +1. If equal to 128 (centered) it is assigned a value of 0. The same is done for the joystick y axis values. For example when x>218 and y>218 the x-direction is 1 and the y-direction is 1 making the joystick in the forward right area. The sketch takes the x and y direction combinations listed in the Fig. 2 Joystick Direction Table powers the appropriate motors to steer the Rover. Note that the Rover steers in the direction of the unpowered motors.
The SparkFun example employs another clever strategy. Apparently the SparkFun joystick does not always return to its exact center. To correct for this a "threshold" area around the center point is created. This comes in handy for the Blynk joystick as well. While the Blynk joystick always returns to the center (see the Auto-Return switch in the joystick set-up) the joystick creates thousands of x,y combinations. This can make the Rover motion erratic if the x,y values are compared to 128 to determine a direction. I found that creating a threshold area around the center of +/- 20 for the x and y values works well.
The sketch powers all four motors in the same direction for forward and in the opposite direction for reverse. For a left turn the left front and rear motors are unpowered (RELEASE). For a right turn the right front and rear motors are released. for a hard left turn the left side motors are run FORWARD and the right side motors are run BACKWARD. This causes the Rover to spin in circles. You can experiment with powering or un-powering particular motors to yield the optimal turning results.
The sketch powers all four motors in the same direction for forward and in the opposite direction for reverse. For a left turn the left front and rear motors are unpowered (RELEASE). For a right turn the right front and rear motors are released. for a hard left turn the left side motors are run FORWARD and the right side motors are run BACKWARD. This causes the Rover to pirouette or spin in circles. You can experiment with powering or un-powering particular motors to yield the optimal turning results.
Step 4: Powering the Robot-Rover
I elected to power the Arduino 101 and Rover motors with separate power supplies. I bought an Anker PowerCore+mini to power the Arduino. Apparently the Arduino does not draw enough power to keep the Anker turned on (it shuts off after about 10 seconds). This seems to be a problem with many USB power sources. To prevent it from shutting off I was ready to build a load circuit for it as described here. Since the Anker has only one USB port I got out an IOGEAR 4-Port USB 2.0 Hub that I had laying around since another USB port is required to plug in the load circuit. It turns out that the USB hub places a large enough load on the Anker battery to keep it on. I am currently powering the motors with 8 x 1.5 volt alkaline batteries. At some point I will invest in a LiPo battery to power the motors.
Step 5: *****ADDENDUM*****
The steering code has been updated to provide improved steering performance. The sketch can be found here. It requires the addition of two switches to the Blynk phone interface.
In the revision a pushbutton widget labelled Right Pirouette on virtual pin V3 and a pushbutton widget labelled Left Pirouette on virtual pin V1 are added. The SliderL (long slider) widget is on V4 and is labelled Motor Speed. The joystick widget is on virtual pin V0.
The revised code now performs the diagonal joystick position (soft) turns by reducing the turning side wheel speeds to 60% of the opposing side wheels. You may want to adjust this ratio for your particular chassis and tire setup. The hard right turns are performed by un-powering (RELEASE) the turning side wheels. The spin or pirouette maneuver is now performed with the pushbuttons. I am thinking about adding some ultrasonic sensors to send distance to object data to the Blynk interface and possibly override the joystick to automatically avoid objects. I'll post the code whenever I have it ready. Enjoy!