LED Brightness with example Bridge Sketch for Yun

When I use REST commands to turn on a LED with the Bridge example for the Yun, the LED is not as bright as when it is turned on in a sketch. I have a 470 (measured 478) ohm resistor in series with the Red LED. With a sketch that justs turns the LED on in Static with pinMode and pinWrite commands, the output pin has 4.62 volts on it. The voltage drop (2.516) across the resistor indicates there is a 5.2 milliampere current through the LED and resistor. This gives full brightness.

When I use the example Bridge sketch with the REST command, arduino.local/aurduino/digital/8/1, the output pin voltage is only 1.728 volts. The voltage drop (38.3 millivolts) across the resistor indicates the current is only 80 microamperes! This is about 65 times less current.

The wiring does not change between the two sketches. What is happening? Does the Yun with REST Commands need its outputs buffered?

Thank you for any help with this.

Is the wiring EXACTLY the same between both sketches? If so, there must be something different happening in the sketch. If you look at the REST code, I'm sure you're going to see that once the command is decoded, it boils down to calling digitalWrite() just like any other sketch. It shouldn't make any difference what is calling digitalWrite().

It is a strange voltage you are seeing. Almost as if two outputs might be connected together and fighting each other: one high and one low. Could the difference in behavior due to a wiring error and one sketch is driving the shorted pin differently than the other?

It's hard to say without actually seeing what's going on. Could you please post the two sketches and your hardware setup?

Thank you, ShapeShifter for the reply. I have check the setup several times for a short. But, I have found none.

The wiring is a wire from pin 8 to the anode of the LED and the cathode of LED is connected to the 470 ohm resistor that goes to ground with another wire. I have only two wires, the resistor and LED connected to the Yun Board. I have confirmed the ground connection does go to ground.

Here is the testLed sketch that I use when the LED lights correctly.

void setup() {
  // put your setup code here, to run once:
  /* single red LED on 8
  */
   pinMode(8, OUTPUT);
   digitalWrite(8, HIGH);

}

void loop() {
  // put your main code here, to run repeatedly:
}

With this code, I get at pin 8 (Led anode), 4.45 Volts and at the LED cathode/470 resistor connection, 2.51 Volts. The LED has a normal brightness.

Here is the code for the bridge example that I am using:

/*
  Arduino Yún Bridge example

 This example for the Arduino Yún shows how to use the
 Bridge library to access the digital and analog pins
 on the board through REST calls. It demonstrates how
 you can create your own API when using REST style
 calls through the browser.

 Possible commands created in this shetch:

 * "/arduino/digital/13"     -> digitalRead(13)
 * "/arduino/digital/13/1"   -> digitalWrite(13, HIGH)
 * "/arduino/analog/2/123"   -> analogWrite(2, 123)
 * "/arduino/analog/2"       -> analogRead(2)
 * "/arduino/mode/13/input"  -> pinMode(13, INPUT)
 * "/arduino/mode/13/output" -> pinMode(13, OUTPUT)

 This example code is part of the public domain

 http://arduino.cc/en/Tutorial/Bridge

 */

#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>

// Listen on default port 5555, the webserver on the Yún
// will forward there all the HTTP requests for us.
YunServer server;

void setup() {
  // Bridge startup
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  Bridge.begin();
  digitalWrite(13, HIGH);

  // Listen for incoming connection only from localhost
  // (no one from the external network could connect)
  server.listenOnLocalhost();
  server.begin();
}

void loop() {
  // Get clients coming from server
  YunClient client = server.accept();

  // There is a new client?
  if (client) {
    // Process request
    process(client);

    // Close connection and free resources.
    client.stop();
  }

  delay(50); // Poll every 50ms
}

void process(YunClient client) {
  // read the command
  String command = client.readStringUntil('/');

  // is "digital" command?
  if (command == "digital") {
    digitalCommand(client);
  }

  // is "analog" command?
  if (command == "analog") {
    analogCommand(client);
  }

  // is "mode" command?
  if (command == "mode") {
    modeCommand(client);
  }
}

