Page 1 of 1

[SOLVED] Packet Serial Issues with Arduino

Posted: Mon Oct 26, 2015 12:07 pm
by harmonicPerc
Hi,

I am attempting to control a Roboclaw 2x60 using the packet serial mode, but encountering some problems. I have verified that the hardware works and is up to date by using the Windows Ionmotion software to update the firmware (on Friday 10/23) and successfully instruct the Roboclaw to drive a motor. However, I am experiencing difficulty getting proper communication established with an Arduino UNO R3. I downloaded the Arduino library and examples the week of 10/12 sometime, so they should be the up to date as well. I am able to get partial function using the simple serial mode example as follows: Roboclaw is set to Mode 6, Option 4; Arduino pin 10 is wired to S2, pin 11 is wired to S1, and Arduino ground is wired to the pin above the '-' label on the Roboclaw's IO block. This results in Motor B being driven bidirectionally as per the code in the example, but not Motor A. I have also attempted to use the packet serial read version example without success. I used the same wiring setup, but with the Roboclaw set to Mode 7, Option 4. Nothing was returned to the Arduino serial monitor (set to the proper baud of 57600), so I added an 'else' case to the code as follows:

Code: Select all

if(rc.ReadVersion(address,version)){
  terminalSerial.println(version);  
} else {
  terminalSerial.println("No response from roboclaw");
}
This resulted in a partially garbled response being printed to the serial monitor, where the first several characters were not in the standard character set and were displayed as '?' boxes. The number of garbled characters remained consistent through each iteration of the loop() function. I tried substituting in Arduino's Serial library, with similar results. I also created a new sketch with only BMSerial at the same baud rate as the example and no Roboclaw calls, and was able to read the messages printed to serial just fine.

Is this code verified to work with an Arduino UNO R3? Or maybe I've made an obvious mistake that someone else here can catch? I'm not really sure how to troubleshoot this further, so any suggestions are welcome!

Thanks for your help!
Ross

Re: Packet Serial Issues with Arduino

Posted: Tue Oct 27, 2015 10:46 am
by Basicmicro Support
You can check if your arduino libraries are up to date by checking the roboclaw.h file. At the bottom of the H file you should see these lines:

void crc_clear();
void crc_update (uint8_t data);
uint16_t crc_get();


If you dont have these functions defined in your arduino library then you have the old library and it wont function with the new firmware.

The fact that one motor did something and the other didnt though tells me it is likely you do have the latest but double check anyway.

I suggest you focus on the ReadVersion command. Loop it a couple times. The Arduino Serial Monitor is not great about getting the first characters. If you loop it you can be sure it isnt the Serial Monitor causing problems.

Let me know what happens when you do that. Copy and paste the results as well. If I see what is being printed it may tell me whats wrong.

Also use a slower baudrate(or a faster one) to see if the baudrate is the problem.

No we have not tested with an UNO R3. We have tested with Mega2560 which I think uses the same USB to serial chip and didnt have problems(beyond normal problems arduino can have). We also test with Leonardo boards and the older Duemilanova. We have tested Due boards but not as recently.

Re: SOLVED - Packet Serial Issues with Arduino

Posted: Sat Oct 31, 2015 12:19 pm
by harmonicPerc
Hi acidtech,

Thanks for your reply, you were right about testing at different baud rates...I changed the baud rate for the Roboclaw to 9600, and everything works perfectly. I borrowed a Mega 2560 for testing, and once that was working, I verified that the code also works with the UNO R3. As for the garbled messages, I believe that they may have been caused by the fact that I was writing a string with ' rather than ". I have updated the code snippet to reflect the proper way to print a string to terminal.

I had read the warnings in the manual about certain baud rates not being particularly functional on the Arduino, but assumed that 37600 would work fine, since it was hardcoded into the examples. You might consider modifying that value for future releases of the Arduino libraries, to facilitate the plug and play experience for new users.

Thanks again for your help!
Ross

Re: SOLVED - Packet Serial Issues with Arduino

Posted: Sat Oct 31, 2015 2:09 pm
by Basicmicro Support
38400 usually does work ok. I would also test at 57600. Both are OK baudrates on arduino(eg fairly minimal bitrate error). Lower baudrates usually have lower errors of course but not always. Also on the arduino if you are using software serial with interrupts other commands that use interrupts can interfer with proper serial communications. If you have the option always use a hardware serial uart on an arduino(eg like on a Mega2560).