Speed Control with analog mode on roboclaw (arduino)

A roboclaw 2x5A v4 hoping to 2 linear actuators 12 volt of up to 5 amps each with my arduino and then my Adafruit pro trinket running off the same chip. I am in analog mode on the roboclaw and I am using pin 9 on the arduino uno. I’m using analogwrite function. I don’t seem to be able to stop the movement although I can change directions ,but the speed isn’t changing no matter what value I use. Mode 3, option 3. I do want it continues until I want to stop the motor.

Hello.

The analogWrite Arduino function in the Arduino environment actually produces a square wave at about 490Hz (for pin 9 on the Uno) where the average voltage of the wave equals the value specified by the “value” parameter. To get good results using analogWrite, you will need to add a filter circuit between the Arduino output and the RoboClaw analog input. The simplest form of a filter is probably an RC (resistor-capacitor) filter.

Alternatively, you might also be able to use the serial control mode of the RoboClaw to pass more exact settings into the RoboClaw. I see you have another forum post looking into this a bit more, so hopefully we can help you decide if that will work for you.

-Nathan

[quote=“nathanb”]Hello,

The analogWrite arduino function in the Arduino environment actually produces a square wave at about 490Hz (for pin 9 on the Uno) where the average voltage of the wave equals the value specified by the “value” parameter. To get good results using analogWrite, you will need to add a filter circuit between the Arduino output and the RoboClaw analog input. The simplest form of a filter is probably an RC (resistor-capacitor) filter.

-Nathan[/quote]

ty
After that filter what would control the speed? Right now I tried using analogwrite 0-255. Documentation says something about PID or something.

[quote=“nathanb”]

Hello,

An RC filter will turn the square wave that analogWrite generates into an smoother, close to constant analog voltage, which would set the speed for the motor controlled by the RoboClaw if it is set to analog mode. However, when using the RoboClaw with an Arduino, it is generally better to use serial communication instead of analog control. Serial communication will allow exact values to be passed from the Arduino to the RoboClaw rather than a messy, approximated analog voltage. Serial communication also requires only the connection wires rather than extra components for a filtering circuit.

On the RoboClaw, PID can be used with feedback from an encoder or potentiometer that detects the motor speed or position to more precisely control these things.

-Nathan

I’m trying to do simple serial now. I’m using instructions from v4 documentation. The code I have below says I need to use pin 5. Their wiring diagram says that I should use tx. I’m using using uno. My motors are brushed DC motors. The code doesn’t seem to do anything

[code]
#include <BMSerial.h>

//Arduino Due only supports using hardware uarts, pins 0/1, 14/15, 16/17 or 18/19.
//Set mode 5 and option 3
//Make sure Arduino and Robo Claw share common GND!
/*1 to 127 controls channel 1
128 to 255 controls channel 2
0 will shut down both channels
64 = Channel 1 - Stop
192 = Channel 2 - Stop
*/

BMSerial mySerial(5,6);

void setup() {

mySerial.begin(19200);
}

void loop() {
//mySerial.write(129);
// delay(2000);
mySerial.write(1);
mySerial.write(-1);
delay(2000);
mySerial.write(127);
mySerial.write(-127);
delay(2000);/* */
} [/code]

Hello,

That looks like the code on page 34 of the user manual, so that should be a valid example to test with.

It is not clear if you set your RoboClaw in the correct mode. I believe you will want to set the RoboClaw to Mode 5 (Standard Serial) to use the example code you provided. There is a detailed description of how to do this on page 18 of the user manual. The number of blinks of the LED and the times between the blinks are important in determining the mode the RoboClaw is set to. Can you check this and verify that you have successfully set the RoboClaw to Mode 5?

After the RoboClaw is set to Mode 5, you will need to set an option to select the serial baud rate. The correct option for this is Option 3.

If you set the RoboClaw to Mode 5 and Option 3, and the sketch still does not run the motors, could you post pictures of your setup that show the RoboClaw, motors, power supply, Arduino, and all of the connections between them?

You might also consider contacting the product’s manufacturer, Ion Motion Control, to troubleshoot this with them directly. They are more familiar with the various operating modes of this product and should be able to help you more efficiently than we can.

-Nathan