Pages: [1] 2   Go Down
Author Topic: USB device drawing too much power (beginner ques.)  (Read 2822 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi! New to Arduino and psyched. However..I've been trying to do simple 'use a pushbutton to a LED' but I get this message when I press the button

Because a USB device was drawing too much power from your computer, one or more of your USB devices have been disabled.
To prevent damaging your computer, the USB device drawing too much power has been disabled. Other devices may have also been disabled...

I'm using an iMac Mac OSX 10.6.4

I'd appreciate any advice. New to this..

Thanks
Logged

0
Offline Offline
Faraday Member
**
Karma: 13
Posts: 2857
ruggedcircuits.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It sounds like your pushbutton is connected to the wrong pins, perhaps between 5V and GND?

Where did you connect your pushbutton?

--
The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, light sensor, potentiometers, pushbuttons
Logged

Melbourne, Australia
Offline Offline
Full Member
***
Karma: 1
Posts: 226
Cyborg-in-progress
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sounds like you've connected it so that the button shorts out the power supply! Could you post details of how you've connected everything together? A sketch or a photo would make it much easier for people to help you.
--
Jon
Practical Arduino: www.practicalarduino.com
Logged

Melbourne, Australia
Offline Offline
Full Member
***
Karma: 1
Posts: 226
Cyborg-in-progress
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

SNAP! We even used the same words and came to the same conclusion, only 3 seconds apart   ;-)
Logged

0
Offline Offline
Faraday Member
**
Karma: 13
Posts: 2857
ruggedcircuits.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Arduino Hive Mind?

--
The Quick Shield: breakout all 28 pins to quick-connect terminals
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I put a photo of what I have here..  http://datavisual.tumblr.com/#1202848716
Logged

0
Offline Offline
Faraday Member
**
Karma: 13
Posts: 2857
ruggedcircuits.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yup, definitely wrong wiring. Connect one side of the switch to GND. Connect the other side of the switch to pin 7 (red wire). Get rid of the resistor and other yellow wire (to 5V).

In your sketch, enable the pullup on pin 7:

Code:
void setup() {
pinMode(7, INPUT);
digitalWrite(7, HIGH);
}

Then, when the button is pushed, pin 7 will read LOW, else it will read HIGH.

--
Need a custom shield? Let us design and build one for you.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks! Good news is I no longer get that USB power message. This is new photo http://datavisual.tumblr.com/#1202980891 and my code.. light still doesn't go on tho..

#define LED 13
#define BUTTON 7

int val = 0;

int state = 0;

void setup() {
pinMode(7, INPUT);
digitalWrite(7, HIGH);
}


void loop() {
  val = digitalRead(BUTTON);
  
  if (val ==HIGH) {
    state = 1 - state;
  }
  
  if (state == 1) {
    digitalWrite(LED, HIGH);
  } else {
    digitalWrite(LED,LOW);
  }
  
}
Logged

Somewhere in Arizona
Offline Offline
God Member
*****
Karma: 0
Posts: 725
Arduino must be a drug, because I'm addicted!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

^^^^^^^^^^
Or you can leave the code as is, and swap the wires for ground and signal. ust move the right yellow wire over, and the red wire to thw contact on the pushbutton.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Jeremy. Liked your suggestion but still can't get the light to go with the wires switched as you said (and the original code). Tried restarting program and computer just for good measure as well. Guess I'm a little stumped here..
Logged

Melbourne, Australia
Offline Offline
Full Member
***
Karma: 1
Posts: 226
Cyborg-in-progress
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm a bit confused about what you're trying to achieve. It *looks* like what you're wanting to do is have the LED change state on a button press, but what you've written won't achieve that. If you just want a simple "on while pressed" behavior, you could simplify your sketch to this (untested):

Code:
#define LED 13
#define BUTTON 7

void setup() {
  pinMode(BUTTON, INPUT);
  digitalWrite(BUTTON, HIGH);
  pinMode(LED, OUTPUT);
}

void loop() {
 if (digitalRead(BUTTON) == LOW) {
   digitalWrite(LED, HIGH);
 } else {
   digitalWrite(LED,LOW);
 }
}

It may seem like the logic is inverted, but what's happening is that the internal pull-up on the BUTTON pin will hold that input high unless the button is pressed. So a LOW value on the button corresponds to a press, which is then used to set a HIGH value (illuminated) for the LED.
--
Jon
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8458
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Or even simpler (but inverted)

Code:
void loop() {
 digitalWrite(LED, digitalRead(BUTTON)
}
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Melbourne, Australia
Offline Offline
Full Member
***
Karma: 1
Posts: 226
Cyborg-in-progress
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey @Graynomad, spot on. Or to be just a little bit trickier:

Code:
void loop() {
 digitalWrite(LED, !digitalRead(BUTTON))
}

@PeteAJ: What Graynomad's suggestion does is set the LED output pin level to match the BUTTON input pin level. Very simple and clear.

The "!" you see in my trivially modified version is a logical "NOT" operator, which reverses the logic so that instead of setting the LED output to the same level as the BUTTON input, it sets it to the *opposite* value. Since the button is "low" while pressed that'll give the effect of turning on the LED when the button is pressed, and off when released.
--
Jon

Edit: Added in the second closing bracket that was missing from the copied / pasted code
« Last Edit: September 28, 2010, 02:24:45 am by jonoxer » Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8458
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

And you even got the syntax right with two closing parens.
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 513
Posts: 31529
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
And you even got the syntax right with two closing parens.

but missed the semicolon off the end.
Logged

Pages: [1] 2   Go Up
Jump to: