Giter VIP home page Giter VIP logo

nerves_neopixel's Introduction

Nerves.Neopixel

Drive WS2812B "NeoPixel" RGB LED strips from a Raspberry Pi using Elixir!

NeoPixel strip driven by a Raspberry Pi

This project was designed to make it easy to drive a string of AdaFruit NeoPixels from a Raspberry Pi using Nerves. The code would probably also work outside of Nerves with minor modifications to the Makefile, if you so desire.

Unfortunately, since the Raspberry Pi has 3.3V I/O outputs and the NeoPixels require 5V I/O input, a little piece of hardware is required. You can read more about this in my blog post about the project.

Installation

  1. Add it to your list of dependencies in mix.exs:

    def deps do
      [{:nerves_neopixel, "~> 0.3.1"}]
    end
  2. Ensure it is started before your application:

    def application do
      [applications: [:nerves_neopixel]]
    end

Usage

Supervision trees and an Elixir Port are used to maintain fault-tolerance when interfacing with the low-level driver, which is written in C. To drive an NeoPixel strip, you just have to configure which GPIO pin to use and how many NeoPixels are in the strip by passing the configuration settings to Nerves.NeoPixel.start_link.

Once the process is started, you can call the Nerves.Neopixel.render function with a list of tuples representing the pixel data, along with the overall intensity, as follows:

alias Nerves.Neopixel
ch0_config = [pin: 18, count: 3]
ch1_config = [pin: 19, count: 3]
{:ok, pid} = Neopixel.start_link(ch0_config, ch1_config)

channel = 0
intensity = 127
data = [
  {255, 0, 0},
  {0, 255, 0},
  {0, 0, 255},
]
Neopixel.render(channel, {intensity, data})

nerves_neopixel's People

Contributors

djellemah avatar erauer avatar gregmefford avatar mobileoverlord avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.