# Getting error on serial monitor when using serial controlled motor

I am using this motor in a robotic arm.

I wanted to move it to a position and the position was provided via an input but I am getting errors on Serial Monitor. Initially when I tried this , name of the serial controller i.e Rhino Motor Controller got printed on serial monitor indicating that the controller is working .But the problem is that I am not able to control the motor via Serial communication because I think it is not accepting the serial commands.

Here is the datasheet for the motor driver.

Here is the code:

#include <SoftwareSerial.h>
int angle ;

int position ;

int speed ;

String stringG1 ;

SoftwareSerial Serial1(10,11);

void setup()
{
Serial.begin(38400);
Serial1.begin(38400);

}
void loop()
{
int position = 4*angle  ;
speed = 10 ;

if(Serial.available()>0)
{
stringG1 = "N1" + String(position) + String(speed);
Serial1.println(stringG1);

if (Serial1.available()>0)
{
}
}
}


Output on serial monitor ,

N1-410
Err
:N1-410
Err
:N122810
Err
:N1-410
⸮⸮⸮5
:N119215⸮⸮5
:Nj⸮⸮0
Err
:N⸮⸮2810
Err
:N1-410
Err
:N119610
Err
:N119210
Err
:N119210RErr
:N1-41jT⸮⸮5
:N122810
⸮⸮⸮5
:N1-410
⸮⸮⸮5
:

• Have you tried communicating to the driver board with a serial communications program such as miniterm or hyperterm yet from your main computer (not the Arduino)? – NomadMaker Aug 24 '18 at 12:56
• The documentation says you need a carriage return at the end of the command. This might require a \n or a \r, or some combination of these. – NomadMaker Aug 24 '18 at 13:00
• @NomadMaker How will I be able to connect the pins of the Driver with my computer ? Do I need to buy a USB convertor for this ? – Sam Aug 28 '18 at 15:37
• It depends on your computer. All the computers that I see today no longer have a serial port, so you would need a USB-Serial cable. These cables are very useful to have anyway. – NomadMaker Sep 3 '18 at 15:15

Welcome to Robotics, Sam. You've posted your code and the errors you're getting, which is great. There are still a few pieces of information lacking, though. Unfortunately, it looks like the "datasheet" is pretty poor and there are several items that I would like to see that I can't find.

With some information missing, here's the list of troubleshooting steps I would take to try to identify the problem. I'm assuming, since you're able to get an error message back from the motor controller, that the wiring between the Arduino and the motor controller is generally okay. Here are the next things I would check:

1. Obviously, if it was working previously and now it is not working, then what did you change? Did you change software, or wiring, power supplies, power supply settings, etc.?
2. Riding on point (1) above, but there is a motor connected, right? You're requesting a particular position, but if there's no motor connected then it's not getting any feedback, or it might fault if it applies terminal voltage to the motor but then doesn't register any current flow.
3. This seems most likely to me - is your command formatted correctly? You send a command like N122810, but how does the motor controller know where position ends and speed starts? In carefully reading the datasheet, it looks like there's supposed to be a space between position and speed when you send the command. You do not have a space. I had thought maybe the space was a typo on the datasheet, but I can't tell how the motor controller would tell the difference between a pos/speed of 12 and 5 and a pos/speed of 1 and 25 without some kind of delimiter.
4. If that doesn't work, try using other commands. If you can successfully (and repeatably!!) poll the device with the S command, then that would eliminate the rest of the steps I've given here. If you can get S to work, try a position-only move with the P or N0 commands.
5. If that doesn't work, it might be an issue with the println. The data sheet says to terminate the command with \r, but println terminates with \r\n. If the motor controller can parse correctly then this shouldn't be an issue.
6. If that doesn't work, it might be an issue with ASCII/binary, and you might need to use Serial1.write() instead of Serial1.print() or Serial1.println().
7. It could also be an issue with voltage levels and proper registration of HIGH/LOW signals. If the Arduino is outputting on a 3.3V level, but the motor controller is expecting a 5V level, then HIGH on the Arduino output would fall in the "no man's land" of levels. Typically, a low is guaranteed to be registered at <0.3*vMax, a high is guaranteed to be registered at >0.7*vMax, and any signal between 0.3 and 0.7 of vMax is "ambiguous" and not guaranteed to be read correctly.
8. It could be an issue with voltage supply to the motor controller. The motor controller is supposed to get a 7-12V input. If, for example, you're powering it off of the 5V output on the Arduino, then you're under-powering the board and can get unexpected results.

:EDIT:

I think your issue might be due to a lack of common ground reference between the Arduino and the motor controller. If you're using a 9V battery to power the motor AND the motor controller, consider the circuit below:

It's also important to note that your 9V battery is probably insufficient to run the motor. For starters, the motor datasheet states the motor should be running on 12V.

Here is a source that shows battery capacity versus discharge rate. The "no load" rating on the motor shows it draws 75mA with zero load. The capacity chart then gives a battery life of about 4 hours with no load. If, however, you go to the rated load of 1400 mA, the battery chart, which tops out at a discharge rating of 1000 mA, estimates the battery life to be about four minutes.

My reading of the datasheet (it's sparse) gives me the feeling that the Vcc 5V connection is a 5V output, meant to power the actual encoder on the motor. You should not be powering this pin.

Finally, if the motor is drawing a large amount of current, it could be browning out battery supply. If/when the 9V battery's terminal voltage falls below 7V, the motor controller becomes underpowered and you become likely to get erratic operation. This might also explain the weird symbols you're getting back from the motor controller, like ⸮⸮⸮5

If this doesn't help, please edit your question to include pictures and/or a drawing of how you currently have everything wired.

Also, I might have the Rx/Tx lines backward in the drawing, but it sounds like you've got your communication to the motor controller already correct.

• Thanks for the response . I forgot to mention that I was using a 9 V battery . I tried using the carriage return it also didn't work. After all this I connected 5V (Arduino) supply to the Vdd pin of the driver and there is another power input point on the motor driver that I connected to the 9 V supply.The motor driver showed no response in the serial monitor like it did initially , but the motor started moving just like any other DC motor (low rpm) also the optical encoder started moving (no specific direction or position) randomly . – Sam Aug 28 '18 at 15:35
• @Sam - I updated the answer. The tl;dr is that your battery might not be big enough, or new enough, and you need to ensure the battery ground is connected to the Arduino ground. If possible, use two 9V batteries, one connected to Vdd and the input ground AND the Arduino ground, then a different 9V battery connected to M+ and M- terminals. – Chuck Aug 28 '18 at 19:33
• Aren't M+ and M- supposed to be connected to the PID controller because when I connect M+ and M- to battery runs continuously. Also I couldn't understand how a angle is converted to a position for serial command. And can I run this motor for positional control via some H bridge controller using Encoder pins separately . – Sam Sep 2 '18 at 12:34
• Apologies , I meant the motor runs continuously. – Sam Sep 2 '18 at 18:19