Control Multiple VESCs with an Arduino

In this video I show you how to control multiple VESCs independently using an Arduino Uno.

VESC Homepage.

VescUart Repository.

The project shown in the video.

Sample Code:

#include <VescUart.h>
#include <SoftwareSerial.h>

/** Initiate vesc1Uart class */
VescUart vesc1;
VescUart vesc2;

/** Initiate SoftwareSerial class */
SoftwareSerial vesc1Serial(12, 13); //RX, TX

float current = -0.5; /** The current in amps */

int counter = 0;

void setup() 
{

  /** Setup Serial port to display data */
  Serial.begin(9600);

  /** Setup SoftwareSerial port */
  vesc1Serial.begin(19200);
  Serial1.begin(19200);

  /** Define which ports to use as UART */
  vesc1.setSerialPort(&vesc1Serial);
  vesc2.setSerialPort(&Serial1);
}

void loop() 
{

  /** Call the function getvesc1Values() to acquire data from vesc1 */
  if ( vesc1.getVescValues() ) 
  {
    Serial.println("VESC 1: ");
    Serial.println(vesc1.data.rpm);
    Serial.println(vesc1.data.inpVoltage);
    Serial.println(vesc1.data.ampHours);
    Serial.println(vesc1.data.tachometerAbs);

  }
  else
  {
    Serial.println("Failed to get data from VESC 1!");
  }

  if ( vesc2.getVescValues() ) 
  {
    Serial.println("VESC 2: ");
    Serial.println(vesc2.data.rpm);
    Serial.println(vesc2.data.inpVoltage);
    Serial.println(vesc2.data.ampHours);
    Serial.println(vesc2.data.tachometerAbs);

  }
  else
  {
    Serial.println("Failed to get data from VESC 2!");
  }

  if(counter < 20 * 10) 
  {
    vesc1.setCurrent(current);
    vesc2.setCurrent(current);
    counter++;
    Serial.print("Counter: ");
    Serial.println(counter);
  }
  else
  {
    vesc1.setCurrent(0);
    vesc2.setCurrent(0);
  }
  delay(50);
}