Code working in MEGA not working in DUE

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 :slight_smile:

Hello comes04

Take a view here to gain the knowledge.

hth

Have a nice day and enjoy coding in C++.

1 Like

The DUE is 3V3 the Mega 5V. The Arduino DUE board is not compatible with other boards. The other key difference between Arduino due board and Arduino mega board is software compatibility. My recommendation is to use another board, the DUE is also on the obsolete list.

I need more processing speed for my project, which one will you recommend? ESP32 its compatible?
Thanks you all for the replies

Start by renaming the VescUart object. 'UART' appears to be a macro defined in the SAM core. Then update VescUart.h to define the available UART ports on the DUE. Note that 'Serial' likely not an object of the HardwareSerial class as it's probably a native USB port on the SAM (it is on SAMD anyway).

Then you have the voltage problem noted by @gilshultz. 5V will likely damage the SAM processor. In fact, just about any faster (or more modern) processor that you pick will be 3.3V. So you'll need to fix that regardless.

All things considered, you'll likely need to re-engineer the entire project if the Mega doesn't work for you. Why exactly do you think you need "more processing speed"?

1 Like

Serial (programming port) on Due is HardwareSerial(*), native USB is SerialUSB.

(*) To be exact, Serial is UARTClass which inherits from HardwareSerial.

Interesting, thanks. Guess I was thinking of the Teensy 3.x family:

extern usb_serial_class Serial;

And the inheritance is:

   Print
     ^
     |
   Stream
     ^
     |

usb_serial_class

As you said, I just change

VescUart UART;

for

VescUart UART2;

And it works.

Thanks you all for your help!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.