Open astagi opened 10 years ago
How can I use the INTERRUPT function in nanpy? Which class do I need to import from nanpy? And how can I use it? Plz show with example if possible because I am a beginner using nanpy
At the moment Nanpy hasn't any interrupt support. I'll schedule it for 0.9.4 release, thanks :)
this means that I cannot use nanpy right now if I want to use for sensor that need interrupt?
Adding interrupt support is not a simple task, I'm still working on the implementation.
What kind of sensor you want to use? Do you have a C library to control it?
Here is the sensor that I need to use http://www.adafruit.com/product/828 This sensor need to use Interrupt
Uh I see. I'll try working on interrupts, anyway I suggest to wrap anything in a library or try fetching the pin value at specific intervals (polling)
On Thu, Feb 26, 2015 at 4:36 PM, KyawZinLatt notifications@github.com wrote:
Here is the sensor that I need to use http://www.adafruit.com/product/828 This sensor need to use Interrupt
— Reply to this email directly or view it on GitHub https://github.com/nanpy/nanpy/issues/14#issuecomment-76199112.
Andrea Stagi (@4stagi) - Develover @Nephila Job profile: http://linkedin.com/in/andreastagi Website: http://4spills.blogspot.it/ Github: http://github.com/astagi
I dont know about wraping anything in a library but for fetching the pin value at specific intervals (poling) will result in, in my opinion, inaccurate data result. Because the sensor need to calculate the amount of water whenever the water comes in. (just my opinion, how do you think?)
https://github.com/adafruit/Adafruit-Flow-Meter/blob/master/Adafruit_FlowMeter.pde This is the example code I am using for this sensor http://www.adafruit.com/product/828 Do you think I can get the correct data without using the Interrupt? I do not know how to change the code without using Interrupt because I am not so familiar with Arduino yet
Yes, interrupts are better in terms of efficiency. I don't know what to suggest, just try :) You can write a class and store pulses using a custom ISR, then store them into a variable and polling with Nanpy, but yeah it's not so easy to do :(
We're talking about Nanpy, that it's "just" a library that calls remote methods from your PC or Raspberry Pi to Arduino. This is not hard to do, you just need to define a protocol that specifies how to call functions/methods, send parameters and receive a return value, but imagine the interrupt case:attaching an interrupt in Arduino is straightforward, you just need to call a function (http://arduino.cc/en/Reference/AttachInterrupt), and this is something that Nanpy can easily do. Using Nanpy you can call something like this:
def blink():
# manage your interrupt
pass
Interrupts.attachInterrupt(0, blink, Interrupts.CHANGE)
The main problem here is the ISR (interrupt service routine) parameter that this function wants: to attach an interrupt you need to define a function and pass its address to the attachInterrupt, also it must be a function without parameters, so within the function you won't know which type of interrupt and/or trigger is managing, so routing is not easy!
The only thing I can do is defining a set of static functions using a combination of interrupts and trigger types, and put them into a matrix of function pointers, something like:
interrupt_routers[0][0] = interrupt_0_change
interrupt_routers[1][0] = interrupt_1_change
interrupt_routers[0][1] = interrupt_0_low
interrupt_routers[1][1] = interrupt_1_low
calling Interrupts.attachInterrupt you will select a function from matrix and then you will call firmware attachInterrupt with the selected function (and the type of the interrupt and the trigger).
void interrupt_0_change() {
Serial.println("0|CHANGE");
}
void interrupt_1_low() {
Serial.println("1|LOW");
}
Trigger types are strings for clarity.
I just need to verify if Serial communication can be used within ISRs. Another big problem is that Nanpy needs to keep listening from Arduino. Each function will notify Nanpy that the interrupt callback has been called and then your python callback will be executed. @ponty any thoughts?
I would use a wrapper code for interrupts and polling which seems to be much easier than rewriting the communication.
Hell guys, im just wondering if some one is working on this, i would love to use nanpy instead of arduino as slave, it is 10 times easier to connect usb than a bunch of cables...
thanks in advance for this effort it will make the community really happy!
I figured out a way to overcome this here
It's 2019 and i cannot find a single example online on interrupt support! , i'm trying to use the code mentioned here https://www.circuitar.com/nanoshields/modules/zero-cross/ using python ?
Bump
@amrsohil — sometimes I think that project is kinda abandoned.
Hi everybody, I created Nanpy a long time ago and now I'm not the active maintainer. I don't know if @ponty is still checking issues and PR. If not I'll try to come back active in the project and help with issues and support requests.
From Cameron's mail:
I'm building a power control unit that uses phase chopping to 'dim' the power to a high power heating element. To do this you fire a triac at a frequency that only allows a portion of the sine wave to reach the load. To do this you need to syncronize the firing of the triac with the sin wave zero crossing: http://en.wikipedia.org/wiki/Phase_fired_controllers
The example line of code we would like to replicate is the following:
where we designate interrupt pin 0 (different pin numbering for the interrupts..) is chosen so that when the signal is RISING it will execute the 'zero_cross_int' function regardless of what else the arduino is doing.