I have recently been using the dfrobotshop rover, and have been happily using it wired with no problems so far.
I have the link to a user guide here:
All the hardware works, and I am able to use a WASD code without the Bluetooth module. It does not let me upload when the cable and Bluetooth module are connected, despite the module not being connected.
I have no software issues either when the cable is in and module out, and my code works perfectly. I am using an Apple Mac and I am on the Mac OS software.
What I am aiming to do is be able to use the rover without the cable, and with it relying on the Bluetooth module. I have been able to connect the module with the computer, and the link light goes on.
If I was using windows, I think I am at the hyper terminal stage, but I cannot use this as I am on a Mac. I have already used many different alternatives to hyper terminal, but I have had no luck.
To confirm, if the Bluetooth module is installed on the rover, you will not be able to upload code or communicate with the rover via USB since it takes up the Tx and Rx pins. You first need to upload the code without the Bluetooth module in place, disconnect it from USB, install the BT module, then power it on and pair with the external device.
Note that you’ll also likely need to change the code slightly to be at the BT module’s default baud rate. The BT module is installed facing the front of the rover.
Thanks for your help cbenson. I have tried what you suggested, and now it’s possible to get the Rover to move forwards and backwards, albeit very briefly! It only moves about a cm…
Any ideas?
MJM
This is the code I’ve used:
int E1 = 6; //M1 Speed Control
int E2 = 5; //M2 Speed Control
int M1 = 8; //M1 Direction Control
int M2 = 7; //M2 Direction Control
void setup(void)
{
int i;
for(i=5;i<=8;i++)
pinMode(i, OUTPUT);
Serial.begin(9600);
Serial.println("setup");
}
void loop(void)
{
while (Serial.available() < 1) {} // Wait until a character is received
char val = Serial.read();
int leftspeed = 255; //255 is maximum speed
int rightspeed = 255;
switch(val) // Perform an action depending on the command
{
case 'w'://Move Forward
case 'W':
forward (leftspeed,rightspeed);
break;
case 's'://Move Backwards
case 'S':
reverse (leftspeed,rightspeed);
break;
case 'a'://Turn Left
case 'A':
left (leftspeed,rightspeed);
break;
case 'd'://Turn Right
case 'D':
right (leftspeed,rightspeed);
break;
case 'q'://Stop
case 'Q':
halt (leftspeed,rightspeed);
break;
}
}
void stop(void)
{
digitalWrite(E1,LOW);
digitalWrite(E2,LOW);
Serial.println("stop");
}
void forward(char a,char b)
{
analogWrite (E1,a);
digitalWrite(M1,LOW);
analogWrite (E2,b);
digitalWrite(M2,LOW);
Serial.println("forward");
}
void reverse (char a,char b)
{
analogWrite (E1,a);
digitalWrite(M1,HIGH);
analogWrite (E2,b);
digitalWrite(M2,HIGH);
Serial.println("reverse");
}
void left (char a,char b)
{
analogWrite (E1,a);
digitalWrite(M1,HIGH);
analogWrite (E2,b);
digitalWrite(M2,LOW);
Serial.println("left");
}
void right (char a,char b)
{
analogWrite (E1,a);
digitalWrite(M1,LOW);
analogWrite (E2,b);
digitalWrite(M2,HIGH);
Serial.println("right");
}
void halt (char a,char b)
{
Serial.print("stop");
analogWrite(E1,0);
digitalWrite(M1,LOW);
analogWrite(E2,0);
digitalWrite(M2,LOW);
}
@Mjm Not sure about why it only moves for a second (can’t really take the time at the moment to go over the code). Have you tried keeping the button pressed? Also, batteries are charged?
The code seems to be the same as the WASD code in the user guide. You also said that it works when connected to USB. That would tend to indicate that the code is fine. Honestly, the short movement sounds like a power problem. Marginal voltage supply from the battery would tend to act like this as the motor startup could load the battery enough to drop below the requirements of the logic circuit. It’s a fairly common problem that essentially causes the board to go braindead whenever the motors draw too much current.
It’s possible to work a capacitor into the VS circuit to cover the load caused by motor startup. It’s also possible to separate the logic power supply from the power supplying the H-Bridge driving the motors. Neither of those is a trivial solution to implement.
I would start with a check that the battery pack is producing adequate voltage. If that looks good, I would then knock the speed down from max to maybe 20-25% to reduce the startup load. If the bot works as expected, then it’s almost certainly as I have supposed.
Post back with the results and we can move ahead to a solution that works for you.