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!");
}
}
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!");
}
}
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.
So if you come up with anything, hit me please <3