I have worked out the issues with the Arduino Mega 2560; however, due to an encounter with magic smoke, I was only able to test the modified code with an older 2x25A RoboClaw. Once I get my hands on a new RoboClaw, I will test the MEGA Pro Mini 3.3V (from Sparkfun).
I was able to get all of the hardware serial ports to operate properly and I tested pins 52/53 as a software serial port. Below is some code that I used to test the operation of these ports. Also, I did not check every command because my older RoboClaw does not support certain commands; I'll test those commands after I get the new unit.
@ drsandyrae - Sandy, please see if these modifications fix your problems (see the attached files).
Code:
#include "BMSerial.h"
#include "RoboClaw.h"
#define address 0x80
#define Kp 200
#define Ki 100
#define Kd 80
#define qpps 51200
BMSerial terminal(0,1);
RoboClaw roboclaw(19,18);
void setup() {
char version[32];
uint16_t voltage;
uint8_t status;
bool valid;
terminal.begin(38400);
roboclaw.begin(2400);
roboclaw.SetM1Constants(address,Kd,Kp,Ki,qpps);
roboclaw.SetM2Constants(address,Kd,Kp,Ki,qpps);
delay(5000); // gives me time to start the terminal
roboclaw.ReadVersion(address,version);
terminal.print(version);
terminal.println();
voltage=roboclaw.ReadMainBatteryVoltage(address, &valid);
terminal.print("Main Battery Voltage:");
terminal.print(voltage);
terminal.println();
}
void displayspeed(void)
{
uint8_t status;
bool valid;
uint32_t enc1= roboclaw.ReadEncM1(address, &status, &valid);
if(valid){
terminal.print("Encoder1:");
terminal.print(enc1,DEC);
terminal.print(" ");
terminal.print(status,HEX);
terminal.print(" ");
}
uint32_t enc2 = roboclaw.ReadEncM2(address, &status, &valid);
if(valid){
terminal.print("Encoder2:");
terminal.print(enc2,DEC);
terminal.print(" ");
terminal.print(status,HEX);
terminal.print(" ");
}
uint32_t speed1 = roboclaw.ReadSpeedM1(address, &status, &valid);
if(valid){
terminal.print("Speed1:");
terminal.print(speed1,DEC);
terminal.print(" ");
}
uint32_t speed2 = roboclaw.ReadSpeedM2(address, &status, &valid);
if(valid){
terminal.print("Speed2:");
terminal.print(speed2,DEC);
terminal.print(" ");
}
terminal.println();
}
void loop() {
uint16_t voltage;
bool valid;
roboclaw.SpeedAccelM1(address,40000,20000);
roboclaw.SpeedAccelM2(address,40000,20000);
for(uint8_t i = 0;i<20;i++)
displayspeed();
voltage=roboclaw.ReadMainBatteryVoltage(address, &valid);
terminal.print("Main Battery Voltage:");
terminal.print(voltage);
terminal.println();
roboclaw.SpeedAccelM1(address,40000,-20000);
roboclaw.SpeedAccelM2(address,40000,-20000);
for(uint8_t i = 0;i<20;i++)
displayspeed();
voltage=roboclaw.ReadMainBatteryVoltage(address, &valid);
terminal.print("Main Battery Voltage:");
terminal.print(voltage);
terminal.println();
}