Uart and VESC motor controller

Nordlicht
Posts: 2
Joined: Sat Mar 24, 2018 8:42 pm

Uart and VESC motor controller

Postby Nordlicht » Mon Mar 26, 2018 5:06 pm

Hi,

I'm fairly new to the ESP32, but I do have a lot of experience with the Arduino.
I want to read the UART data from the motorcontroller "VESC". The Creator of it even has a library for it, so it should be easy-peasy, am I right?
Thing is it sends data with a baudrate of 115200, which is too fast for software serials. And only very few Arduinos have a second hardware UART, thats what got me to the ESP32.

So this is his original vanilla Arduinocode:

Code: Select all

/*
/*
  Name:		VescUartSample.ino
  Created:	9/26/2015 10:12:38 PM
  Author:	AC
*/

// the setup function runs once when you press reset or power the board
// To use VescUartControl stand alone you need to define a config.h file, that should contain the Serial or you have to comment the line
// #include Config.h out in VescUart.h

//Include libraries copied from VESC
#include "VescUart.h"
#include "datatypes.h"


#define DEBUG
unsigned long count;

void setup() {

  //Setup UART port
  Serial1.begin(115200);
#ifdef DEBUG
  //SEtup debug port
  Serial.begin(115200);
#endif
}

struct bldcMeasure measuredValues;

// the loop function runs over and over again until power down or reset
void loop() {
  //int len=0;
  //len = ReceiveUartMessage(message);
  //if (len > 0)
  //{
  //	len = PackSendPayload(message, len);
  //	len = 0;
  //}

  if (VescUartGetValue(measuredValues)) {
    Serial.print("Loop: "); Serial.println(count++);
    SerialPrint(measuredValues);
  }
  else
  {
    Serial.println("Failed to get data!");
  }

}
And this is the Code I modified to work with ESP32s UART:

Code: Select all

/*
  Name:    VescUartSample.ino
  Created: 9/26/2015 10:12:38 PM
  Author:  AC
*/

// the setup function runs once when you press reset or power the board
// To use VescUartControl stand alone you need to define a config.h file, that should contain the Serial or you have to comment the line
// #include Config.h out in VescUart.h

//Include libraries copied from VESC
#include "VescUart.h"
#include "datatypes.h"
#include <HardwareSerial.h>


HardwareSerial Serial1(1);

#define DEBUG
unsigned long count;

void setup() {

  //Setup UART port
  Serial1.begin(115200, SERIAL_8N1, 16, 17);
#ifdef DEBUG
  //SEtup debug port
  Serial.begin(115200);
#endif
}

struct bldcMeasure measuredValues;

// the loop function runs over and over again until power down or reset
void loop() {
  //int len=0;
  //len = ReceiveUartMessage(message);
  //if (len > 0)
  //{
  //  len = PackSendPayload(message, len);
  //  len = 0;
  //}

  if (VescUartGetValue(measuredValues)) {
    Serial.print("Loop: "); Serial.println(count++);
    SerialPrint(measuredValues);
  }
  else
  {
    Serial.println("Failed to get data!");
  }

}
As you can see, not much done and actually the error is in the VESC lib:

Code: Select all

\\hrzfs01.hrz.isc.fh-kiel.de\home_st$\selnvett\Arduino\libraries\VescUartControl-master\VescUart.cpp: In function 'int ReceiveUartMessage(uint8_t*)':

\\hrzfs01.hrz.isc.fh-kiel.de\home_st$\selnvett\Arduino\libraries\VescUartControl-master\VescUart.cpp:36:9: error: 'SERIALIO' was not declared in this scope

  while (SERIALIO.available()) {

         ^

\\hrzfs01.hrz.isc.fh-kiel.de\home_st$\selnvett\Arduino\libraries\VescUartControl-master\VescUart.cpp: In function 'int PackSendPayload(uint8_t*, int)':

\\hrzfs01.hrz.isc.fh-kiel.de\home_st$\selnvett\Arduino\libraries\VescUartControl-master\VescUart.cpp:139:21: warning: converting to non-pointer type 'uint8_t {aka unsigned char}' from NULL [-Wconversion-null]

  messageSend[count] = NULL;

                     ^

\\hrzfs01.hrz.isc.fh-kiel.de\home_st$\selnvett\Arduino\libraries\VescUartControl-master\VescUart.cpp:147:2: error: 'SERIALIO' was not declared in this scope

  SERIALIO.write(messageSend, count);

  ^

\\hrzfs01.hrz.isc.fh-kiel.de\home_st$\selnvett\Arduino\libraries\VescUartControl-master\VescUart.cpp: In function 'void SerialPrint(uint8_t*, int)':

\\hrzfs01.hrz.isc.fh-kiel.de\home_st$\selnvett\Arduino\libraries\VescUartControl-master\VescUart.cpp:253:3: error: 'DEBUGSERIAL' was not declared in this scope

   DEBUGSERIAL.print(data[i]);

   ^

\\hrzfs01.hrz.isc.fh-kiel.de\home_st$\selnvett\Arduino\libraries\VescUartControl-master\VescUart.cpp:256:2: error: 'DEBUGSERIAL' was not declared in this scope

  DEBUGSERIAL.println("");

  ^

\\hrzfs01.hrz.isc.fh-kiel.de\home_st$\selnvett\Arduino\libraries\VescUartControl-master\VescUart.cpp: In function 'void SerialPrint(const bldcMeasure&)':

\\hrzfs01.hrz.isc.fh-kiel.de\home_st$\selnvett\Arduino\libraries\VescUartControl-master\VescUart.cpp:261:2: error: 'DEBUGSERIAL' was not declared in this scope

  DEBUGSERIAL.print("avgMotorCurrent: "); DEBUGSERIAL.println(values.avgMotorCurrent);

  ^

exit status 1
Fehler beim Kompilieren für das Board ESP32 Dev Module.
But I just cant wrap my mind around it. I also have sadly no Arduino with a hardware serialport to test his vanilla code, but I assume its correct since the VESC is a very much used controller and the creator of it is really close to the community.

So if you come up with anything, hit me please <3

McEsp32
Posts: 1
Joined: Sat Jan 18, 2020 7:42 pm

Re: Uart and VESC motor controller

Postby McEsp32 » Sat Jan 18, 2020 7:58 pm

Hi Nordlicht,

I'm new to the ESP32 and the connecting process to the FSESC 4.12 brushless motor controller. I thought it would be possible by using the PWM library of the ESP32. Then I recognized that FSESC accepts PPM input instead of PWM. Did you really succeed connecting the ESP32 with the controller via UART? Well, I don't like to invent a new wheel. So can you please help me with some tips to go forward? We also can talk German.

Thanks in addvance!

squiggle
Posts: 3
Joined: Fri Oct 21, 2022 10:14 pm

Re: Uart and VESC motor controller

Postby squiggle » Fri Oct 21, 2022 10:16 pm

Hi McEsp32
The FSESC and VESC do not use PPM, they use PWM. It's just named wrong in their documents.

Who is online

Users browsing this forum: No registered users and 73 guests