Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interrupts #63

Closed
nicolaspanel opened this issue Jun 12, 2013 · 5 comments
Closed

Interrupts #63

nicolaspanel opened this issue Jun 12, 2013 · 5 comments

Comments

@nicolaspanel
Copy link

It seems that current version does not handle interrupts (to manage encoders for example), is it planned in your roadmap?

@soundanalogous
Copy link
Member

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.

@nicolaspanel
Copy link
Author

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

@soundanalogous
Copy link
Member

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.

@nicolaspanel nicolaspanel reopened this Jun 13, 2013
@nicolaspanel
Copy link
Author

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 ;)

@nicolaspanel
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants