2

I have successfully wrote a sketch for Ethernet Shield and Arduino. If I plug it into computer's USB, it works.

But if I plug into any other power source, like USB power adapter from iPhone or laboratory power source to power socket -- it doesn't work.

LEDs are doing various strange bursts, very different than if powered from computer.

What can be the reason?

UPDATE

I have updated sketch so that it doesn't refer serial:

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
// B6-62-C5-CC-48-81
byte mac[] = {
  0xB6, 0x62, 0xC5, 0xCC, 0x48, 0x81
};
IPAddress ip(192, 168, 10, 90);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

long requestCount = 0;
long upCounts[] = {0, 0, 0, 0, 0, 0};
long downCounts[] = {0, 0, 0, 0, 0, 0};
int currVals[] = {0, 0, 0, 0, 0, 0};
int prevStats[]= {0, 0, 0, 0, 0, 0};
int upThreshold = 1024-32;
int downThreshold = 32;



void setup() {
  // Open serial communications and wait for port to open:
//  Serial.begin(9600);
//  while (!Serial) {
//    ; // wait for serial port to connect. Needed for native USB port only
//  }


  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
//  Serial.print("server is at ");
//  Serial.println(Ethernet.localIP());
}


void loop() {

  for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
    int sensorReading = analogRead(analogChannel);
    currVals[analogChannel] = sensorReading;

    if( prevStats[analogChannel] == 0 ) {
      if( currVals[analogChannel] >= upThreshold ) {
        prevStats[analogChannel] = 1;
        if( requestCount>0 ) {
          upCounts[analogChannel] ++;
        }
      }
    }
    else {
      if( currVals[analogChannel] < downThreshold ) {
        prevStats[analogChannel] = 0;
        if( requestCount>0 ) {
          downCounts[analogChannel] ++;
        }
      }
    }
  }


  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    //Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        //Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 2");  // refresh the page automatically every 2 sec

          client.print("X-Inthemoon-Request-Count: ");  
          client.println(requestCount);
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            client.print("X-Inthemoon-Analog-To-Digital: ");  
            client.print("Channel=");
            client.print(analogChannel);
            client.print("; ");
            client.print("Min-Value=0; ");
            client.print("Max-Value=1023; ");
            client.print("Value=");
            client.print(currVals[analogChannel]);
            client.print("; ");
            client.print("Up-Change-Count=");
            client.print(upCounts[analogChannel]);
            client.print("; ");
            client.print("Down-Change-Count=");
            client.print(downCounts[analogChannel]);
            client.println(";");
          }


          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          // output the value of each analog input pin
          client.print("Was counting: ");
          if( requestCount>0 ) {
            client.print("YES (request count is ");
            client.print(requestCount);
            client.print(")");
          }
          else {
            client.print("NO");
          }
          client.println("<br />");
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(currVals[analogChannel]);
            client.print(", up changes count is ");
            client.print(upCounts[analogChannel]);
            client.print(", and down changes count is ");
            client.print(downCounts[analogChannel]);
            client.println("<br />");
          }
          client.println("</html>");

          requestCount++;
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    //Serial.println("client disconnected");
  }
}

The situation is the same:

https://youtu.be/vypaNOxZ5KI

It is plugged into Samsung tablet USB power of 2A, so insufficient current is unprobable reason.

UPDATE 2

I also tried to remove inclusion of SPI.h

UPDATE 3

If I connect another Arduino board (but of the same vendor, it is from AliExpress), the behavior is the same.

UPDATE 4

I have compiled blink example and it works in any combination. If I connect Ethernet shield, then it blinks with both LEDs on Arduino board and on Ethernet shield.

UPDATE 5

I bought different Ethernet Board and it doesn't work too.

Please help. Have anybody ever powering Arduino + Ethernet not from USB?

  • 1
    This is basically unanswerable. Either your software requires communication from a host PC to function, or else some part of the setup is not what it is described to be. – Chris Stratton Aug 26 '16 at 1:39
  • Software is just Ethernet sample from here: arduino.cc/en/Tutorial/WebServer It is true that is contains writing to serial. Can this explain my situation? – Dims Aug 26 '16 at 8:44
  • Is the Ethernet shield status LEDs the same if you disconnect the network cable? – Mikael Patel Aug 26 '16 at 15:50
  • @MikaelPatel definitely not. If no Ethernet cable, then only power LED shines. If ETH cable connected, then other green LED bursting. But not the same way as when board works (if connect computer USB). – Dims Aug 26 '16 at 19:49
  • 1
    Have anybody ever powering Arduino + Ethernet not from USB? - yes I have one sitting around plugged into a wall-wart and connected to the (ethernet) network. It certainly works in that configuration. – Nick Gammon Sep 24 '16 at 2:14
2

Sorry I didn't see this earlier but I suspect you have a bad earth, because:

  1. It works with the PC
  2. You are using a wall wart
  3. You are wiring your board to another electrical source (Ethernet)
  4. You are saying the LEDs are flashing differently.

Run a lead from the GND connector on the board to an Earth point.
(It might be the Ethernet that is at fault, but unless you have access to the switch I don't know how you could ground that properly)

  • Indeed, bring the board over to a friend's house, check if it also happens there. – Paul Jul 26 '17 at 4:56
  • Good idea, will try! – Dims Oct 10 '18 at 9:47
0

There should be absolutely no difference between powering your Arduino from a computer USB port or a wall plug, especially if you keep your serial monitor closed.

So this is the debug procedure I would advice:

  1. disconnect the shield
  2. connect the Arduino and upload a firmware with

    • no calls to Serial, but the most important one you must avoid is the while loop in the setup() function

    • a short blink of an LED (you can use the onboard one, if you wish so) every time the loop() function iterates

  3. power your Arduino (without the shield attached) from your computer with no serial consoles and check the LED blinks at constant intervals
  4. power your Arduino (without the shield attached) from your wall plug and check the LED blinks at constant intervals
  5. disconnect the wall plug, attach the ethernet shield without an ethernet cable, reconnect the wall plug and check the debug LED and the LEDs on the shield are all blinking as expected
  6. plug the ethernet cable and hit the Arduino reset button and check all the LEDs are blinking as expected

Possible faults i can currently think of:

  • STEP 3
    • the firmware running on your board is incorrect: double check the compilation and upload process has completed successfully and you have no error in the Arduino IDE console
  • STEP 4
    • the firmware still contains some code which expects some input from the serial console: start opening the libraries you use in search for such code
    • the voltage measured at the board between GND and 5V pins is insufficient and the board browns out: check the voltage is above 4.5V and the USB cable is not damaged or faulty
  • STEP 5
    • some of the code inside the ethernet shield library is trying to read data from a serial connection: check the library code again
    • some of the components on the ethernet shield are faulty and they are pulling enough current from your wall wart to actually make your board go into protection (hard to believe, a 2A serious wall plug should be much better power source than your PC)
  • STEP 6
    • same as for step 5, but your ethernet cable might be playing a role

This might not be an answer per se, but it might help you find out the answer you need.

  • This won't work, the code is designed to run Ethernet shield and may be blocking forever at some point if the shield is not present. Moreover Dims already wrote that a simple blink code works with and without Shield. The problem only seem to occur when using the ethernet library. – Julien Sep 28 '16 at 19:28
  • @Julien i didn't open the Ethernet library, so I can't state you are either right nor wrong when you say may be blocking forever, but I believe he can give a try to this. Also, he said the board is blinking with the blink sketch, but I am suggesting to use a LED pulse at the beginning of his loop() function as a debug measure.... something you also suggested in the comments. – Roberto Lo Giacco Sep 29 '16 at 15:16
0

Maybe your laboratory power source is of poor quality. A computer's USB is a good power source. Try using a pack of 4x1.5v AA batteries. I have use this setup with arduino+ethernet shield+cheap servo.

  • Tried eveything, including this. – Dims Jan 22 '18 at 11:05
  • Maybe the alimentation part of your arduino is broken. Do you have another one to test ? – BOC Jan 22 '18 at 16:52
-5

I assume that your power adapter or whatever power source you are using ouputs higher amps than the board can handle:

The Arduino/Genuino Uno has a resettable polyfuse that protects your computer's USB ports from shorts and overcurrent. Although most computers provide their own internal protection, the fuse provides an extra layer of protection. If more than 500 mA is applied to the USB port, the fuse will automatically break the connection until the short or overload is removed.

That means that your USB can't exceed 500mA, which power adapters do. Also:

External (non-USB) power can come either from an AC-to-DC adapter (wall-wart) or battery

So, either you power your board through USB connected to a computer, or you can use the external power adapter. However, you should consider also this:

The board can operate on an external supply from 6 to 20 volts. If supplied with less than 7V, however, the 5V pin may supply less than five volts and the board may become unstable. If using more than 12V, the voltage regulator may overheat and damage the board. The recommended range is 7 to 12 volts.

Considering all of the above, I believe that I answered your question. Have a nice day.

  • 2
    Sorry, but this represents a complete misunderstanding of electric circuit principles. A 5v power supply rated for high current is able to keep supplying 5v to a load which draws high current. But it still only has 5v of potential to force current through a load - a load desgined to operate on a 5v supply will not draw excessive current unless there is something wrong with that load that is causing it to operate other than as designed. – Chris Stratton Aug 26 '16 at 1:36
  • 1
    This answer is like saying that the power station outputs more amps than the light bulb in your house can handle. The light bulb draws what it needs. The power station doesn't "push" all its generating capacity into it. – Nick Gammon Sep 24 '16 at 2:11
  • 1
    complete misunderstanding of electric circuit principles – Julien Sep 25 '16 at 8:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.