I'm having trouble communicating with a stepper motor through a driver running on MCode.
I'm trying to talk to Schneider Electric's MForce Motor Driver using an Arduino Mega and a BOB-10124 TTL to RS485 converter.
The Mega's Serial1 port is working, but the data sent from the Arduino is not understood by the Driver and I'm receiving continuous gibberish data back from the Motor Drive. Any clue what's going on?
Hardware Components:
Arduino Mega
BOB-10124 TTL to RS485 converter
MForce Micro Drive Plus Motor controller
NEMA 17 Stepper Motor
#define SSerialRX 19 //Serial Receive pin
#define SSerialTX 18 //Serial Transmit pin
#define SSerialTxControl 3 //RS485 Direction control
#define RS485Transmit HIGH
#define RS485Receive LOW
#define Pin13LED 13
int ledPin = 5;
/*-----( Declare Variables )-----*/
char dataReceived;
char dataSend;
void setup() /****** SETUP: RUNS ONCE ******/
{
// Start the built-in serial port
Serial.begin(9600);
Serial.println("Input motor commands:");
pinMode(Pin13LED, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(SSerialTxControl, OUTPUT);
digitalWrite(SSerialTxControl, RS485Receive); // Init Transceiver
// Start the serial port, to another device
//RS485Serial.begin(4800); // set the data rate
Serial1.begin(9600);
}//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
digitalWrite(Pin13LED, HIGH); // Show activity
if (Serial.available()) {
dataSend = Serial.read();
digitalWrite(SSerialTxControl, RS485Transmit); // Enable RS485 Transmit
Serial1.write(dataSend); // Send byte to Motor Driver
// Serial1.write('\r');
delay(10);
digitalWrite(SSerialTxControl, RS485Receive); // Disable RS485 Transmit
digitalWrite(Pin13LED, LOW); // Show activity
}
if (Serial1.available()){
digitalWrite(ledPin, HIGH);
digitalWrite(SSerialTxControl, RS485Receive); // Ensure RS485 Receiving
dataReceived = Serial1.read();
delay(10);
digitalWrite(ledPin, LOW);
Serial.println(dataReceived);
}
}