Serial communication with Arduino erratic behavior.
-
- Posts: 5
- Joined: Sun Sep 06, 2015 6:25 pm
Serial communication with Arduino erratic behavior.
The RoboClaw works perfectly when using the IonMotion software. The problem is...
I have an Arduino Mega 2560 connected to RoboClaw 2x15A V5 using simple serial protocol. The arduino is powered from the BEC 5V, sharing common ground. The Arduino runs and stops motor 1 and indicates it using its onboard LED. The LED alternates every two seconds as expected, but the motor behaves completely unpredictably. It runs in random directions at random intervals. BUT, this erratic behavior goes away when I connect the RoboClaw to a powered PC using USB. It goes away whether I plug it in before powering on or afterwards. (while the code is running on Arduino and motor 1 is doing random moves) I have no idea what's going on. Please help me figure this out. Thank you in advance.
I have an Arduino Mega 2560 connected to RoboClaw 2x15A V5 using simple serial protocol. The arduino is powered from the BEC 5V, sharing common ground. The Arduino runs and stops motor 1 and indicates it using its onboard LED. The LED alternates every two seconds as expected, but the motor behaves completely unpredictably. It runs in random directions at random intervals. BUT, this erratic behavior goes away when I connect the RoboClaw to a powered PC using USB. It goes away whether I plug it in before powering on or afterwards. (while the code is running on Arduino and motor 1 is doing random moves) I have no idea what's going on. Please help me figure this out. Thank you in advance.
-
- Posts: 12
- Joined: Mon Aug 31, 2015 8:00 am
Re: Serial communication with Arduino erratic behavior.
I couldn't get the software serial to work well either. So I switched to a library that uses hardware serial and it works:
http://forums.basicmicro.co.uk/topic997 ... 048518b33f
http://forums.basicmicro.co.uk/topic997 ... 048518b33f
- Basicmicro Support
- Posts: 1594
- Joined: Thu Feb 26, 2015 9:45 pm
Re: Serial communication with Arduino erratic behavior.
You definitely want to use hardware serial if you can. If you cant you will probably need to use a lower baudrate.
If you are using our arduino libraries and you specify the hardware serial pins when initializing the class the library should use the hardware serial arduino library to talk to the serial port automatically.
Also in general I highly recommend you use our arduino library instead of trying to hand code your own commands to the board or using simple serial. Simple serial is easy but there is NO error correction. If it gets bad data(which it looks like it is from your description) then you get random motor movements. Also I'd recommend updating to the newest firwmware. We recently adjusted the baudrates so they are more accurate. But if you have to use simple serial and you are having issues like this then lower the baudrate.
If you are using our arduino libraries and you specify the hardware serial pins when initializing the class the library should use the hardware serial arduino library to talk to the serial port automatically.
Also in general I highly recommend you use our arduino library instead of trying to hand code your own commands to the board or using simple serial. Simple serial is easy but there is NO error correction. If it gets bad data(which it looks like it is from your description) then you get random motor movements. Also I'd recommend updating to the newest firwmware. We recently adjusted the baudrates so they are more accurate. But if you have to use simple serial and you are having issues like this then lower the baudrate.
-
- Posts: 12
- Joined: Mon Aug 31, 2015 8:00 am
Re: Serial communication with Arduino erratic behavior.
I used the hardware serial pins and it didn't work for me. Had to use that hardware library to get it working.If you are using our arduino libraries and you specify the hardware serial pins when initializing the class the library should use the hardware serial arduino library to talk to the serial port automatically.
- Basicmicro Support
- Posts: 1594
- Joined: Thu Feb 26, 2015 9:45 pm
Re: Serial communication with Arduino erratic behavior.
Ill pull out a mega2560 and test it this week sometime.
-
- Posts: 5
- Joined: Sun Sep 06, 2015 6:25 pm
Re: Serial communication with Arduino erratic behavior.
Lowering baudrate with software serial definately improved stability, but I was still getting occasional hiccups/unintended behaviors. Using hardware serial UART on the Arduino solved the problem completely. Confirmed working with simple serial and packet serial.acidtech wrote:You definitely want to use hardware serial if you can. If you cant you will probably need to use a lower baudrate.
If you are using our arduino libraries and you specify the hardware serial pins when initializing the class the library should use the hardware serial arduino library to talk to the serial port automatically.
Also in general I highly recommend you use our arduino library instead of trying to hand code your own commands to the board or using simple serial. Simple serial is easy but there is NO error correction. If it gets bad data(which it looks like it is from your description) then you get random motor movements. Also I'd recommend updating to the newest firwmware. We recently adjusted the baudrates so they are more accurate. But if you have to use simple serial and you are having issues like this then lower the baudrate.
- Basicmicro Support
- Posts: 1594
- Joined: Thu Feb 26, 2015 9:45 pm
Re: Serial communication with Arduino erratic behavior.
Good to know. Software serial on Arduino uses interrupts to catch the start bit on bytes being received. Other interrupts can cause problems with this(eg delay the PCINT from being handled). Were you by chance using any other commands that may have been using other interrupts?
Note: Hardware serial would not have this problem.
Note: Hardware serial would not have this problem.
-
- Posts: 12
- Joined: Mon Aug 31, 2015 8:00 am
Re: Serial communication with Arduino erratic behavior.
Since the hardware UART library works so much better than the software serial library, i think you should support the hardware library - in other words you should have a link to it and you should clean up the one that I linked to.
- Basicmicro Support
- Posts: 1594
- Joined: Thu Feb 26, 2015 9:45 pm
Re: Serial communication with Arduino erratic behavior.
If you use the hardware serial pins for the receivepin and transmitpin in the Roboclaw constructor, then our library will use the arduino hardware serial classes(Serial, Serial1, Serial2,Serial3 or Serial4) depending on the pins used(eg Roboclaw(15,14,10000) for Serial3). The pins must be the specific RX and TX uart pins. You cant use one RX pin from one port and a TX from another port. I tested this the other day(with a Mega 2560) when I was testing 115200 on the new Roboclaw firmware.
I have not had an opportunity to look through that other hardware serial library to see if something different is going on.
I have not had an opportunity to look through that other hardware serial library to see if something different is going on.
- Basicmicro Support
- Posts: 1594
- Joined: Thu Feb 26, 2015 9:45 pm
Re: Serial communication with Arduino erratic behavior.
Also, if you need the highest speed communications possible then always use the hardware serial port on the Arduino. These are pins 0 and 1 on the UNO and Duemilanova boards. On the Mega 2560 there are 4 hardware serial ports. The Arduino can communicate up to 57600 with little error and 115200 is accetable error margins using the hardware serial ports.