I prefer working with Ruby, so here's a Ruby interface for the raspberry-pi sensehat.
TODO list of supported features
### Display
[x] clear
[x] set pixels
[x] get pixels
[ ] set pixel
[ ] get pixel
[ ] rotation
[ ] flip_h
[ ] flip_v
[ ] load_image
[ ] show_message
[x] show_letter
### Environment
[ ] humidity
[ ] temp from humidity
[ ] pressure
[ ] temp from pressure
### IMU Sensor
[ ] compass
[ ] gyro
[ ] acceleration
On your raspberry-pi (make sure you have ruby installed!)
pi@raspberrypi:~/Scripts/test $ echo "gem 'sense_hat', git: 'https://github.com/rjlynch/ruby-sense-hat'" >> Gemfile
pi@raspberrypi:~/Scripts/test $ bundle
Fire up irb and require bundler set up and the gem
pi@raspberrypi:~/Scripts/test $ irb
irb(main):001:0> require 'bundler/setup'
irb(main):002:0> require 'sense_hat'
Then have a play around!
The below snippet will make the LED display all green.
irb(main):003:0> display = SenseHat::Display.new
=> #<SenseHat::Display:0x01644ea0 @device=#<SenseHat::Display::Device:0x01644e88 @device_path="/dev/fb1">>
irb(main):004:0> display.set_pixels Array.new(64) { [0, 255, 0] }
irb(main):005:0> display.clear
irb(main):006:0> exit
display = SenseHat::Display.new
display.clear
Pass a 64 element array of RGB colour values to set_pixels
.
Each pixel is represented as an array of 3 integers in the range 0..255 indicating it's RGB value.
The below example would set the whole display to red.
display.set_pixels([
[255, 0, 0],
[255, 0, 0],
...
[255, 0, 0]
])
show_letter
displays a single character on the LED display.
It accepts optional keyword args for setting the colour and background.
display.show_letter 'A'
display.show_letter 'A', colour: [0, 0, 0], background: [248, 252, 248]
get_pixels
will return the colour values of each LED.
Due to the RGB565 encoding the max value returned for red or blue will be 248
and for green the max value will be 252.
See this stackoverflow answer
for more information.
display.get_pixels # => [[248, 0, 0], [248, 0, 0], ... [248, 0, 0] ]
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/rjlynch/sense_hat.
The gem is available as open source under the terms of the MIT License.