There is the AtomVM, a (mini)BEAM for microcontrollers https://www.atomvm.net/
There is also integration for Elixir and AtomVM.
Could you have a Pi on Nerves talking to microcontrollers?
I've never really worked with hardware but this all looks fascinating.