Control VESC with Arduino

Support for creating custom user applications on the VESC.
Posts: 1
Joined: 03 Feb 2018, 14:09
Location: CH

Control VESC with Arduino

Postby Far3ll » 03 Feb 2018, 14:17

Hey, got some trouble with the Serial connection i think. Hope someone can help me.

I want to control the VESC over UART withe Arduino. Control works with the Nunchuck function, but i can't get the values from the VESC using this Code:

Code: Select all

 Name:    Board.ino
 Created: 19.01.2018 10:02:38
 Author:  dschi
#include "Config.h"
#include <VescUart.h>
#include <datatypes.h>
#include "local_datatypes.h"
#include "U8glib.h"

#include <SPI.h>

U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_NO_ACK|U8G_I2C_OPT_FAST);  // Fast I2C / TWI

struct remotePackage remPack;
struct bldcMeasure values;

const int xAxis = 17;
const int yAxis = 16;
const int buttonR = 3;
const int buttonL = 2;

int xBuf = 0;
int xVal = 0;
int yBuf = 0;
int yVal = 0;
int buttonRState = 0;
int buttonLState = 0;

float voltage = 0.0;

void setup() {


    remPack.valXJoy     = 127; //middle Position
    remPack.valYJoy     = 127;
    remPack.valLowerButton  = 0;
    remPack.valLowerButton  = 0;

void draw(void) {
  u8g.setPrintPos(0, 20);

void loop() {

while (SERIALIO.available()){

 if(VescUartGetValue(values, 0)){
voltage = 404;

        yBuf = analogRead(yAxis);
    //yVal = map(yBuf, 0, 1023, 0, 255);

    remPack.valYJoy = map(yBuf, 0, 1023, 0, 255);

    VescUartSetNunchukValues( remPack, 0);
  do {
  } while( u8g.nextPage() );


When i add the line : VescUartGetValue(values, 0), the Nunchuk control also doesn't work anymore. I've set the Baudrate of the VESC to 9600. I've also set this Config.h:

Code: Select all

Copyright 2015 - 2017 Andreas Chaitidis
This program is free software : you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program.If not, see <>.

//The Config.h is a file, that I use in other programs usualy. So I define also the serial ports there. If you don't want to
//use it, just comment the include statement in the VescUart.h out.

//#include "Arduino.h"

#ifndef _CONFIG_h
#define _CONFIG_h

#define SERIALIO Serial
//#define DEBUGSERIAL Serial


#define TIMEOUTMAX  500

Did i've to modify the "VescUART.h" ? Thank's for any help

I use the VESC HW Vers. 4.12 with the latest SW, MCU is the Arduino Mini Pro

Posts: 2
Joined: 14 May 2018, 01:54

Re: Control VESC with Arduino

Postby ZFreaky » 14 May 2018, 02:04

I'm using a mega, have yet to get to using a nano cause I'm working on another UART issue. I get away with " VescUartGetValue(VescMeasuredValues);" as the call line for the data, basically lifted from the example, maybe try that?

Return to “Custom Applications”

Who is online

Users browsing this forum: No registered users and 1 guest