2

I have arduino uno + ethernet shield + 9V/200mA adapter. I am trying to send some data with HTTP connection. When it's connected to USB it works perfectly, but when I plugged out USB, hangs (after less than a minute, it stops pinging).

I have tried this:

EthernetClient.cpp

int EthernetClient::connect(IPAddress ip, uint16_t port) {
  if (_sock != MAX_SOCK_NUM)
    return 0; // i changed to -1  as suggested on previous link

  for (int i = 0; i < MAX_SOCK_NUM; i++) {
    uint8_t s = socketStatus(i);
    if (s == SnSR::CLOSED || s == SnSR::FIN_WAIT || s == SnSR::CLOSE_WAIT) {
      _sock = i;
      break;
    }
  }

and also example from library Examples-library-WebClientRepeating, but I get the same problem as in my code. Is my adapter too weak?

This code is from Example WebClientRepeating:

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED    };

// fill in your Domain Name Server address here:
IPAddress ip(193, 77, 60, 66);
IPAddress subnet(255, 255, 255, 0);
IPAddress gateway(193, 77, 60, 7);
IPAddress myDns(193, 77, 60, 213);

EthernetClient client;

char server[] = "www.arduino.cc";
//IPAddress server(64,131,82,241);

unsigned long lastConnectionTime = 0; // last time you connected to the server, in millisecond
const unsigned long postingInterval = 10L * 1000L; // delay between updates, in milliseconds
// the "L" is needed to use long type numbers

void setup() {
  // start serial port:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  // give the ethernet module time to boot up:
  delay(1000);
  // start the Ethernet connection using a fixed IP address and DNS server:
  Ethernet.begin(mac, ip, myDns, gateway, subnet);

  // print the Ethernet board/shield's IP address:
  Serial.print("My IP address: ");
  Serial.println(Ethernet.localIP());
}

void loop() {
  if (client.available()) {
    char c = client.read();
    Serial.write(c);
  }

  // if ten seconds have passed since your last connection, then connect again and send data:      
  if (millis() - lastConnectionTime > postingInterval) {
    httpRequest();
  }    
}

// this method makes a HTTP connection to the server:
void httpRequest() {
  // close any connection before send a new request.
  // This will free the socket on the WiFi shield
  client.stop();

  // if there's a successful connection:
  if (client.connect(server, 80)) {
    Serial.println("connecting...");
    // send the HTTP PUT request:
    client.println("GET /latest.txt HTTP/1.1");
    client.println("Host: www.arduino.cc");
    client.println("User-Agent: arduino-ethernet");
    client.println("Connection: close");
    client.println();

    // note the time that the connection was made:
    lastConnectionTime = millis();
  }
  else {
    // if you couldn't make a connection:
    Serial.println("connection failed");
  }
}

EDIT 1: Also when I plug USB in its start working with 9V power adapter.

4
  • Is the voltage regulator on the Arduino very hot, or the external 9V adapter very hot, when it stops pinging? Maybe it is likely one or the other failing. Are the LEDs on the Arduino and shield still on? It might be worth blinking a LED to ensure you can see what is working.
    – gbulmer
    Dec 23 '15 at 11:20
  • Arduino voltage regulator is not so hot, it's touchable. Leds on arduino are ok but on ethernet shield is only first one on, data lights are off.
    – JanOlMajti
    Dec 23 '15 at 11:46
  • Then it is probably not power a power problem. Can you measure the voltage on the Arduino's 5V pin? For example, have you a multi-meter? That would confirm or disprove the power supply theory.
    – gbulmer
    Dec 23 '15 at 12:39
  • I'm pleased it's working and stable, even if my answer was wrong :-) Merry Christmas!
    – gbulmer
    Dec 23 '15 at 15:32
2

The problem is that when you are using the external 9V power supply, you are relying on the Arduino's on-board regulator to provide the 5V power supply to both the Arduino and the Ethernet shield. This regulator has very limited current capacity — much less than the 500 mA that's available from a PC's USB port — and you're overloading it.

To avoid this problem, you should use a 5V plug pack with a USB connector to power your system.

2
  • I think your description of the cause is slightly incomplete, and so may be misleading for others. Tests show the Arduino UNO's on-board regulator can supply 500mA at 9V, see the Arduino UNO temperature vs current graphs FTDI NerO. It should be easy for the OP to diagnose this as the voltage regulator should be very hot. If this is the case, I agree your solution should work.
    – gbulmer
    Dec 23 '15 at 11:32
  • Arduino voltage regulator was hot, it was in box. When i get Arduino out, it starts working. So i change 9V adapter With 5V 1A and now is working fine. I'll test it over night. Thanks
    – JanOlMajti
    Dec 23 '15 at 12:39
1

It may be that, for some reason, the library thinks Serial communication is working, but when the buffer of unsent characters gets full, it hangs waiting to complete a Serial.print() or Serial.println().

So, try commenting out all use of Serial.

For example change

  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

to

  /*
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  */

and Serial.println(...); to // Serial.println(...);

This might happen if the system is started with USB working, and then USB is unplugged.

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.