Hi there!
I am using the following code with an Arduino MEGA2560 to send a string to a driver in order yo rotate a motor. I connect via UART with RX1 and TX1 (also GND and 5V pin connected) of the Arduino MEGA.
This is working fine.
#include <VescUart.h>
/** Initiate VescUart class */
VescUart UART;
//float current = 3.0; /** The current in amps */
float rpm = 0.00;
String dir;
String vel;
float dir_vel;
void setup() {
Serial.begin(9600);
/** Setup UART port (Serial1 on Atmega32u4) */
Serial.begin(115200);
while (!Serial1) {;}
/** Define which ports to use as UART */
UART.setSerialPort(Serial1);
}
void loop() {
if (Serial.available()>1.0)
{
String input = Serial.readStringUntil('\n'); //leer los datos hasta que se introduzca nueva linea
//Separar datos
char direction = input.charAt(1);
String velocity = input.substring(3);
dir = (direction == 's' ? "+" : "-");
vel = velocity;
dir_vel = (dir + vel).toFloat();
Serial.print(dir);
Serial.println(vel);
Serial.println(dir_vel);
rpm = Serial.parseFloat();
}
else Serial.println("nothing to read");
delay(50);
UART.setRPM(dir_vel);
My problem comes when I try to use the same code with an Arduino DUE. When I upload it doesn't work and i receive the following error message:
(I connect the Arduino DUE the same way as the MEGA2560, RX1, TX1, GND, 5V)
In file included from C:\Users\User\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\system/CMSIS/Device/ATMEL/sam3xa/include/sam3xa.h:44:0,
from C:\Users\User\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\system/CMSIS/Device/ATMEL/sam3.h:59,
from C:\Users\User\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\system/CMSIS/Device/ATMEL/sam.h:198,
from C:\Users\User\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\system/libsam/chip.h:25,
from C:\Users\User\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino/Arduino.h:42,
from C:\Users\User\AppData\Local\Temp\arduino\sketches\3DB61CEE1FE196AC7FEDFCA570022F68\sketch\sketch_VESC_UART_CONTROL_CON_S_W.ino.cpp:1:
C:\Users\User\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\system/CMSIS/Device/ATMEL/sam3xa/include/sam3x8e.h:489:29: error: expected ')' before '*' token
#define UART ((Uart *)0x400E0800U) /**< \brief (UART ) Base Address */
^
C:\Users\User\Documents\Arduino\sketch_VESC_UART_CONTROL_CON_S_W\sketch_VESC_UART_CONTROL_CON_S_W.ino:11:10: note: in expansion of macro 'UART'
VescUart UART;
^
C:\Users\User\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\system/CMSIS/Device/ATMEL/sam3xa/include/sam3x8e.h:489:29: error: expected ')' before '*' token
#define UART ((Uart *)0x400E0800U) /**< \brief (UART ) Base Address */
^
C:\Users\User\Documents\Arduino\sketch_VESC_UART_CONTROL_CON_S_W\sketch_VESC_UART_CONTROL_CON_S_W.ino:11:10: note: in expansion of macro 'UART'
VescUart UART;
^
C:\Users\User\Documents\Arduino\sketch_VESC_UART_CONTROL_CON_S_W\sketch_VESC_UART_CONTROL_CON_S_W.ino: In function 'void setup()':
C:\Users\User\Documents\Arduino\sketch_VESC_UART_CONTROL_CON_S_W\sketch_VESC_UART_CONTROL_CON_S_W.ino:27:8: error: request for member 'setSerialPort' in '1074661376u', which is of pointer type 'Uart*' (maybe you meant to use '->' ?)
UART.setSerialPort(Serial1);
^
C:\Users\User\Documents\Arduino\sketch_VESC_UART_CONTROL_CON_S_W\sketch_VESC_UART_CONTROL_CON_S_W.ino: In function 'void loop()':
C:\Users\User\Documents\Arduino\sketch_VESC_UART_CONTROL_CON_S_W\sketch_VESC_UART_CONTROL_CON_S_W.ino:59:8: error: request for member 'setRPM' in '1074661376u', which is of pointer type 'Uart*' (maybe you meant to use '->' ?)
UART.setRPM(dir_vel);
^
exit status 1
Compilation error: request for member 'setSerialPort' in '1074661376u', which is of pointer type 'Uart*' (maybe you meant to use '->' ?)
Any idea how can i solve this?
Thnaks in advance