Jim

Jim

Is it possible to handle hardware interrupts from Elixir?

I ask because I need to respond to a button press. If I was coding to bare metal I would write an ISR, but of course there is BEAM sitting on Debian. If I can’t do an ISR can I have a process block until the hardware changes?

Thanks!

Showing Posts 1 to 10

NobbZ

NobbZ

Short: No you can’t.

Longer: you might be able to achieve your goal using ports and cports. External programs that can be written in any language and communicate with the BEAM. You can read these messages as if they were from another process using a receive block.

I do not think that you can use NIFs properly here.

Also, since I’m on a mobile I can’t search appropriate links right now.

Jim

Jim OP

Thanks for the reply and info @NobbZ. What is an NIF?

NobbZ

NobbZ

Natively implemented function.

xpg

xpg

When sitting in user-space on a Linux system, I think GPIO sysfs is the way to go about it.

elixir_ale provides a nice Elixir abstraction on top of GPIO sysfs. I haven’t had time to play around with it yet, but from its documentation and the example it looks fairly straight forward.

Jim

Jim OP

The elixir_ale solution seems to be exactly what I need. It’s a soft real time system so I don’t need to process the interrupt the microsecond it is triggered. As long as I get it within say 100 or 200 ms that will do very well.

jsimmonds2

jsimmonds2

I really miss Node,js events :wink:

In the latest ElixirALE.I2C is it possible (at all) to set up an async. message on a hardware interrupt ?

Thanks (-:

[edit] My platform is RaspberryPi 3 B+ with Nerves package nerves_system_rpi3 providing Linux 4.14.71

GregMefford

GregMefford

Oh, did you mean specifically send an async message when you receive a certain I2C message? For that, I think you’d want to set up your own worker that polls for I2C data and sends them as messages on whatever conditions you need.

fhunleth

fhunleth

Co-author of Nerves

I think that John is connecting his Pi to a chip that has an I2C interface and a separate interrupt signal that notifies the Pi when data is ready. Lots of chips do that since I2C doesn’t support async notifications. The pattern is to use ElixirALE.GPIO to detect the interrupt and send a message. Then in the message handler function, call into ElixirALE.I2C to read the new data.

Just as an aside, it would be cool if ElixirALE.I2C could do this for you. The problem is that the command you send to read the chip on interrupt depends on the chip. The updated I2C protocol, I3C, lets devices send interrupts w/o a separate GPIO, so it should be possible to do something nicer when it becomes available.

jsimmonds2

jsimmonds2

Thanks for those helpful comments. I did think about my situation more thoroughly last night and I realized that the ElixirALE.GPIO port converts pin state changes to messages, and my I2C chip (LPS25HB sensor) could be wired to a dedicated GPIO pin for that purpose.

Under the hood, on the RPi3B+, how do GPIO interrupts reach the ALE GPIO Port process ? Signals or OS Events ?

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews