Ruby support for UnicornHAT?

Hi all. I’m a Ruby developer that’s looking to play with the UnicornHAT.

I know that Python is the primary language for the UnicornHAT, but I’d really much rather use it with Ruby, to (in theory) avoid lots of yak shaving and and needing to learn another language. So far as I’m aware there’s no reason why it shouldn’t be possible to control it using Ruby, it just needs a library/package/gem writing for it.

Talking of which, I did do a search for this, and found a couple of links:

But I’ve toyed around with them, and I can’t make them work.

Has anyone else had any joy controlling the UnicornHAT with Ruby, and if so, how did you manage it? Thanks.

1 Like

The first one you linked looks like it should work, it’s certainly the solution I’d use, although unicornd also works well in my limited experience. What troubles did you run into with them?

Hi, thanks for your reply.

The problem I’m having is installing it, I get the following error:

pi@babblepi:~ $ sudo gem install ws2812
Fetching: ws2812-0.0.2.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing ws2812:
        ERROR: Failed to build gem native extension.

    /usr/bin/ruby2.1 extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.1.0/gems/ws2812-0.0.2 for inspection.
Results logged to /var/lib/gems/2.1.0/extensions/arm-linux/2.1.0/ws2812-0.0.2/gem_make.out

I guess I should post this on the repo.

Ooh, that’s easy enough to fix. If I recall correctly:

sudo apt-get install ruby-dev

Then try again!

I’ve actually managed to get a little further with this:

But still without too much joy :/

Okay! I’ll bite. I like Ruby still. I used to champion the local Ruby User Group in Norwich.

I’ve created a fork with the updated code that makes it work on the Pi 2 and Pi 3, see here: https://github.com/Gadgetoid/ruby-ws2812

1 Like

You are my hero! I very much look forward to playing with this later today, thank you so much :D

Let me know how it goes. I’ll add a link to the Ruby library from the Unicorn HAT library if it works well.

1 Like

If I manage to get anything interesting working with it, I’ll post it here. My first goal is to replicate this in Ruby.

Sorry for the double post, but I just wanted to show that it’s working :D

1 Like

Double-post away! Hurrah!

Love that example, it’s ingenious use of space, or lack thereof.

It is indeed, I looked at the source code - way over my head!

I notice that all of his examples reference the library directly, which I guess is a good thing as the gem version doesn’t work. I’m still pretty new to Ruby (most of the stuff I’ve done is in Rails), so I’m still feeling my way around, but I’m pretty excited that I can finally do something in a language that I know :)

I’ve been having a play, slowing educating myself on how to make animations, and have come up with the following:

https://vine.co/v/id67L0dYJxe

It’s meant to be laughing, but I can’t quite make it work.

https://vine.co/v/idjOgtbxMg6

This is a shadow-like cat running in the Twilight, but it doesn’t really work, so…

https://vine.co/v/idj5a9ZVAnm

That’s a bit easier to tell what it is.

I’m logging my activities over on my forum if you’re interested in seeing my (poor) source code.

Right now I’m having to do all of this within a folder inside @gadgetoid’s repo, as I don’t know enough about how it all works to just use it as a gem, so hopefully wejn will pull in the changes and push them out as a gem