Having trouble with ENC28J60 - Link, but no connection.

Hi all,

I hope that some of you can help me with the following topic:

I am now doing a project to control an SetTopBox Via Ethernet.

I am using a Arduino Nano (Atmega328), and a ENC28J60.

Once i connect the Arduino to the ethernet module, i go a link (The green light goes on, and the orange one, flashes sometimes).

Since I am in a company, using the internal Network, the issue could be caused due to some firewall or something like a network equipment, locking the connection. After aligning with my network management team, i found out that there was no restrictions in the network.

I used to have this modules, and uploaded code working, but no longer! Can someone help me?! :drooling_face:

[Other info]

Arduino IDE v1.6.11

Libraries in use:

  • UIPEthernet library
  • IRremote

My Source Code:
#include <IRremote.h>
#include <SPI.h>
#include <UIPEthernet.h>
#include <stdio.h>
#include <string.h>

byte mac = { 0xEF, 0x23, 0x31, 0x30, 0xEA, 0xF7 }; //ethernet shield mac address //EF233130E6F7
byte ip = { 172, 16, 107, 44 }; // arduino IP in lan
byte gateway = { 172, 16, 107, 62 }; // internet access via router
byte subnet = { 255, 255, 255, 192 }; //subnet mask
char codeChar[50];
char functionName[50];
double codeDouble;
int i, cont;
String readString;

EthernetServer server(80); //server port

IRsend irsend;

/*
const int sensorMin = 500; // sensor minimum
const int sensorMax = 1024; // sensor maximum
int LDR = 0; //analog pin to which LDR is connected, here we set it to 0 so it means A0
int LDRValue = 0; //that’s a variable to store LDR values
int light_sensitivity = 100; //This is the approx value of light surrounding your LDR
*/

// ‘Sintax’ da função de envio de codigos Ir e nome da função via URL.
// 172.16.107.4:80/?func=funcanaammemmee&code=0xd565
// IP:Port/?func=nomedafunção&code=0xCodigo da tecla

void setup() {
pinMode(6, OUTPUT); //pin FREE led
pinMode(7, OUTPUT); //pin LOCKED led
pinMode(8, OUTPUT); //pin selected to control
digitalWrite(6, HIGH);
//start Ethernet
Ethernet.begin(mac, ip, gateway, gateway, subnet);
server.begin();

//enable serial data print
Serial.begin(9600);
Serial.println(“Start Servidor Arduino!”); // so I can keep track of what is loaded
}

void loop() {
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {

char c = client.read();
//read char by char HTTP request
if (readString.length() < 20) {
//store characters to string
readString += c;
Serial.print(c);
}

//if HTTP request has ended
if (c == ‘\n’) {

//querystring
cont = 0;
for (i = readString.indexOf(“code=”) + strlen(“code=”) ; ; i++) {
if (readString == ’ ’ || readString == ‘&’)
* break;*
_ codeChar[cont++] = readString*;
}
Serial.println(codeChar);
if ((int) strtol(codeChar, (char *)NULL, 10) == 1000) {
digitalWrite(8, HIGH);

* Serial.println(“Liga STB”);
} else if ((int) strtol(codeChar, (char *)NULL, 10) == 2000) {
digitalWrite(8, LOW);

* Serial.println(“Desliga STB”);
} else if ((int) strtol(codeChar, (char *)NULL, 10) == 3000) {
digitalWrite(8, LOW);

* delay(1000);
digitalWrite(8, HIGH);
Serial.println(“Reiniciou STB”);
delay(2000);
Serial.println(“STB Ligada”);
} else {
Serial.println(“Comando IR”);
Serial.print("codigo: “);
Serial.println(codeChar);
processacomando((int) strtol(codeChar, (char *)NULL, 10));
}

if ((int) strtol(codeChar, (char *)NULL, 10) == 5000 && digitalRead(6) == 0 && digitalRead(7) == 1) { // Recebe 5000 - Se locked - Unlock_
_ digitalWrite(6, HIGH);
delay(50);
digitalWrite(7, LOW);
Serial.println(‘Arduino Unlocked - Led verde Aceso’);
} else if ((int) strtol(codeChar, (char *)NULL, 10) == 5000 && digitalRead(6) == 1 && digitalRead(7) == 0) { // Recebe 5000 - Se unlocked - Lock_
_ digitalWrite(6, LOW);

* delay(50);
digitalWrite(7, HIGH);
Serial.println(‘Arduino Locked - Led vermelho Aceso’);
} else if (((int) strtol(codeChar, (char *)NULL, 10) == 5000 && digitalRead(6) == 1 && digitalRead(7) == 1)) {
digitalWrite(6, HIGH);

* delay(50);
digitalWrite(7, LOW);
Serial.println(‘ERRO! Leds de Estado Incoerentes - Arduino Now Free!’);
} else if (((int) strtol(codeChar, (char *)NULL, 10) == 5000 && digitalRead(6) == 0 && digitalRead(7) == 0)) {
digitalWrite(6, HIGH);

* Serial.println(‘Led Verde Inicializado’);
}
Serial.println(readString); //print to serial monitor for debuging*
* //now output HTML data header*
* if (readString.indexOf(’?’) >= 0) { //don’t send new page*
* client.println(“HTTP/1.1 200 OK”);
}
delay(1);
//stopping client*
* client.stop();
//clearing string for next read*
* readString = “”;
}
}
}
}
// ----- FIRE SENSOR CODE ------//
/

