Community
cancel
Showing results for 
Search instead for 
Did you mean: 
PMora5
New Contributor I
1,788 Views

MRAA ISR not working

Hi community,

I'm trying to implement a simple Python program that showcase the ISR functionality of MRAA library. Unfortunately, I'm not able to make it work. I'm using version 1.2.3 of MRAA library and i tried a similar code with nodejs and did not make any progress.

Here is my Python code (it's from a sparkfun tutorial):

import mraa

import time

switch_pin_number=7

led_pin_number=5

def interr_test(args):

led.write(1)

time.sleep(0.2)

led.write(0)

switch = mraa.Gpio(switch_pin_number)

led = mraa.Gpio(led_pin_number)

# Configuring the switch to input & led to output respectively

switch.dir(mraa.DIR_IN)

led.dir(mraa.DIR_OUT)

# The command below enables the interrupt.

switch.isr(mraa.EDGE_RISING, interr_test, interr_test)

# The interrupt is going to be valid for as long as the program runs

# Therefore we setup a dummy "do-nothing" condition

try:

while(1):

pass # "do-nothing" condition

except KeyboardInterrupt:

led.write(0)

exit

Not even the provided example from MRAA Git repository is working with me:

import mraa

import time

import sys

class Counter:

count = 0

c = Counter()

# inside a python interrupt you cannot use 'basic' types so you'll need to use

# objects

def test(gpio):

print("pin " + repr(gpio.getPin(True)) + " = " + repr(gpio.read()))

c.count+=1

pin = 7

if (len(sys.argv) == 2):

try:

pin = int(sys.argv[1], 10)

except ValueError:

printf("Invalid pin " + sys.argv[1])

try:

x = mraa.Gpio(pin)

print("Starting ISR for pin " + repr(pin))

x.dir(mraa.DIR_IN)

x.isr(mraa.EDGE_BOTH, test, x)

var = raw_input("Press ENTER to stop")

x.isrExit()

except ValueError as e:

print(e)

I've also tried with Nodejs, but with no success:

var mraa = require('mraa');

// Set up digital input on MRAA pin 36 (GP14)

var buttonPin = new mraa.Gpio(7);

buttonPin.dir(mraa.DIR_IN);

// Global counter

var num = 0;

// Our interrupt service routine

function serviceRoutine() {

num++;

console.log("BOOP " + num);

}

// Assign the ISR function to the button push

buttonPin.isr(mraa.EDGE_FALLING, serviceRoutine);

// Do nothing while we wait for the ISR

periodicActivity();

function periodicActivity() {

setTimeout(periodicActivity, 1000);

}

Could somebody help with MRAA_ISR on Python, please?

P.S. are there specific pins that we can attach an interrupt?Because I've tested one of the code above with pin 6 and it worked.

Thanks.

Tags (1)
0 Kudos
6 Replies
idata
Community Manager
122 Views

Hi PaulaK,

 

 

We tested your code and it didn't work specifically with pins 7 and 8, and we have the same result with the GitHub example.

 

 

We recommend you to use other pins for these tasks, we tested your code with pins 10, 9, 6, 4, 3, 2 and it worked perfectly. We only tried with these pins so can be the possibility that your code runs with another pin, but we can assure you that your code works.

 

 

I hope you find this information useful,

 

 

Regards,

 

-Leonardo

 

idata
Community Manager
122 Views

Hi PaulaK,

 

 

Was the information useful? Did your code work with other pins? Let us know if you have another problem.

 

 

Regards,

 

-Leonardo
PMora5
New Contributor I
122 Views

Hi Leonardo,

The information was very useful.

I ran some tests and got different results than yours. I'm using MRAA version 1.2.3, and the pins that I can implement ISR are 4,5,6,9 and 11.

Do you think the different result have something to do with my library version?

Best,

Paula

idata
Community Manager
122 Views

Hi PaulaK,

 

 

It is not the library version because I am using the same version of MRAA (1.2.3). I tested your code on 2 different Galileo Gen2 boards and it worked perfectly with all the digital pins that I told you on the first reply plus the pin 11 that you used too.

 

 

I found this http://download.springer.com/static/pdf/456/chp%253A10.1007%252F978-1-4302-6838-3_14.pdf?originUrl=h... document and it says that all the pins supports different modes of interrupts, you can check it on the column "Interrupt Modes", where I can confirm that pins 7 and 8 doesn't work with interrupts. So it is weird that your code doesn't run on the other pins so try to test them again. If they don't work it can be a hardware problem with your Galileo board.

 

 

Let me know if you have another problem.

 

 

Regards,

 

-Leonardo
PMora5
New Contributor I
122 Views

Hi Leonardo,

Thank you so much for the document, it helped a lot.

All pins worked as expected.

Best,

Paula

idata
Community Manager
122 Views

Hi PaulaK,

 

 

It is nice to see that the document helped you.

 

 

If you need something else let us know.

 

 

Regards,

 

-Leonardo
Reply