mruby gem for accessing Raspberry IO.
##Intro mruby-raspberry is a wrapper around wiringpi library. At the moment, it support most of the original basic functionalities, excluding I2C, SPI, Shift, Software PWM, and Software Tone.
##Requirements and Building
The wiringpi library v2 needs to be installed before using this mruby-gem.
libi2c-dev must be installed.
To do a quick test, after installing WiringPi, proceed as follows:
$ git clone --depth 1 https://github.com/uniTN-Mechatronics/mruby-raspberry.git $ cd mruby-raspberry $ ./run_test.rb # this also clones mruby master $ sudo tmp/mruby/bin/mirb # sudo needed for accessing hw pins
Adding to your mruby
To use it within your custom mruby, just add
conf.gem :github => 'UniTN-Mechatronics/mruby-raspberry', :branch => 'master' in your
The C functions of the original WiringPi library are grouped under the module
Raspberry. Each of the categories in which the WiringPi functions are collected is implemented either as a submodule of
Raspberry or as a class when it makes sense:
Raspberry module only has one function,
setup(), which maps the
wiringPiSetup C call. Note: if you
include Raspberry, the
setup function is automatically called; otherwise, you explicitly need to call it for the rest to work.
The following is the list of the implemented functions/methods. For details, see the original WiringPi documentation.
pin_mode(pin, mode), mode is one of the constants
pull_mode(pin, mode), mode is one of the constants
digital_write(pin, level), level is one of the constants
write_byte(value), value is casted into a 8 bit int
pwd_set_mode(), mode is one of the constants
board_rev(), returns either 1 or 2
wpi_pin(), converts WirnigPI pin number into GPIO pin number
phys_pin(), converts physical pin number into GPIO pin number
Serial.valid_rate?(rate), returns true if rate is a standard valid baud rate
Serial.new(port, baud), creates and opens a serial port connection
Serial#put_char(chr), only the first character of
This class supports TWI/I2C communication, or at least a subset of it. It has been tested against an Arduino Uno directly connected to a Raspberry Pi Rev.2, see here for details.
Requirement: Remember to
sudo apt-get install i2c-tools libi2c-dev before building!
I2C.new(id): creates a new instance over the given I2C device ID
I2C#write(arg): writes a String or an Array of Fixnums to the selected device ID. If
argis a single integer or char, writes it directly. If it is a string or an array of Fixnums, iterates over the elements with a delay between each write that can be set via
I2C#delay=(v)(delay is in milliseconds, default to 5000 ms)
I2C#read(n=nil): reads value(s) from the selected device ID. If
n=nil, it reads a single value (as Fixnum). If
n > 0, it performs exactly
nread operations waiting
@delayevery time, and returns an array of
I2C#read_chr: Reads a single value and converts it to a single character