USB port, not cable. My bad for the wrong nomenclature.
To clarify "flaky at best": On startup, the LCD displays the initial message properly. When a button is pressed on the circuit to invoke a servo move, sometimes the servo will move slightly, sometimes it will over-travel, sometimes it will just sit there. The LCD may or may not display one of the several possible text lines as contained in the sketch, then it will return to the initial display as reflected at the top of the sketch. It's almost as if there's not enough power to drive the servo, and the whole circuit sags and resets. I will put a scope on the 5V pins to see what's going on during execution. The power going into the ADK is provided at Vin from a 9 volt regulator (common 7809) that is itself sourced by a 24VDC 1A wall wart. The servos and LCD are powered via the 5V ins on the ADK. Using the USB port for power (supplied from notebook with Arduino editor) works fine. Disconnect the USB cable and attach the wall wart for power, and the circuit fails as described above. Using a different PC to provide power through USB also causes the failure symptoms. The wall wart is never attached to the circuit when a USB cable is live. Again, I'll start poking around the ADK with a scope during the failure mode to see if the 5V rail is collapsing.
I am not invoking USB in the sketch. The project is a standalone test fixture in an electronics manufacturing environment. It moves two standard Futaba servos (one at a time), uses an LCD for user messaging and drives a small circuit board (device under test) that pulls about 100mA.
Here's the code - apologies for it not being very clean - it's a work in progress and contains some commented stuff I bring in and out as the project progresses. I also had to truncate it due to message length limitations on this site. You can at least see the initial setups...
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(22, 24, 28, 30, 32, 34);// LCD pins used on these digital I/O pins.
#include <Servo.h> // include the library
Servo myservo; // create two servo objects to control the 2 servos
// a maximum of eight servo objects can be created
Servo MyServo; // for the encoder intrusion servo
// these constants describe the pins. They won't change:
const int ypin = A3; // x-axis of the accelerometer
const int xpin = A2; // y-axis
int pos = 0; // variable to store the servo position
const int StartPin = 2; // the number of the pushbutton pin = > START BUTTON
const int ResetPin = 11; // the number of the pushbutton pin = > RESET BUTTON
const int ledPin = 9; // the number of the LED pin: for FAIL indicator. Not used
// variables will change:
int SState = 0; // variable for reading the START pushbutton status
int RState = 1; // variable for reading the RESET pushbutton status
boolean flag = true; // variable for sanity check.
void setup()
{
Serial.begin(9600);
// set up the LCD
lcd.begin(16, 2); // intitalize the LCD
myservo.writeMicroseconds(1464); // set servo to mid-point // encoder board servo value
// set cursor on LCD
lcd.home();
MyServo.writeMicroseconds(1450); // set blue servo close to mid-point
// highest will be 1700
pinMode(31, OUTPUT); // y out
pinMode(12, OUTPUT); // x out
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
// initialize the pushbutton pins as an input:
pinMode(StartPin, INPUT);
pinMode(ResetPin, INPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT); // FOR FAIL LIGHTS
}
void loop()
{
myservo.attach(10); // attaches the servo on pin 10 to the servo object
// checking conditions
MyServo.attach(48); // attaches the blue servo on pin 48 to the servo object
int valOne = digitalRead(6);
int valTwo = digitalRead(7);
int valThree = digitalRead(8);
// lcd.print("PRESS RESET ");
delay(700);
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("INSTALL BOARD");
//lcd.clear();
lcd.setCursor(0, 2);
lcd.print("THEN PRESS START ");
// myservo.write(0);
Serial.println("WAITING FOR START" );
Serial.println("VALUE FOR RESET BUTTON IS ");
Serial.print(RState);
boolean flag=true;
SState=0;
while(SState==0)
{
SState = digitalRead(StartPin);
if(SState==1){
// when the button is pressed
break;
}
// will wait until Start button is pressed.
}// end of while
// now start button was pressed.
lcd.clear();
lcd.print("TESTING... ");
// before SERVO moves, we want the intial value of the axis.
int a = analogRead(ypin);
int c = analogRead(xpin);