Spring 2016 Pathfinder: Bluetooth Communication with the Arxterra App
By: Xiong Lee (Systems Engineer)
Table of Contents
Introduction to Arxterra App:
We first had to download the Arxterra App by emailing Jeff Gomes to give us the invitation to download Arxterra. The app has two modes we can access. The first one is remote control and the other is community. The remote control mode allows us to control the movement of the pathfinder from the Arxterra app on your phone. The community mode allows us to control the pathfinder through the control panel online found here. For our purpose, we wanted to be able to communicate with app via bluetooth so we used the remote control mode to show Bluetooth connection. To learn more about the features of the app, the video is shown here.
Code:
The code that was used to test the Bluetooth connection to the Arxterra app is found here. This code was the latest code we could find that was used for this pathfinder. There was trouble having the code work. The first problem we came up with was not having all the library files so the code could not compile. The files that we needed in the library was found on GitHub and was implemented into our Arduino IDE library. The libraries on GitHub can be found here. To add libraries to the arduino, you can go here.
Debugging the code:
if (cmd == MOVE) {
/***********************************
* motion command = 0x01
* motordata[3] left run (FORWARD = index 1, BACKWARD = index 2, BRAKE = index 3, RELEASE = index 4)
* motordata[4] left speed 0 – 255
* motordata[5] right run (FORWARD, BACKWARD, BRAKE, RELEASE)
* motordata[6] right speed 0 – 255
* example
* forward half speed 0x01, 0x01, 0x80, 0x01, 0x80 0101800180
***********************************/
/*
WARNING
WARNING ONLY THE TB6612FNG HAS BEEN UPDATED WITH NEW INDEX ADDRESSES
WARNING Typically all you need to do is add 2 to the index (1 -> 3, 2 -> 4, etc.)
*/
// Pololu VNH5019 motorshield (Pathfinder)
// move_VNH5019(data);
//collisionDetection = (data[1] == 1) || (data[2] == 1); // set to true if any motor is moving forward
}
After finding all the libraries that we needed, we uploaded the code to the microcontroller. When testing the code, it did not move at all. From the picture above, we can see that the app is sending command packets to the arduino, but it is still not moving. So in conclusion, we knew that the code was not decoding the commands correctly and had to run over the code and debug it.
While running through the code, we found out that the move command was not being called in the command tab. When going to the move command, there was no command there to tell the pathfinder what to do because we have the pololu VNH 5019 motor shield on the pathfinder. The move routine was commented out and not calling the pathfinder to move. So after uncommenting this command (the code highlighted in red above), we also needed to uncomment the move subroutine on the first tab (arxrobot firmware).
//void move_VNH5019(uint8_t * motordata)
//{
// int m1Speed = dirArray[motordata[1]] * motordata[2]; // left motor
// int m2Speed = dirArray[motordata[3]] * motordata[4]; // right motor
// md.setSpeeds(m1Speed, m2Speed);
//}
Another problem with the code was in the move_VNH5019 routine. The motordata[ ] should be in the order of 3,4,5,6. So instead of the code you see up there, it should be
int m1Speed = dirArray[motordata[3]] * motordata[4]; // left motor
int m2Speed = dirArray[motordata[5]] * motordata[6]; // right motor
md.setSpeeds(m1Speed, m2Speed);
Bluetooth connection on Arduino board:
Their Bluetooth chip (HC-06) was connected on the previous pathfinder’s custom PCB. In the code, the ports that the Bluetooth chip is reading on the Arduino board was the serial port 2. This means that the Bluetooth chip need to be connected to the RX2 and TX2. Since the chip was on the PCB, we couldn’t tell if it was connected to the right port and so we decided to disconnect the PCB and jump wire the Bluetooth to the ports using a breadboard instead.
Conclusion:
Another error came into factor when we still couldn’t get it to work. The other error was that the batteries were low and couldn’t run the motors. So we charged the batteries and after doing all the debugging and rewiring, we finally got the arxterra app to work via bluetooth. We made the pathfinder move using the remote control mode. The things we learned were to not expect the codes to work right away. We had to learn how the commands were transferred through the app and how it was decoded. We had to assume the bluetooth chip was not connected to the RX2 and TX2 pin because we couldn’t tell if their custom PCB was working properly. In the end, we were able to get the Bluetooth connection to work with the Arxterra App.
Source Materials:
http://arxterra.com/control-panel/
https://www.youtube.com/channel/UCJXZGMpv8GqxkOi6W02GzoQ
http://arxterra.com/pathfinder-axterra-gps-communication-part-three/