Recently, I just bought the MSSS30 as the motor driver for my wheelchair project(2 wheels).
My goal is to motorized the wheels and I chose to use the combination of the dc motor driver, Arduino kit and the Arduino shield V2 as my parts.
I used the following link as my reference to set up my model.
https://www.youtube.com/watch?v=6RxugAY1-TU
Please adjust the time to 3:00 to watch the setup.
My question is that which mode should I choose? (Analog joystick to PWM?)
The mode I used right now is 01 00 00 00(Analog mixed mode?) I'm very confused about this.
My goal is to control the wheels using a joystick which can achieve going forward, going backward, turn left, and turn right.
The other major problem is about the code. Because I am really new to the coding part, I hope someone can help me with it.
The current code I used is following:
- CODE: SELECT_ALL_CODE
#include <Cytron_SmartDriveDuo.h>
#define IN1 4 // Arduino pin 4 is connected to MDDS30 pin IN1.
#define AN1 6 // Arduino pin 5 is connected to MDDS30 pin AN1.
#define AN2 5 // Arduino pin 6 is connected to MDDS30 pin AN2.
#define IN2 3 // Arduino pin 7 is connected to MDDS30 pin IN2.
Cytron_SmartDriveDuo smartDriveDuo30(PWM_INDEPENDENT, IN1, IN2, AN1, AN2);
char inChar;
signed int speedLeft, speedRight;
void setup()
{
pinMode(13, OUTPUT);
Serial.begin(9600);
digitalWrite(13, HIGH);
delay(2000); // Delay for 5 seconds.
digitalWrite(13, LOW);
}
void loop()
{
int motorspeedA = analogRead(A0);
speedRight = map(motorspeedA, 0, 1023,-100,100);
int motorspeedB = analogRead(A1);
speedLeft = map(motorspeedB, 0, 1023,-100,100);
smartDriveDuo30.control(speedLeft, speedRight);
delay(100);
}
It is possible that I could have some ridiculous mistakes in my code. Appreciate it if someone could give me some suggestion or advice.
One thing to mention is that I also want to add some function like when the joystick is near the center position, give a range to the value so that the motor will stop when it is near the center part.
Also, a function that will keep the motor not rotating when it is at low rpm like 30rpm.
In general, my questions are:
1. Which mode should I choose by using a joystick connected to Arduino kit to control motors?
2. Do you have any suggestion on how should I connect all these parts?
3. Do you have advice on how should I revise my code or even a general code for joystick control motors?
4. I want to add functions like keep motors rest when the joystick is near its center, also make it rest when the rpm is low.