An archive of community.esquilo.io as of Saturday January 26, 2019.

Hardware Interrupts on Esquilo Air?

gwittie

I am trying to interface to a rotary encoder and my driver code (from an Arduino library) needs hardware interrupts to detect state changes on the A and B encoder pins.

The documentation regarding the Arduino:
"The Arduino interrupt functions are not supported on Esquilo. They are hardware dependent and can cause unexpected behavior on Esquilo’s real-time operating system."

Are there no options like what is available on the Arduino to set hardware pin change interrupt?

Scott_Shumate

We plan to add pin change interrupts to Esquilo through a Squirrel method on the GPIO object. It will work something like this:

intPin <- GPIO(10)
intPin.onchange(function(level) { print("pin changed!\n"); });

Real hardware interrupts, like those from the hardware peripherals, are best handled in C in the OS. Once we get the open source for Esquilo going, you'll be able to do that if you want. We do plan to add asynchronous callbacks to many of the Squirrel classes that control hardware which will be much easier to use in many cases. Here's an example of what we're planning for a read callback on the UART:

uart <- UART(0)
uart.onread(function(c) { print("I got a " + c + "!\n") });

Now that we're over the Kickstarter hump, Patrick and I are currently prioritizing the feature set for the next release of EOS and asynchronous callbacks are pretty high on the list.

gwittie

I am looking forward to getting this additional functionality.
The first proposal appears to be better for my rotary encoder interfacing. I'm not sure how it would work with the second proposal.

softwarejanitor

Is this functionality still on the roadmap? I just ported the Arduino library for the AS3935 Lightning Sensor and some of the example code uses Arduino interrupts. The onchange() looks like it would work perfect for that sensor. Basically with the library I've ported it will set a GPIO pin high when it detects lightning then with this functionality it could be set up to call a function which would read the sensor to get the distance, etc., and then do something useful like an erpc call or just log it to data somewhere.

Scott_Shumate

onchange(), onrising(), and onfalling() were added in EOS 0.3. They all take a function as the parameter that will be called with the GPIO changes. More docs are here : http://www.esquilo.io/docs/#esquilo-library-gpio

softwarejanitor

Excellent! I hadn't found that yet, but it is exactly what I need.