I'm an Arduino newbasauras

I need some help. I have most of my sub built and I am trying to get the arduinos to talk to each other but I’m not having much luck. I just got a tether interface board which is freaking awesome!! I am using some code I found on the blue robotics site and I know the code works because I used it to test my last version of my sub with three thrusters. It worked perfectly and I didn’t even have to change anything.

I’m completely new to this so I don’t even know were to start. Should both ardunios have the same code? I would think each one would have to be a little different.

Here is the code I’m using:

/* Blue Robotics Example Code

Title: Analog Joystick Control Example (Arduino)
Description: This code is an example of how to use the Blue Robotics thrusters
and ESCs to control a simple underwater vehicle. The code is designed to use
analog joysticks (Gimbal Joystick - Parallax) and three thrusters.
The thrusters are oriented with two pointing forward, one on the left and one
on the right side of the vehicle, as well as a vertical thruster.
The code is designed for the Arduino Uno board and can be compiled and
uploaded via the Arduino 1.0+ software.

The MIT License (MIT)
Copyright (c) 2014 Blue Robotics Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-------------------------------*/

#include <Servo.h>

// Joystick Settings
static const int JS_CENTER_0 = 511; // Analog reading at center, 0-1023
static const int JS_CENTER_1 = 511;
static const int JS_CENTER_2 = 511;
static const int JS_RANGE_0 = 128; // Analog range, 0-1023
static const int JS_RANGE_1 = 128; // Set to 128 for Parallax joystick
static const int JS_RANGE_2 = 128;
static const int JS_DIR_0 = 1; // +1 or -1
static const int JS_DIR_1 = 1;
static const int JS_DIR_2 = 1;

// ESC/Thruster Settings
static const int MAX_FWD_REV_THROTTLE = 400; // Value between 0-400
static const int MAX_TURN_THROTTLE = 400; // Value between 0-400
static const int MAX_VERTICAL_THROTTLE = 400; // Value between 0-400
static const int CENTER_THROTTLE = 1500;

// Arduino Pins
static const byte JS_ADC_0 = A0;
static const byte JS_ADC_1 = A1;
static const byte JS_ADC_2 = A2;
static const byte THRUSTER_LEFT = 9;
static const byte THRUSTER_RIGHT = 10;
static const byte THRUSTER_VERTICAL = 11;

// Servos
Servo thrusterLeft;
Servo thrusterRight;
Servo thrusterVertical;

void setup() {
// Set up serial port to print inputs and outputs
Serial.begin(38400);

// Set up Arduino pins to send servo signals to ESCs
thrusterLeft.attach(THRUSTER_LEFT);
thrusterRight.attach(THRUSTER_RIGHT);
thrusterVertical.attach(THRUSTER_VERTICAL);

// Set output signal to 1500 microsecond pulse (stopped command)
thrusterLeft.writeMicroseconds(CENTER_THROTTLE);
thrusterRight.writeMicroseconds(CENTER_THROTTLE);
thrusterVertical.writeMicroseconds(CENTER_THROTTLE);

// Delay to allow time for ESCs to initialize
delay(1000);
}

void loop() {
// Read the joysticks and use the Arduino “map” function to map the raw values
// to the desired output commands.
int forwardCommand = map(analogRead(JS_ADC_0), // Read raw joystick value
JS_CENTER_0-JS_DIR_0JS_RANGE_0, // Joystick low value
JS_CENTER_0+JS_DIR_0
JS_RANGE_0, // Joystick high value
-MAX_FWD_REV_THROTTLE, // Command low value
MAX_FWD_REV_THROTTLE); // Command high value
int turnCommand = map(analogRead(JS_ADC_1), // Read raw joystick value
JS_CENTER_1-JS_DIR_1JS_RANGE_1, // Joystick low value
JS_CENTER_1+JS_DIR_1
JS_RANGE_1, // Joystick high value
-MAX_TURN_THROTTLE, // Command low value
MAX_TURN_THROTTLE); // Command high value
int verticalCommand = map(analogRead(JS_ADC_2), // Read raw joystick value
JS_CENTER_2-JS_DIR_2JS_RANGE_2, // Joystick low value
JS_CENTER_2+JS_DIR_2
JS_RANGE_2, // Joystick high value
-MAX_VERTICAL_THROTTLE, // Command low value
MAX_VERTICAL_THROTTLE); // Command high value

// Combine the “stopped” command with forward, turn, and vertical and send
// to the ESCs.
thrusterLeft.writeMicroseconds(CENTER_THROTTLE+forwardCommand+turnCommand);
thrusterRight.writeMicroseconds(CENTER_THROTTLE+forwardCommand-turnCommand);
thrusterVertical.writeMicroseconds(CENTER_THROTTLE+verticalCommand);

// Output via serial
Serial.print("Fwd: "); Serial.print(forwardCommand);
Serial.print("Turn: "); Serial.print(turnCommand);
Serial.print(“Vert: “); Serial.print(verticalCommand);
Serial.println(””);

// Delay 1/10th of a second. No need to update at super fast rates.
delay(100);
}

The above code is not for serial communication between two Arduinos, it is strictly one Arduino doing an analog read of the joystick potentiometer values through the tether, and then mapping that to ESC control values.

Hi,

We were going through your code and noticed an MIT license in there. We are nearly finished on our BlueROV over at Sea Grant, and if you are working on campus we would be interested in hearing about your experience with BlueROV.

Best,

Alicia

Hi Alicia,

Like Richard mentioned, this code is only for use on a single Arduino, running on the topside and connected to the thrusters through a tether cable. Please search for “arduino serial communication” to learn more about how serial communication works and how you can talk between two devices. This code can be adapted for use with that, but it would require some changes.

The MIT License is generic open-source software license that we like to use because it provide a lot of flexibility for our end-users and makes it very clear what they can do with our software. We’re based on southern California but we’d love to meet you next time we’re on that coast! :slight_smile:

-Rusty

Hi Rusty,

That’s really cool, we didn’t know about that license! We just assumed someone else on campus got a bluerov and were curious :slight_smile: And as for Arduino we’re waiting to test the pixhawk-ras pi setup we have, and will post some photos in the build forum soon.