I am attempting to drive two servos, and found that I could not get the servo output to occur until a com port connection was made. When looking at the output on an oscilloscope, the pulse does not start until the exact instance a com port connection is made. So we stripped everything from our code in the setup() and loop() functions. We found that these two functions were not being executed at all, again, until the com port connection is made; even when just running simple things like attachpin and a delay, no serial writes, no UART comms, nothing complicated at all. Is there something that has to be changed in order to allow the setup function to be executed with an external power supply and not a com port connection. Once the com port connection is made the setup and loop function execute perfectly and everything operates exactly as needed even after the USB connection is removed. Does any have any ideas of what we are doing wrong?
Sorry, I forgot to include some important information. I am using the Arduino Uno (ATmega328)
Is there something that has to be changed in order to allow the setup function to be executed with an external power supply and not a com port connection.
That doesn't make much scence. Are you saying the program runs when the UNO is powered via the USB connection and not when powered from an external power supply? when using an external power supply have you tried pushing the UNO reset button? Does the blink example work? Your code could also have issues.
It really doesn't make sense. No, it will not work if it is just powered by USB, it will not work until a com port connection is made to the board. I have not tried pushing the Uno reset button because it didn't seem to make a difference between USB power or external power supply. Will the reset clear everything and require a reload?
The Blink example does work.
david2009:
The Blink example does work.
Then you probably have issues with your code, wiring, or power supply.
Got anything attached to pins 4 or 7 ? If so then try moving to another pin.
The following is all I am doing as a test and it requires a com port connection to work. There's no way that this should require a com port connection to run the setup function.
#include <Servo.h> // Built in servo library
// Values determined by based on experimentation
static const int SERVO_MAIN_STOP = 94;
static const int SERVO_MAIN_TURN_LEFT = 87;
static const int SERVO_MAIN_TURN_RIGHT = 100;
// Define our Servos for moving the main body and tail motors
Servo servoMain;
Servo servoTail;
/*
*
- Arduino setup
/
void setup()
{
servoMain.attach(9); // servo on digital pin 9 for body movement
}
/
*
- MAIN LOOP
*/
void loop()
{
// center the Servos
servoMain.write(SERVO_MAIN_LEFT);
delay(2500);
servoMain.write(SERVO_MAIN_RIGHT);
delay(2500);
servoMain.write(SERVO_MAIN_STOP);
}
My power supply is at 8.48 Vdc LiPo battery, just measured it with a multimeter. The positive is connected to two smaller wires, one goes to Vin on the board and the other goes to the Servo's red wire. The Negative of the batter is connected directly to the Gnd (between the +5V pin and the 2nd Gnd). The 2nd Gnd pin is connected to both of the servos' black Gnd wires. Then the pulse, pin 9 (also used 8 in the past) is connected to the yellow signal wire of the servo... This expected pulse is sent out of pin 9 (or 8) on two occasions: 1. when the code is uploaded to the board, and 2. when a com port connection is made to the board using Teraterm. Otherwise when the com port is and the board is powered up, it does not send the pulse like it is suppose to. I have verified this on an oscilloscope.
Problem solved. It appears as though the Arduino Uno had a hardware failure of some type. As I switched it out with an Arduino Mega 2560 and the code functioned perfectly. I will be replacing the Uno with another Uno, and at that point will see if it is a true hardware problem or a servo.h library compatibility issue with the Uno.
I take back my last posting. So I solved one problem and apparently I have two. I still have to make a com port connection for my servo output pin to put out a pulse, ONLY when I have my Wilfy GSX attached to my Arduino Uno. If I take off the wifly shield the sketch runs as expected. Do I need to regulate the Rx data pin in my code so that the setup and loop functions can execute?
Did you see my reply to your problem?
If the problem only happens when you're using servos (i.e. other sketches work as expected), the problem is likely related to power. Try, for example, not connecting your battery to the Vin pin on the Arduino (power the Arduino from the USB port or it's own external power supply). Or you could try adding some big capacitors (e.g. >= 100 uF) between Vcc and Ground on the Arduino board.
Should the servo be powered by 5Volts?
I looked at the sparkfun Wifly sheild and it uses a 1k pullup attached to digital pin 7. That will cause what you are seeing on a Uno (r2).
You did say the problem went away if the sheild was removed. This would let pin 7 be free from the pullup on it.
Why? Just for a test,with the sheild removed, add a pullup on pin 7(pin 4 also shows this situation) - say 1k to 10k from the pin to the 5V pin. What happens?
To still use the Wifly sheild and not see the problem you are seeing it would require adding a diode on the reset pin. Please see how Atmel in their design notes, AVR042 page 5 , use a diode on the reset pin.
Justone
I saw your previous responses. I have nothing on pin 4 or 7. I tried a 10k resistor from pin 7 and pin 4 to the 5Vpin and neither allowed the sketch to run. So your saying add in diodes to the reset? I couldn't find an Arduino board diagram to show me the best way to tie into the reset button, any help? I still don't fully understand why the Wilfy board would cause a problem, it doesn't use much power. Do you also suggest trying the capacitor accross the Vin to ground? Thanks!
A diode 1N914 from the 5V pin to the reset pin fixed the problem. From other online research is seems that there is a voltage spike on the R2. Thank you all for your help, I now have it working with the wilfy board attached.