Rustle

Rustle is a gem that aims to allow you to control an addressable RGB LED strip in Ruby (using an Arduino as a middleman). Run it on your computer, a Raspberry Pi, or whatever you want! All you need is a strip, an Arduino, and a serial connection.

Installation

It's pretty easy.

$ gem install rustle

Getting Started

1. Set up your Arduino

Upload the basic.ino sketch to your Arduino. Make sure that you take a look at the file first and modify it to suit your physical setup.

Gotcha: the Arduino resets itself upon any serial communication. We are currently considering switching to the firmata protocol in order to work around this problem. For now, you will need to place a 10μF capacitor between the RESET and GND pins on your Arduino after uploading the sketch if you want to use Rustle from a static Ruby script.

The sketch itself is still being worked on. Our goal, in the future, is to simply allow you to call rustle arduino:prepare to automatically generate and upload the sketch (with the number of LEDs, frames per second, etc) to the Arduino using Ino.

2. Connect to the Arduino

The majority of Rustle's actions are performed by calling methods on a receiver's LED strip. First, connect to your receiver:

arduino = Rustle::Receiver.new do
  # replace this path with the one specified by the Arduino IDE 
  port_file "/dev/[PORTFILE]"

  # replace this with the number of LEDs connected to your receiver
  num_leds 30
end

3. Throw a party

That's it! You can now control your LED strip with Ruby. Try out some of the following (this might be easier in a Ruby console):

# Adding on to the code from earlier...
strip = arduino.strip

# Make the strip red
strip.to Color.hex('f00')

# Make a fancy-schmancy wipe transition to white
strip.transition :wipe_to, 2000, color: white

Want to make a custom transition? It's easy! See the Transition class for a quick guide. If you want to make it a part of Rustle, throw it into the lib/transitions folder, and submit a pull request.

Documentation

$ yard

Alternatively, view it on RubyDoc.info.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request