void digitalCommand(YunClient client) {
  int pin, value;

  // Read pin number
  pin = client.parseInt();

  // If the next character is a '/' it means we have an URL
  // with a value like: "/digital/13/1"
  if (client.read() == '/') {
    value = client.parseInt();
    digitalWrite(pin, value);
  }
  else {
    value = digitalRead(pin);
  }

  // Send feedback to client
  client.print(F("Pin D"));
  client.print(pin);
  client.print(F(" set to "));
  client.println(value);

  // Update datastore key with the current pin value
  String key = "D";
  key += pin;
  Bridge.put(key, String(value));
}

void analogCommand(YunClient client) {
  int pin, value;

  // Read pin number
  pin = client.parseInt();

  // If the next character is a '/' it means we have an URL
  // with a value like: "/analog/5/120"
  if (client.read() == '/') {
    // Read value and execute command
    value = client.parseInt();
    analogWrite(pin, value);

    // Send feedback to client
    client.print(F("Pin D"));
    client.print(pin);
    client.print(F(" set to analog "));
    client.println(value);

    // Update datastore key with the current pin value
    String key = "D";
    key += pin;
    Bridge.put(key, String(value));
  }
  else {
    // Read analog pin
    value = analogRead(pin);

    // Send feedback to client
    client.print(F("Pin A"));
    client.print(pin);
    client.print(F(" reads analog "));
    client.println(value);

    // Update datastore key with the current pin value
    String key = "A";
    key += pin;
    Bridge.put(key, String(value));
  }
}

void modeCommand(YunClient client) {
  int pin;

  // Read pin number
  pin = client.parseInt();

  // If the next character is not a '/' we have a malformed URL
  if (client.read() != '/') {
    client.println(F("error"));
    return;
  }

  String mode = client.readStringUntil('\r');

  if (mode == "input") {
    pinMode(pin, INPUT);
    // Send feedback to client
    client.print(F("Pin D"));
    client.print(pin);
    client.print(F(" configured as INPUT!"));
    return;
  }

  if (mode == "output") {
    pinMode(pin, OUTPUT);
    // Send feedback to client
    client.print(F("Pin D"));
    client.print(pin);
    client.print(F(" configured as OUTPUT!"));
    return;
  }

  client.print(F("error: invalid mode "));
  client.print(mode);
}

When I use this code with REST command for pin 8 on (arduino.local/arduino/digital/8/1), get the lower value of 1.74 Volts at the pin 8 LED anode connection. The LED cathode resistor connection is 38 millivolts.

There are no other connections to the board other than the USB power. I decided to turn on all the pins from 8 to 13 "on". Pins 8, 9, 10, 11, and 12 all produced the low LED light output when the LED is connected to them. However, with a pin 13 connection, the LED has normal brightness along with the board L13 device. There is no problem turning on or off a pin.

I am open to trying any suggestions. Thanks in advance for any help.

Here is a jpg picture attached of the board showing the connections.

Well, the hardware doesn't get much simpler than that, does it?

If you look at the code, when you issue arduino.local/arduino/digital/8/1, it ends up calling digitalWrite(8,1) which should set pin 8 high. No difference from your test sketch there. What is different in the code is that there is no initial call to pinMode() like there is in your test sketch.

The reference page for digitalWrite() includes this comment:

NOTE: If you do not set the pinMode() to OUTPUT, and connect an LED to a pin, when calling digitalWrite(HIGH), the LED may appear dim. Without explicitly setting pinMode(), digitalWrite() will have enabled the internal pull-up resistor, which acts like a large current-limiting resistor.

By not calling pinMode to set the pin to an output, all you are doing is turning on a weak pullup resistor internal to the processor chip. That pullup allows some current to flow out the pin, and is enough to make a floating input appear high, but it doesn't allow enough current to fully light an LED, as you have discovered.

Issuing this REST call before trying to set the pin 8 state should fix it:

http://arduino.local/arduino/mode/8/output

Thank you ShapeShifter. I did one more check. I have tried the ConsolePixel sketch and it worked correctly. It does have pinMode() function in Setup. So your reply does make sense to me. It was my lack of knowledge on the REST commands.

Yes on the simple hardware. I try to keep things simple when trying to learn something new. Thanks again.

I just had the same issue and indeed setting the pinmode to OUTPUT was the solution. Now I have nice and bright LEDs I can turn on and off with a browser. Thanks.