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:
- 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.?
- 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.
- 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.
- 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
- If that doesn't work, it might be an issue with the
println. The data sheet says to terminate the command with
println terminates with
\r\n. If the motor controller can parse correctly then this shouldn't be an issue.
- If that doesn't work, it might be an issue with ASCII/binary, and you might need to use
Serial1.write() instead of
- 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.
- 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.
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
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.