Pages: [1]   Go Down
Author Topic: First time using interrupts  (Read 834 times)
0 Members and 1 Guest are viewing this topic.
South East England
Offline Offline
Newbie
*
Karma: 0
Posts: 37
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok this is my first time using interrupts so go easy on me
I am going to be building a weather sation using the sparkfun weather meters, fine.

I need to use interrupts, fine.

Firstly, assume arduino Mega 2560

what I don't understand is the Arduino documentation..

External Interrupts: 2 (interrupt 0), 3 (interrupt 1), 18 (interrupt 5), 19 (interrupt 4), 20 (interrupt 3), and 21 (interrupt 2)

am i right in thinking that, the number outside the brackets is the physical pin number
and the interrupt number (the one in brackets) is the number i use in the attachInterrupt method

for example to set 2 interrupts
Code:
attachInterrupt(0, myFunc, FALLING)    // sensor attached to pin 2
attachInterrupt(1, myOtherFunc, FALLING)    // sensor attached to pin 3

if i am wrong, can someone please correct me
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 508
Posts: 31389
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
am i right in thinking that, the number outside the brackets is the physical pin number
and the interrupt number (the one in brackets) is the number i use in the attachInterrupt method

Yes that is correct.  smiley
Logged

South East England
Offline Offline
Newbie
*
Karma: 0
Posts: 37
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

AH HA!
I love it when I'm right!

now all i need is the sparkfun delivery to arrive, and a 1 10KOhm resistor and I can have a play with the wiring :S

there is some sample code I am going to base my work on (why reinvent the wheel?)

and has the following wiring diagram

Code:
                       +5V
                        |
                        <
                        >     10K
                        <   Resistor
                        <
                        >
                        |
 Analog Pin 5-----|
                        |
                        -------| To weather vane
                                | (mystery resistance)
                   -----------|
                   |
                   |
                 -----
                  ---
                   -

am i right in thinking, i can take a feed from the 5+v pin on the arduino, put my resistor in line, then split the line one going to pin 5 (or my chosen pin) and the other to the weather vane.

and GND just goes direct to the Arduino GND pin?

if so, can someone explain how/why this works? so that I understand please?
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 508
Posts: 31389
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes right again. However you don't need to wait for delivery of your resistor. Just wire it up without and enable the internal pull up resistor, by doing a digithaWrite high to your input pin.
Logged

South East England
Offline Offline
Newbie
*
Karma: 0
Posts: 37
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

do you mean didtalWrite? even though its an analog input?
Logged

New Hampshire
Offline Offline
God Member
*****
Karma: 13
Posts: 779
There are 10 kinds of people, those who know binary, and those who don't.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

do you mean didtalWrite? even though its an analog input?

Analog inputs cannot function as interrupts.  What exactly are you trying to accomplish here?

Are you looking for an interrupt to occur when a particular analog signal crosses a certain threshold?  If so, you need to set up an external comparator as the source to a digital input that serves as your interrupt.

That, or code a 'software' interrupt that continually reads an Analog input and initiates some function when said threshold is crossed.

Or are you doing something else entirely?
Logged


Manchester (England England)
Online Online
Brattain Member
*****
Karma: 508
Posts: 31389
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

While I agree with the above. Yes the internal pullups work on the analogue inputs as well.
Logged

South East England
Offline Offline
Newbie
*
Karma: 0
Posts: 37
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think you have the 2 use cases mixed up. The resistor is not for an interrupt. It is for a more passive instrument.

And will be connected to analog pin 5, in which case how/why digital write? Its to an analog pin
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 508
Posts: 31389
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Analogue inputs will work like digital ones just use the numbers pin 14 for input 0, pin 15 for input 1 and so on.
So yes for analogue input 5 use pin 19.
Logged

Pages: [1]   Go Up
Jump to: