Coder Social home page Coder Social logo

Interrupts about arduino HOT 5 CLOSED

firmata avatar firmata commented on May 14, 2024
Interrupts

from arduino.

Comments (5)

soundanalogous avatar soundanalogous commented on May 14, 2024

Interrupts are currently used behind the scenes. In fact if you use StandardFirmata an Arduino Uno or similar board all of the interrupts are currently in use. PWM uses interrupts, Servo uses interrupts, millis() uses an interrupt, etc. This has been one of the larger problems when trying to scale Firmata. We're working on a new firmata example called ConfigurableFirmata (see the configurable branch and the new utility directory as well as the ConfigurableFirmata example). With ConfigurableFirmata you select features for a particular application rather than the general purpose StandardFirmata approach. This could free up a timer as long as conflicting features are not chosen. For example if you don't need a Servo, then you don't include the Servo class and that frees up a timer or if you don't need PWM you could free up multiple timers. Then we could add a RotaryEncoder feature class, but you'd need to sacrifice an existing feature in order to add a new feature that relies on interrupts so you couldn't use both a rotary encoder and a servo or a rotary encoder and pwm for example.

For more capable boards such as the Due this may not be an issue as there may be additional timers available.

from arduino.

nicolaspanel avatar nicolaspanel commented on May 14, 2024

Thanks a lot ! I will give a try to ConfigurableFirmata then.
Best regards

from arduino.

soundanalogous avatar soundanalogous commented on May 14, 2024

are you specifically interested in a rotary encoder feature or just interrupts in general. If you would like a rotary encoder feature class for configurable firmata that can be added as a feature issue and I'd be happy to accept a pull request, just be aware of this:

"Inside the attached function, delay() won't work and the value returned by millis() will not increment. Serial data received while in the function may be lost. You should declare as volatile any variables that you modify within the attached function."

So an interrupt handler needs to be extremely quick. I'm assuming the issue here is that millis shares the same timer that is allocated for attachInterrupt. The work around is to use another timer, but that would have to be done with avr-gcc syntax, instead of attachInterrupt (which abstracts away a ton of complexity) and would be processor dependent to some extent.

from arduino.

nicolaspanel avatar nicolaspanel commented on May 14, 2024

In fact I'd like to use incremental rotary (or linear) optical encoders with my arduino MEGA, more informations here .
Because I'm not very comfortable with C / C + +, I thought Firmata could be a solution.

Anyway I'll try to follow your advice.
As soon as my encoder works I will send the pull request ;)

from arduino.

nicolaspanel avatar nicolaspanel commented on May 14, 2024

As discussed, I'm trying to implement a new feature to manage encoders (EncoderFeature) but I'm facing a problem I can't deal with :

During sketch compilation, Arduino IDE returns the following error : IS_PIN_INTERRUPT and PIN_TO_INTERRUPT not defined in EncoderFeature.cpp (however these constants are defined in the Boards.h file and everything seems ok)

I tried to include files using double quotes instead of brackets but nothing works

have you ever had this problem?

Note : If you want to reproduce the error, you can use nicolaspanel/Firmata(interrup branch)/test/unit/encoder_test/encoder_test.ino (or any other sketch)

UPDATE (15/07/2013) :
I was finally able to find a (temporary) solution (even if it is not ideal), by redefining macros IS_PIN_INTERRUPT and PIN_TO_INTERRUPT in EncoderFirmata.cpp file .

This implementation uses arduino external interrupts and my first tests are encouraging.
I'll send the pull request once I could test that there are no regressions on the other features.

Best regards

from arduino.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.