* // read the sensor on analog A0:
int sensorReading = analogRead(A0);
// map the sensor range (four options):
// ex: ‘long int map(long int, long int, long int, long int, long int)’
int range = map(sensorReading, sensorMin, sensorMax, 0, 3);
// range value:
switch (range) {
case 2: // No fire detected.
Serial.println(“No Fire”);
break;
default:
Serial.println(“Fire!!!”);
digitalWrite(8, LOW);
}
delay(1);
/
// ----- COLOR DETECTION CODE ----- //

/
COMPLETE CODE!!! CAREFULL!!!
int OutPut= 10;//naming pin10 of uno as output*
* unsigned int frequency = 0;
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins*
* LiquidCrystal lcd(8, 9, 7, 11, 12, 13);//RS,EN,D4,D5,D6,D7*
* void setup()
{
// set up the LCD’s number of columns and rows*
* lcd.begin(16, 2);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);//PINS 2, 3,4,5 as OUTPUT*
* pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(10, INPUT);//PIN 10 as input*
* digitalWrite(2,HIGH);
digitalWrite(3,LOW);//setting frequency selection to 20%
}
void loop()
{
lcd.print(“R=”);//printing name*
* digitalWrite(4,LOW);
digitalWrite(5,LOW);//setting for RED color sensor*
* frequency = pulseIn(OutPut, LOW);//reading frequency*
* lcd.print(frequency);//printing RED color frequency*
* lcd.print(” “);
lcd.setCursor(7, 0);//moving courser to position 7*
* delay(500);
lcd.print(“B=”);// printing name*
* digitalWrite(4,LOW);
digitalWrite(5,HIGH);// setting for BLUE color sensor*
* frequency = pulseIn(OutPut, LOW);// reading frequency*
* lcd.print(frequency);// printing BLUE color frequency*
* lcd.print(” “);
lcd.setCursor(0, 1);
delay(500);
lcd.print(“G=”);// printing name*
* digitalWrite(4,HIGH);
digitalWrite(5,HIGH);// setting for GREEN color sensor*
* frequency = pulseIn(OutPut, LOW);// reading frequency*
* lcd.print(frequency);// printing GREEN color frequency*
* lcd.print(” ");
lcd.setCursor(0, 0);
delay(500);
}
/
}

void processacomando(double ircode) {
* irsend.sendRC5(ircode, 12);
delay(40);
}
//Do not worry about the comments trough the code, they are in portuguese, the ones not in portugueses are incorrect*_