Ethernet Shield Interrupts

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
tlerdrden
 
Posts: 80
Joined: Fri Nov 30, 2012 4:46 pm

Ethernet Shield Interrupts

Post by tlerdrden »

Hi Adafruit,
I've developed a code that uses interrupts in Arduino Uno. I am trying to post the data to a web server, so I am using an Ethernet Shield, but it seems that the Ethernet Shield can't detect those interrupts. Do you know if the Ethernet shield support interrupts?
See the code:

Code: Select all

int rpm;
 unsigned long previTemps = 0;        // Variable per comparar temps previ i actual
 long interval = 60000;           // interval entre operacions (ms)
 
 void setup()
 {
   Serial.begin(9600);
   attachInterrupt(0, rpm_cinta, RISING);
   rpm = 0;
 }
 void loop()
 {
    unsigned long actualTemps = millis();
    if(actualTemps - previTemps > interval) {
    previTemps = actualTemps;   
    Serial.print("Rpm al min= ");
    Serial.println(rpm);
    rpm=0;      // Reset rpm
  }
 }
 void rpm_cinta()
 {
  rpm++; //Add rpm
  //Serial.print("Nova rpm! ");
  Serial.println(rpm);
  }
Thanks,
Anton

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Ethernet Shield Interrupts

Post by adafruit_support_bill »

http://arduino.cc/en/Main/ArduinoEthernetShield
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.

User avatar
tlerdrden
 
Posts: 80
Joined: Fri Nov 30, 2012 4:46 pm

Re: Ethernet Shield Interrupts

Post by tlerdrden »

So... interrupts can't be used with an Ethernet Shield?!

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Ethernet Shield Interrupts

Post by adafruit_support_bill »

If you want interrupts from the shield, install the jumper as described.

If you want interrupts from somewhere else, don't install the jumper.

User avatar
tlerdrden
 
Posts: 80
Joined: Fri Nov 30, 2012 4:46 pm

Re: Ethernet Shield Interrupts

Post by tlerdrden »

Sorry but I'm still confused: The interrupts come from the Arduino Uno, not from the shield... On the other hand, where should I install the INT jumper? Finally, doesn't say the Arduino webpage that the Ethernet library doesn't support interrupts?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Ethernet Shield Interrupts

Post by adafruit_support_bill »

The interrupts come from the Arduino Uno, not from the shield..
No. Your code is looking for external interrupts on pin 2: http://arduino.cc/en/Reference/AttachInterrupt
These are not generated by the Arduino UNO. That is why they are called 'external' interrupts. http://arduino.cc/en/Reference/AttachInterrupt
On the other hand, where should I install the INT jumper?
Where is your interrupt coming from? If it is not coming from the Ethernet shield, you don't need the jumper - or Ethernet library support.

You have an attachInterrupt() and an interrupt handler in your code. These appear to be intended to measure RPM. Where is the RPM pulse coming from? It needs to be connected to pin 2.

I also see that you are doing Serial.println(rpm); in your interrupt handler. You should not do serial I/O in an interrupt handler.

User avatar
tlerdrden
 
Posts: 80
Joined: Fri Nov 30, 2012 4:46 pm

Re: Ethernet Shield Interrupts

Post by tlerdrden »

Okey, I've done the tests with and without the Ethernet Shield with the same code:

Code: Select all

 int rpm;
 unsigned long previTemps = 0;        // Variable per comparar temps previ i actual
 long interval = 60000;           // interval entre operacions (ms)
 
 void setup()
 {
   Serial.begin(9600);
   attachInterrupt(0, rpm_cinta, CHANGE);
   rpm = 0;
 }
 void loop()
 {
    unsigned long actualTemps = millis();
    if(actualTemps - previTemps > interval) {
    //cli(); // Parem interrupcions per tenir temps a enviar les rpm 
    previTemps = actualTemps;   
    //Serial.println(rpm); // BANNED el valor leido BANNED serial.
    Serial.println(rpm);
    rpm=0;      // Reinicialitzem rpm
    //sei();// Tornem a habilitar interrucions
  }
 }
 void rpm_cinta()
 {
  rpm++; //Anem sumant rpm
  //Serial.println(rpm);  
  }
This is what serial comm shows me after some minutes working:
1. Without the Ethernet Shield:
0
0
5
0
0
0
0
With the Ethernet Shield:
0
15
22
22
22
16
19
21
21
21
Definetly, it seems that the code works better without the Ethernet Shield, Why? The wiring is the same with or without the ethernet shield (interrupt connected to digital pin 2). Regarding to the circuit i'm using, it's basically the same of this one: http://www.dave-auld.net/?option=com_co ... Itemid=107
Am I doing something wrong?
Thanks,
Anton

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Ethernet Shield Interrupts

Post by adafruit_support_bill »

Make sure that the int jumper is not installed, so the Ethernet interrupt line does not interfere.

From the photo on the Arduino site, it looks like the jumper is not labeled:
Attachments
Capture.PNG
Capture.PNG (341.1 KiB) Viewed 1161 times

User avatar
tlerdrden
 
Posts: 80
Joined: Fri Nov 30, 2012 4:46 pm

Re: Ethernet Shield Interrupts

Post by tlerdrden »

I have exactly the same of your picture...

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Ethernet Shield Interrupts

Post by adafruit_support_bill »

You have no timing code in your program so it is running 'open-loop'. Without knowing the loop time or the interrupt frequency, it is difficult to know what the output should look like. Clearly you are receiving more interrupts with the shield installed.

If you post a photo showing all your connections, we might be ale to see why it is behaving inconsistently.

User avatar
tlerdrden
 
Posts: 80
Joined: Fri Nov 30, 2012 4:46 pm

Re: Ethernet Shield Interrupts

Post by tlerdrden »

Here it goes:
Attachments
Dwg.JPG
Dwg.JPG (146.28 KiB) Viewed 1151 times

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Ethernet Shield Interrupts

Post by adafruit_support_bill »

I can't see in the photo. Is there a pullup resistor on the interrupt line?

Without a pullup, any noise on the line could result in false interrupts.

User avatar
tlerdrden
 
Posts: 80
Joined: Fri Nov 30, 2012 4:46 pm

Re: Ethernet Shield Interrupts

Post by tlerdrden »

It works!
The pull up resistor was wired, but i've connected a new resistor between the LED and the Digital input of my Arduino. See the attached dwg.These are the results showed in the Serial COM with and without the Arduino Ethernet Shield:
0
0
0
0
0
0
0
Thanks a lot!
Attachments
foto (1).JPG
foto (1).JPG (114.35 KiB) Viewed 1137 times

User avatar
tlerdrden
 
Posts: 80
Joined: Fri Nov 30, 2012 4:46 pm

Re: Ethernet Shield Interrupts

Post by tlerdrden »

What is still dificult to control is the number of interrupts when i push the pushbutton...For instance, I would push the button once and detect just one interruption, but it detects more, depending on the time the button is pushed...Anyway, it works for my application.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Ethernet Shield Interrupts

Post by adafruit_support_bill »

Pushbuttons have 'contact bounce' which can result in extra interrupts.

You can 'debounce' the button using a filter circuit. Or you can just disable interrupts for for a short time after the press is detected.
http://www.allaboutcircuits.com/vol_4/chpt_4/4.html

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”