Leonardo USB Power Issues

Hello Everyone,

I am new to Arduino, but before I begin, I would like to say a hearty THANK YOU to everyone who put these boards together. I have an interesting application where an Arduino will control the inverter drive on a small warper that I am developing. In the midst of building a component of the schematic I noticed something strange with my Arduino Leonardo. I am using a Fairchild HCPL3700 to sense voltage and input logic on pin#4. My code differs a only a little from the basic button example...

const int buttonPin = 4;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);     
}

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:    
    digitalWrite(ledPin, HIGH);
  } 
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}

The way it works is that when voltage is present, the LED turns off. At all other times it is ON. My connections are as follows.

Arduino Pin HCPL3700 Pin
5V 2 & 8
GND 5 & 3 (To turn the LED off)
Digital 4 6

Additionally, I have a 0.1uF capacitor connected to pins 8 & 5 of the HCPL3700 in accordance with the datasheet here.

When I test it with the USB cable hooked up, it is very buggy and won't display proper logic. However, when I unplug the USB and plug in my Adafruit 9v power supply, everything works fine. I have tried it on multiple computers with no change. Any ideas why this is happening?

phprf:
where an Arduino will control the inverter drive on a small warper

What is a "warper"?

phprf:
I am using a Fairchild HCPL3700 to sense voltage and input logic on pin#4

AC mains voltage?

phprf:
When I test it with the USB cable hooked up, it is very buggy and won't display proper logic. However, when I unplug the USB and plug in my Adafruit 9v power supply, everything works fine.

I think you forgot to explain what this chip is "connected to".

James:

Here are the answers to your questions...

  1. A warper is a machine used in textiles to wind multiple ends of yarn onto a beam or bobbin. It is irrelevant in my current setup since I haven't connected it yet.

  2. The HCPL3700 is sensing DC 5V from the Arduino on pins 2 & 3 of the HCPL3700. The HCPL3700's logic output (Vo) is connected to Digital pin 4 on the Arduino which I am using as an input.

  3. My answers above should clear this one up. However, in different words, when I power the Arduino with USB I get what would appear to be absolute chaos on pin 4 of the Arduino (which again, is connected to the HCPL3700's logic output). Everything clears up and works as it should with I disconnect USB power and instead power the Arduino with the 9VDC power supply I referred to earlier.

My question is this: why would it behave differently? I have a guess, but I don't know if it is correct. I am using the 5V from the Arduino to both power the HCPL3700 and to supply the input to the chip. Perhaps it is drawing more current than is available from USB port, but not too much from the power supply? Just a thought. For the information the behavior is the same as the USB when I connect both USB and power supply.

Sounds like it could be a ground issue.

What is pin 3 of the optoisolator connected to?

GND on the Arduino