Ethernet Library

Hi Arduino, I am working on a project where I must use sense interrupts and an Ethernet Shield as well. I've done tests using the Arduino Uno and it works perfectly, but when I try to attach the Ethernet Shield, seems that the interrupts can't be detected. I've reviewed the Ethernet Shield webpage and there is sentence that says that the Ethernet library doesn't support interrupts:

The solder jumper marked "INT" can be connected to allow the Arduino board to receive interrupt-driven notification of events from the W5100, but this is not supported by the Ethernet library. The jumper connects the INT pin of the W5100 to digital pin 2 of the Arduino.

So... ¿Hasn't anybody tried to use interrupts with the Ethernet Shield? On the other hand, what's the jumper marked "INT"? I can't see it... Thanks! Anton

I haven't used the interrupt feature, but I know where the jumper is. The INT jumper pads are not marked on my ethernet shield. They are the two pads on the bottom of the shield between pin D0 and the ICSP connector.

I am using a Freetronics Ethermega and use all of its functionality including interupts, ethernet, SD card, etc.


Catweazle NZ

CatweazleNZ: I am using a Freetronics Ethermega and use all of its functionality including interupts, ethernet, SD card, etc.


Catweazle NZ

You do not call any ethernet functions in the ISR function, do you? Many ethernet functions require the delay() function, and it doesn't work while in an ISR.

edit: At least last time I checked. If this is not correct, please let me know.

No I do not - you cannot do anything that relys on timing within an interrupt. Just set a volatile boolean flag within the interrupt and process the interrupt in a procedure that is called within the loop procedure.

Here is some sample code:

#define DC_BedroomPIRInterrupt0_2   0 //interrupt 0 on pin 2
#define DC_LoungePIRInterrupt1_3    1 //interrupt 1 on pin 3
#define DC_HallwayPIRInterrupt2_21  2 //interrupt 2 on pin 21
#define DC_GaragePIRInterrupt3_20   3 //interrupt 3 on pin 20
#define DC_PatioPIRInterrupt4_19    4 //interrupt 4 on pin 19
#define DC_BathroomPIRInterrupt5_18 5 //interrupt 5 on pin 18
#define DC_PIRCount 6

struct TypePIRSensor {
  String PIRSensorName;
  unsigned long LastDetectionTime;
  unsigned long DetectionTimer;

TypePIRSensor G_PIRSensorList[DC_PIRCount];
volatile boolean G_PIRInterruptSet[DC_PIRCount];

 attachInterrupt(DC_LoungePIRInterrupt1_3   ,LoungePIRDetection1_3,RISING);    //Interrupt 1 on pin 3

void LoungePIRDetection1_3() {
  //This is an interrupt
  //Serial.print("Interrupt 1 on 3");
  G_PIRInterruptSet[1] = true;

  ProcessPIRInterrupts();     //Action any PIR interrupts that have come in recently

void ProcessPIRInterrupts() {
  //We use G_PIRGeneralDelay to delay PIR operations
  //- 120 seconds when the system is initialised
  //- 60 seconds when the alarm is activated (not implemented yet)
  //if (CheckSecondsDelay(&G_PIRGeneralDelay, G_PIRGeneralDelaySeconds * 1000) == false)
  const byte c_proc_num = 38;
  if (CheckSecondsDelay(G_PIRGeneralDelay, G_PIRGeneralDelaySeconds * 1000) == false) {
  //Called from loop - we do not process PIR detections when anything else is happening
  for (byte l_pir = 0; l_pir < DC_PIRCount; l_pir++) {
    //We only process PIR interrupts every 30 seconds
    //if (CheckSecondsDelay(&G_PIRSensorList[l_pir].DetectionTimer, 30000) == true) {
    if (CheckSecondsDelay(G_PIRSensorList[l_pir].DetectionTimer, 30000) == true) {
      if (G_PIRInterruptSet[l_pir] == true) {

        //Serial.print("Interrupt ");
        //Serial.print(" ");

        //Initialise the PIR timer
        G_PIRSensorList[l_pir].LastDetectionTime  = Now();
        G_PIRSensorList[l_pir].DetectionTimer = millis();

        //Reset the interrupt flag
        G_PIRInterruptSet[l_pir] = false;

        //reset the PIR LED timer for another 30 secs
        G_PIRLEDTimer = millis();  
        digitalWrite(DC_PIRLedPin, HIGH);

        if (G_HouseAlarmActive == true) {
          //The email heading is automatically written to the activity log
          //The success or failure or the email is automatically written to the activity log
          byte l_result = EmailInitialise(EPSR(E_HOUSE_ALARM_PIR_ALERT_2511));
          if (l_result == 0) {
            EmailLine(EPSR(E_PIR_Sensorco__2480) + G_PIRSensorList[l_pir].PIRSensorName);
            EmailLine(EPSR(E_Dateco__2309)     + DateToString(G_PIRSensorList[l_pir].LastDetectionTime));
            EmailLine(EPSR(E_tbTimeco__2502)   + TimeToHHMMSS(G_PIRSensorList[l_pir].LastDetectionTime)); //Remove tab from this EEPROM constant
      } //only process if the PIR interrupt has operated
    } //skip if 30 secs has not elapsed since last PIR detection 
  } //for each PIR
} //ProcessPIRInterrupts


Catweazle NZ