Thanks to visit codestin.com
Credit goes to github.com

Skip to content

mteinum/erlang-sensehat

Repository files navigation

Erlang Sense Hat

Build and Test Erlang/OTP License

Raspberry Pi Sense Hat Erlang port driver

Project image

The Sense Hat is a framebuffer device and there is no native support in Erlang to open this through the file api.

If you try to open the device from erlang, this is the result:

Erlang/OTP 18 [erts-7.0] [source] [smp:4:4] [async-threads:10] [kernel-poll:false]

Eshell V7.0  (abort with ^G)
1> file:open('/dev/fb1', []).
{error,eisdir}

This project implements a port driver in C, that will allow Erlang to control the 8x8 LED display on the Sense Hat.

http://erlang.org/doc/reference_manual/ports.html

Specification for the Sense Hat

https://www.raspberrypi.org/blog/astro-pi-tech-specs/

8×8 RGB LED matrix with ~60fps refresh rate and 15-bit colour resolution (RGB 5 5 5): Cree CLU6AFKW/CLX6AFKB (data sheet) Accessible via frame buffer driver /dev/fb1 where each pixel is 16 bit (RGB 5 6 5).

WARNING

This code is experimental and not production ready (i.e., not ready for Astro Pi on the International Space Station ISS).

Prerequisites

  • Raspberry Pi (any model with 40-pin GPIO header)
  • Raspberry Pi Sense HAT attached
  • Build tools: gcc, make
  • Erlang/OTP 27 or later (recommended)
  • rebar3 build tool

Installation

Install Erlang OTP

Install Erlang/OTP 27 or later. You can use:

Note: OTP 27 is required for proper dialyzer support. OTP 28 (development version) may have compatibility issues with some build tools.

Build

Using rebar3 (recommended):

rebar3 compile

Or using make:

make all

Testing

Run unit tests with EUnit:

rebar3 eunit

Run dialyzer type checking:

rebar3 dialyzer

Run cross-reference analysis:

rebar3 xref

Usage Example

Start Erlang:

erl

Start the port driver, which will find the framebuffer device and map it into memory:

Eshell V7.0  (abort with ^G)
1> sensehat:start().      
<0.35.0>
2> shexample:logo().
ok
3> sensehat:set_rotation(180).
ok
4> sensehat:stop().
sensehat_drv: stop
stop

API Documentation

sensehat module

  • start() - Start the Sense Hat port driver
  • stop() - Stop the port driver and close the connection
  • set_pixel(X, Y, RGB) - Set a single pixel at coordinates (X, Y) with RGB color
  • set_pixels(Pixels) - Set multiple pixels at once
  • clear() - Clear the display (set all pixels to black)
  • clear(RGB) - Clear the display with specified RGB color
  • get_gamma() - Get current gamma correction values
  • set_gamma(Gamma) - Set gamma correction
  • set_gamma_low_light() - Apply low light gamma correction
  • reset_gamma(Gamma) - Reset gamma correction to specified values
  • set_rotation(Degrees) - Rotate the display (0, 90, 180, or 270 degrees)

Joystick Support

The sensestick_drv.c driver provides joystick integration for the Sense Hat's 5-button joystick (up, down, left, right, and enter/click). See st_event.erl, st_event_manager.erl, st_port.erl, and st_supervisor.erl for the event handling implementation.

TODO

  • Expand text rendering capabilities (basic framebuffer support exists in shfb.erl)
  • Add more example applications
  • Improve error handling and validation
  • Add unit tests

Reference

About

Raspberry Pi Sense Hat Erlang port driver

Resources

License

Stars

Watchers

Forks

Packages

No packages published