Boe-Bot with Arduino and Joystick: Works with USB, but Left wheel spins when USB unplugged.
Hi I am working with a student and we have a behavior that has stumped us. I will try and get a video and a code snippet to share.
We have a Boe-Bot with the Arduino Uno and Shield. We placed the Arduino Joystick on a breadboard and hardwired the breadboard to the arduino with a 5 foot piece of Ethernet Wire.
The Code works when the USB cable to the computer is plugged in. But the moment the USB cable is unplugged the Left Wheel starts spinning full speed forward. The joystick still works; controls the right wheel and can be used to reverse the left wheel. Plugging the Arduino Uno back into the USB cable and the left wheel stops immediately and the Joystick Control returns normally.
Next time the student is in class I wll get a video of the behavior and post the code.
We have a Boe-Bot with the Arduino Uno and Shield. We placed the Arduino Joystick on a breadboard and hardwired the breadboard to the arduino with a 5 foot piece of Ethernet Wire.
The Code works when the USB cable to the computer is plugged in. But the moment the USB cable is unplugged the Left Wheel starts spinning full speed forward. The joystick still works; controls the right wheel and can be used to reverse the left wheel. Plugging the Arduino Uno back into the USB cable and the left wheel stops immediately and the Joystick Control returns normally.
Next time the student is in class I wll get a video of the behavior and post the code.
Comments
Whether or not this is the problem, here's a good chance to teach your student good troubleshooting skills. Here are some of the most common reasons for this kind of issue. Work out a method for isolating and testing each one.
1. Poor (non-USB) power supply. Either the power isn't enough volts (should be 7V to 12V), not enough current, or both.
2. If you are using the servo headers on the Arduino Shield, be sure they are jumpered properly. Options are 5V (their power comes from the Shield's onboard regulator), or Vin. Be careful of this setting if you are using >6V supply, and your servos are not rated for over 6V. Otherwise, the servos may be damaged, or could behave erratically.
3. Check the switch position on the Shield. It should be in the "2" position when running servos. This is necessary for operation, and also to avoid damaging things. If you try to pulse a servo that is not powered, the servo could try to pull its current from the signal line. The Arduino cannot provide enough current for this. I recall, but can't be certain, that the shield includes current limiting resistors for the servo headers, but it's best not to tempt fate.
4. Add a "sanity check" to the top of the Arduino code that lets you immediately identify if the board is going into brownout. One good method is to have the LED on pin 13 flash a few times upon startup, but not thereafter. If the LED keeps flashing, then you know the board is resetting.
Servo servoLeft; // Declare left and right servos
Servo servoRight;
int spLeftRight = A0; // select the input pin for the potentiometer
int spUpDown = A1;
int vLeftRight;
int vUpDown;
int clr;
int cedUp;
void setup() {
// declare the ledPin as an OUTPUT:
servoLeft.attach(12); // Attach left signal to pin 13
servoRight.attach(13); // Attach right signal to pin 12
tone(4, 3000, 1000); // Play tone for 1 second
delay(1000);
Serial.begin(9600);
Serial.print("Starting");
Serial.print("\n");
}
void loop() {
// read the value from the sensor:
vLeftRight= analogRead(spLeftRight)*(400/970.0)-200+14;
vUpDown = analogRead(spUpDown)*(400/970.0)-200+21;
clr=(1500+ (-1*(vUpDown-vLeftRight)));
cedUp=(1500+ (vUpDown+vLeftRight));
Serial.print("LeftRight: ");
Serial.print( vLeftRight);
Serial.print(" UpDown: ");
Serial.print( vUpDown);
Serial.print(" clr ");
Serial.print(clr);
Serial.print(" cedUp");
Serial.print(cedUp);
Serial.print("\n");
if ((abs(vUpDown)+abs(vLeftRight))>40)
{
servoLeft.writeMicroseconds(clr); // Left wheel counterclockwise
servoRight.writeMicroseconds(cedUp); // Right wheel clockwise
}
else
{
servoLeft.writeMicroseconds(1500); // Left wheel counterclockwise
servoRight.writeMicroseconds(1500);
}
//delay(0); // ...for 0 seconds
}
In addition or in replacement of the tone, I'd flash the LED a few times at startup. The tone is okay, but the LED gets things going much faster. A couple of rapid flashes is enough, and there's no reason to pause for a second before starting with the rest of the sketch. The more obvious it is that the Arduino might be browning out the better.