Sending commands th...
 
Notifications
Clear all

Sending commands through Arduino with RS232 Shield

11 Posts
1 Users
0 Likes
2,941 Views
(@amrinder703)
Posts: 0
New Member Guest
 

Dear All,

I am trying to use arduino along with RS232 shield. Before using arduino along with rs232 shield, CLass5D style motors motor wire was connected through usb with laptop and send the "RPA " command using termite terminal to know the position of motors and it does work.

Next i used the following code to send the same command through arduino. The Tx light blinks but motor do not send back the data.

To check if the RS 232 is pushing the commands, the RS232 shield and usb from arduino was both connected to laptop. After uploading the sketch, the RS 232 does show the commands in the terminal with Tx blinking light.

The motors are not responding to the RPA command through RS232 shield? Is there any command i can use to know position of motor 1 only through RS232 command line?

Kindly find the follwing code and attached rs232 shield diagram.

#include //we have to include the SoftwareSerial library, or else we can't use it
#define rx 3 //define what pin rx is going to be
#define tx 2 //define what pin tx is going to be
SoftwareSerial mySerial (rx, tx); //3 is TX, 2 is RX
String m;
void setup()
{
pinMode(3, INPUT);
pinMode(2,OUTPUT);
Serial.begin(9600,SERIAL_8N1); // setup serial with computer
mySerial.begin(9600);
Serial.write("Sending the command RPAr");
mySerial.write("RPA rn");
m=mySerial.readString();
Serial.println(m);

}
void loop()
{
//while(mySerial.available() > 0)
m=mySerial.readString();
Serial.print(m);
}

 
Posted : 30/01/2019 8:09 am
(@mmeyer)
Posts: 0
New Member Guest
 

Hello,

I believe your issue is in the formatting of the commands/characters sent. I have not used the termite terminal before, but my guess is that it has a built-in ASCII/hex converter, while Serial write in Arduino may not. If you open the Serial Sniffer (View > Serial Data Analyzer) in our SMI software, you will see that what is actually being sent to the motor is 52 50 41 20 when you issue "RPA". This is how you will want to communicate. I would check what's actually being sent/received if possible.

 
Posted : 30/01/2019 8:27 am
(@amrinder703)
Posts: 0
New Member Guest
 

Hello,
thanks for the quick reply, I tried using

mySerial.write("52 50 41 20 rn");

motor did not responded back, The Rx light on arduino did not blink at all.

Thanks and regards,
Amrinder Singh

 
Posted : 30/01/2019 8:34 am
(@mmeyer)
Posts: 0
New Member Guest
 

That would seem that Arduino handles serial writes correctly with ASCII characters. Perhaps the discrepancy is in the method of reading. Have you tried read() rather than readString()?

 
Posted : 30/01/2019 8:40 am
(@amrinder703)
Posts: 0
New Member Guest
 

I would not think so because i do not see flashing light on my Rx pin which means that motor never responded back. If the Rx light flashes and there is no data displayed that would prove that method of reading is wrong.

Tried the read() but it gave -1 which means that no data is available on the port.

When the motors are restarted, it shows some messages in the termite terminal window that lens are in home position. When motors are connected to RS232 shield, motors do not communicate (as Rx do not blinks).

How can i make sure that motors are communicating with the RS232 shield because so far i am not able to see any receiving data (flashing light on RS 232 shield Rx flashes with the incoming data) from motors.

Is there a arduino library available for class 5 animatic motors to know the position of only master or slave as RPA shows the position of both motors?

 
Posted : 30/01/2019 9:20 am
(@swalters)
Posts: 0
New Member Guest
 

There is no library. Please consider using the serial.print() as opposed to the write functions and specifying the exact type data being sent.

 
Posted : 30/01/2019 9:24 am
(@amrinder703)
Posts: 0
New Member Guest
 

Found a way to input HEX format through arduino but the motor is not moving to target position, Please find the program below used to move the motor 1 to a target position.

the command used is PT=19590 G (used through termite and it works)
the command used is (81 50 54 3D 31 39 35 39 30 20 30 20 47 20) (through arduino to motors)

Tested the program in the computer through RS232 Termite terminal and it looks like arduino is pushing right command but the motor is not moving though same command in characters in termite window works.

// Serial Communication
// 2019
// Purpose: Control the motor position using RS232 communications
// Status:

#include

// Do not use 0 and 1 if you want to be able to upload code while RS232 shield is attached to Arduino
SoftwareSerial mySerial(3, 2); //2 is TX, 3 is RX

// Motor Commands

byte preset1[4] = {0x52, 0x50, 0x41, 0x20}; // RPA
byte preset2[12] = {0x81, 0x50, 0x54, 0x3D, 0x31, 0x39, 0x35, 0x39, 0x30, 0x20, 0x47, 0x20}; // PT=19590 G

int delayTime = 500; //Time between commands

void setup()
{
Serial.begin(9600); // Serial Communication w/ Computer for Debugging
mySerial.begin(9600); // Serial Communication w/ motor

//for (int i = 0; i < (sizeof(preset1)); i++) // sizeof returns a count of bytes, not numbers if using int, float, or long
//{
//mySerial.write(preset1); // sends each byte sequentially
//Serial.println("motor comand 1 Byte Sent");
//}

for (int i = 0; i < (sizeof(preset2)); i++) // sizeof returns a count of bytes, not numbers if using int, float, or long
{
mySerial.write(preset2); // sends each byte sequentially
Serial.println("motor comand 1 Byte Sent");
}

delay(delayTime); //delay to allow motor time for next command

}

void loop()
{
}

Thanks and regards,
Amrinder Singh

 
Posted : 31/01/2019 5:59 am
(@mmeyer)
Posts: 0
New Member Guest
 

Amrinder,

Do you get a response from the motor for the RPA command in your arduino code? If not, the method of communication is still not correct.

Either way, you will need to send additional commands to the motor in order to see motion. For a position move, you will also need to define MP, VT= , ADT=. You will also need to disable hardware travel limits with EIGN(W,0) once at the beginning of your program.

 
Posted : 31/01/2019 8:04 am
(@amrinder703)
Posts: 0
New Member Guest
 

Dear Meyer,

Finally motors are responding back to RPA commands and I am able to move the motors using PT= positionnumber G comand send in the HEX format.
The issue was that the RS 232 shield has 2nd pin as TX and 3rd as RX and it was same configuration on the 9 pin of motors. After swapping the pins coming from RS232, motor started responding. code looks good.

Is there any way to get the the only position number from motors rather than having the RPA xxxxx xxxx as reply back from motor.

Thanks for the support and quick replies.

 
Posted : 04/02/2019 7:14 am
(@swalters)
Posts: 0
New Member Guest
 

See the ECHO command in the dev guide. Please note this is not the default state. Also please note that the ADDR value is not initialized automatically on boot up. These settings are changed when SMI detects or finds motors.

 
Posted : 04/02/2019 7:17 am
(@amrinder703)
Posts: 0
New Member Guest
 

ECHO_OFF worked smoothly.
Thanks and regards,
Amrinder Singh

 
Posted : 04/02/2019 8:18 am
Share: