starthere_-_working_now.pde (3491Bytes)
EDIT: LED problem solved thanks to RobotFreak. I forgot to set the pins to output mode using the pinMode command. As RobotFreak points out, the Arduino sets all pins as inputs by default. I added a For loop to set all the pins to outputs, and everything worked great.
void setup() {
pinMode(13, OUTPUT);
for (int pinindex = 0; pinindex < 14; pinindex++) {
pinMode(pinindex, OUTPUT); // set pins 0 to 13 as outputs
}
I have updated the attached code with the working version.
Note that the USB still resets when the board is not connected to external power and the servo is commanded to move. I suspect the servo draws close to 500mA or whatever my laptop's USB port can support.
I'm working on an Arduino version of the Start Here robot. I haven't got all the hardware yet, but I'm testing out the code on my Arduino Mega clone. I've got an LED that I'm using on different outputs to test their state during program operation.
Here's the weird thing. The LED is running really dim. I can barely see it. At first I thought maybe my cheap Chinese knock-off copy of the Mega was having a problem. I had previously tested all the outputs and they were fine. However, when I download the standard "Blink" program to the Mega with the the output pin changed to my LED pin, it works fine.
So now I suspect something in my code is weird. This is where you come in, my friends. ; j
I've attached my code and would appreciate a quick review to see if I've done something foolish. Here's some info on my setup and things I've tried so far.
Setup
- LED and 150 ohm resistor on Output 7 (one of the motor outputs), with other side going to ground
- Arduino connected to USB port
- Arduino powered by external wall wart: 12VDC, 2A
- Dagu mini servo connected to pin 9 (plus power and ground, of course)
- Sharp GP2Y0A21YK IR sensor connected to Analog pin 0 (pin 54 on Arduino Mega)
- Attached code pulls all unused Analog ports to HIGH using internal pullups
- Built in board LEDs are lit up nice and bright
Observations/Symptoms
- LED dim when running on pin 7 or 5 (motor outputs that are high during normal operation)
- LED lights up bright if I connect to pin 9 in parallel to servo, or directly to board 5V supply
- Running attached code, if I disconnect the external 12V supply, my computer keeps dropping the USB connection. I suspect I'm drawing more than the 500mA the USB is rated for. Works find with the external supply.
- Running standard Arduino 'Blink' program with output on pin 8, LED lights up nice and bright.
- Servo and Sharp sensor seem to work fine.
Stuff I've tested
- I've tried commenting out the For loop that sets all the internal pullup resistors: no effect
- I've tried commenting out all the servo commands: no effect
- I've tried commenting out the Serial.begin command: no effect
- I've tried phyically disconnecting power to the servo and to the Sharp: no effect
- I've tried adding a digitalWrite command to set an unused output to HIGH and moved the LED to that output: LED lights dimly
- I've tried asking for help from you guys: Effect to be determined ; j
If there's a problem with my code, I can't see it. I'm going to try to wire up the SN754410NE motor driver and see if outputs 7,6,5,4 are providing enough current to drive the logic. I'll post an update when I have some results. In the meantime, can anyone check over my code?
I'm also open to any suggestions to changes in my code. I'm pretty new to the Arduino. I'm not trying to do anything fancy with this one yet. Just trying to replicate the posted Start Here robot. I'll elaborate on the code and physical robot design later.