Nano and ENC28J60 stopping after a few minutes

Hope someone can help.
I’m trying to write some code that uses a Nano and a ENC28J60 shield to send data to a computer via UDP. The software works for a while, anywhere from a minute to 30 minutes before it stops, and I have to reset the nano for it to start working again. The stoppage is completely random and I can see an obvious cause. Can anyone see any issues with this code?

#include <EthernetENC.h>

//Device IP & MAC (Variable)
byte mac[] = { 0x2A, 0x01, 0x22, 0x22, 0x20, 0x20 };
IPAddress ip(192, 168, 1, 20);
char remote_IP1[] = "192.168.1.183";
int remote_Port1 = 43041;
EthernetUDP Udp;  //Class variable (Initiates process of UDP)

int EB = 4;
int BS1 = 5;
int BS2 = 6;
int BS4 = 7;


void remote_send(int data)
{
  Udp.beginPacket(remote_IP1, remote_Port1);
  Udp.write(data);
  Udp.endPacket();
  delay(250);
}

void setup()
{
  pinMode(EB, INPUT_PULLUP);
  pinMode(BS1, INPUT_PULLUP);
  pinMode(BS2, INPUT_PULLUP);
  pinMode(BS4, INPUT_PULLUP);

  Ethernet.begin(mac, ip);   // Set up the Ethernet Shield
  Udp.begin(remote_Port1);      // Open a socket for this port
  //Serial.begin(9600);        // Set up serial monitor with PC4
  delay(500);
}

void loop() {

  //Serial.println("");
  if (digitalRead(EB) == 0)
  {
    remote_send(9);
  }
  else
  {
    remote_send(8);
  }
  if (digitalRead(BS1) == 0 && digitalRead(BS2) == 1 && digitalRead(BS4) == 1 )
  {
    remote_send(0);
  }
  else if (digitalRead(BS1) == 0 && digitalRead(BS2) == 1 && digitalRead(BS4) == 0 )
  {
    remote_send(1);
  }
  else if (digitalRead(BS1) == 0 && digitalRead(BS2) == 0 && digitalRead(BS4) == 0 )
  {
    remote_send(2);
  }
  else if (digitalRead(BS1) == 0 && digitalRead(BS2) == 0 && digitalRead(BS4) == 1 )
  {
    remote_send(3);
  }
  else if (digitalRead(BS1) == 1 && digitalRead(BS2) == 0 && digitalRead(BS4) == 1 )
  {
    remote_send(4);
  }
  else if (digitalRead(BS1) == 1 && digitalRead(BS2) == 0 && digitalRead(BS4) == 0 )
  {
    remote_send(5);
  }
  else if (digitalRead(BS1) == 1 && digitalRead(BS2) == 1 && digitalRead(BS4) == 0 )
  {
    remote_send(6);
  }
  else if (digitalRead(BS1) == 1 && digitalRead(BS2) == 1 && digitalRead(BS4) == 1 )
  {
    remote_send(7);
  }
}

The code looks OK to me.

With my telescope It appears you are overheating the Nano regulator causing it to shut down. As soon as it does it cools enough and the Nano comes alive again. Can you post an annotated schematic, I am fairly confident you are powering that with the Nano which is not a power supply. Show all power sources etc and grounds as well.

Data sheet shows it draws 120 to 180 ma while operating. Can your Arduino handle that continuously?

1 Like

I run your sketch for 30 minutes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.