fhunleth

fhunleth

Co-author of Nerves

Circuits GPIO, I2C and SPI - Use Elixir to control hardware and read sensors

Elixir Circuits is a set of libraries for interacting with hardware. We previously announced Circuits.UART, and now we’re ready to announce Circuits.GPIO, Circuits.I2C, and Circuits.SPI. Here are examples of devices that you can control with the libraries:

  • Circuits.GPIO - buttons, switches, and lights
  • Circuits.I2C - accelerometers, gyroscopes, compasses, some thermometers, displays, lighting and motor controllers and more
  • Circuits.SPI - analog to digital converters, small displays, and custom programs running on FPGAs

These libraries work on Raspberry Pis with Raspbian, other embedded Linux devices and the official Nerves platforms. The libraries also include test backends for compilation and limited testing on development machines.

The Circuits GPIO, I2C, and SPI libraries can be thought of as Elixir ALE 2.0. During the development of Elixir ALE 2.0, we decided to break apart the library based on hardware interface. The APIs are similar to Elixir ALE, but different enough that if you are currently using ALE, we recommend that you review the porting guides in the documentation. All users of Elixir ALE are highly encouraged to update their projects to the appropriate Circuits libraries.

Changes from Elixir ALE 1.0 include:

  1. Circuits GPIO, I2C, and SPI now use NIFs. The performance improvement is noticeable - especially for GPIOs. Yes, there’s a trade off in stability. Based on our experience with ALE, we felt we could achieve a similar level of stability with NIFs and support use cases that were limited by ALE’s performance.
  2. Various API improvements and conveniences like supporting iodata when writing to the I2C and SPI buses and more configuration in open calls to support “glitch-free” initialization
  3. Support for internal pull-ups and pull-downs on GPIOs on Raspberry Pis. This saves you from having to connect a resister to buttons
  4. More user-friendly support for finding devices on I2C buses
  5. Timestamped GPIO interrupt messages to improve pulse measurement precision

Check out https://elixir-circuits.github.io/ for more information.

We really enjoy using the Elixir programming language with hardware and we hope that you will too.

Happy hardware hacking!

Frank Hunleth
Mark Sebald
Matt Ludwigs

Most Liked

fhunleth

fhunleth

Co-author of Nerves

We just released circuits_gpio v0.4.1 which has important updates for Raspbian. All Circuits projects should work well on Raspbian now.

While many of us primarily work with Nerves, we want Circuits to have a great out-of-box experience with Raspbian and other Linux distros running on Raspberry Pis, Beaglebones, etc. If you’re using one of these, please let us know (via GitHub issue) if anything doesn’t work or is confusing.

fhunleth

fhunleth

Co-author of Nerves

Circuits.GPIO 2.1.3 is now available that fixes a serious issue that caused interrupt messages to stop being sent. Please update when you can. I went ahead and marked the hex packages for versions prior to 2.1.3 as invalid since this issue can be quite hard to track down. Thanks to @akoutmos for providing me a Nerves Livebook that reproduced it and @gus who also was able to reproduce and confirm the fix in a different context.

The bug affects anyone using two or more GPIOs in interrupt mode. If you’re not using interrupts or use only one, then upgrading is less important. In practice, the issue occurred when a GenServer using one GPIO in interrupt mode crashes and restarts. Another open GPIO in interrupt mode could stop getting interrupt messages. Internally, the ordering of events matters, so it was possible to get inconsistent outcomes.

fhunleth

fhunleth

Co-author of Nerves

circuits_gpio v0.4.2 is available now. It has an important update that makes GPIO pullup and pulldown settings work with the Raspberry Pi 4. This feature is frequently used by Raspberry Pi hats that have buttons on them.

Where Next?

Popular in Announcing Top

wmnnd
Hi there, for my project DBLSQD, I needed a file storage solution that is a bit more flexible than Arc. Because I thought others might f...
New
pkrawat1
Presenting Aviacommerce, open source e-commerce platform in Elixir Aviacommerce is an open source e-commerce platform in Elixir. We at...
New
woutdp
Hi! I wanted to introduce my latest project LiveSvelte. It allows you to render Svelte inside LiveView with end-to-end reactivity. It’s ...
New
kip
Image is an image processing library for Elixir. It is based upon the fabulous vix library that provides a libvips wrapper for Elixir. I...
622 18934 194
New
michalmuskala
Another small library today. PersistentEts Hex: persistent_ets | Hex GitHub: GitHub - michalmuskala/persistent_ets · GitHub Ets table ...
New
anshuman23
Hello all, I have been working on my proposed project called Tensorflex as part of Google Summer of Code 2018.. Tensorflex can be used f...
New
devonestes
Introducing assertions, the library that helps you write really great test assertions! GitHub: GitHub - devonestes/assertions: Helpful a...
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
wfgilman
I’ve cleaned up and open sourced three financial libraries I was using for my company. They are bindings for the APIs of these three comp...
New
mattludwigs
Grizzly is a library for working with Z-Wave devices. Z-Wave is a low-frequency radio protocol for controlling smart home devices on a me...
New

Other popular topics Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31265 143
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New

We're in Beta

About us Mission Statement