Back to Reference Guide Index

gh_rpi Library

Description

gh_rpi is the module that manages the Raspberry Pi (RPi) GPIO and RGB LED matrix panel programming.

Number of functions: 31



gh_rpi.gpio_analog_read

Description

Reads an analog value of a given pin.

Languages

Lua - Python

Parameters

  • pin [INTEGER]: pin number.

    Return Values

  • value [INTEGER]: analog value.

    Code sample

    value = gh_rpi.gpio_analog_read(pin)
                


    gh_rpi.gpio_analog_write

    Description

    Writes the analog value to the given pin.

    Languages

    Lua - Python

    Parameters

  • pin [INTEGER]: pin number.
  • value [INTEGER]: analog value

    Return Values

    This function has no return value(s).

    Code sample

    gh_rpi.gpio_analog_write(pin, value)
                


    gh_rpi.gpio_digital_read

    Description

    Reads the value of a given pin, returning 1 (HIGH) or 0 (LOW).

    Languages

    Lua - Python

    Parameters

  • pin [INTEGER]: pin number.

    Return Values

  • value [INTEGER]: 1 (HIGH) or 0 (LOW).

    Code sample

    pin = 23
    value = gh_rpi.gpio_digital_read(pin)
                


    gh_rpi.gpio_digital_write

    Description

    Writes an output bit.

    Languages

    Lua - Python

    Parameters

  • pin [INTEGER]: pin number.
  • value [INTEGER]: 0 (LOW) or 1 (HIGH).

    Return Values

    This function has no return value(s).

    Code sample

    pin = 23
    state = 1
    gh_rpi.gpio_digital_write(pin, state)
                


    gh_rpi.gpio_digital_write_byte

    Description

    Writes an 8-bit byte to the first 8 GPIO pins.

    Languages

    Lua - Python

    Parameters

  • value [INTEGER]: 8-bit value

    Return Values

    This function has no return value(s).

    Code sample

    gh_rpi.gpio_digital_write_byte(value)
                


    gh_rpi.gpio_init

    Description

    Initializes the access to the RPi. Must be called once in a INIT script.

    Languages

    Lua - Python

    Parameters

  • pin_mode [INTEGER]: sets the pin numbering mode: 0 (wirinPi mode), 1 (GPIO mode), 2 (GPIO system mode) and 3 (physical mode).

    Return Values

    This function has no return value(s).

    Code sample

    GPIO_PINS_MAPPING_MODE_GPIO = 1
    GPIO_PINS_MAPPING_MODE_PHYSICAL = 3
    gh_rpi.gpio_init(GPIO_PINS_MAPPING_MODE_GPIO)
                


    gh_rpi.gpio_get_alt

    Description

    Returns the ALT bits for a given pin.

    Languages

    Lua - Python

    Parameters

  • pin [INTEGER]: pin number.

    Return Values

  • x [INTEGER]: ALT bits.

    Code sample

    x = gh_rpi.gpio_get_alt(pin)
                


    gh_rpi.gpio_get_board_info

    Description

    Returns information about the Raspberry Pi board.

    Languages

    Lua - Python

    Parameters

    This function has no input parameter(s).

    Return Values

  • model [STRING]: model of the board.
  • rev [STRING]: revision of the board.
  • maker [STRING]: maker of the board.
  • memsize [STRING]: memory size available on the board.

    Code sample

    model, rev, maker, memsize = gh_rpi.gpio_get_board_info()
                


    gh_rpi.gpio_phys_pin_to_gpio

    Description

    Translates a physical pin number to native GPIO pin number.

    Languages

    Lua - Python

    Parameters

  • phys_pin [INTEGER]: Physical pin number.

    Return Values

  • gpio_pin [INTEGER]: GPIO pin number.

    Code sample

    gpio_pin = gh_rpi.gpio_phys_pin_to_gpio(phys_pin)
                


    gh_rpi.gpio_pwm_tone_write

    Description

    Writes the given frequency on the RPi's PWM pin.

    Languages

    Lua - Python

    Parameters

  • pin [INTEGER]: pin number.
  • freq [INTEGER]: frequency

    Return Values

    This function has no return value(s).

    Code sample

    gh_rpi.gpio_pwm_tone_write(pin, freq)
                


    gh_rpi.gpio_pwm_write

    Description

    Writes an output PWM value.

    Languages

    Lua - Python

    Parameters

  • pin [INTEGER]: pin number.
  • value [INTEGER]: PWM value

    Return Values

    This function has no return value(s).

    Code sample

    gh_rpi.gpio_pwm_write(pin, value)
                


    gh_rpi.gpio_set_gpio_clock

    Description

    Sets the frequency of a GPIO clock pin.

    Languages

    Lua - Python

    Parameters

  • pin [INTEGER]: pin number.
  • freq [INTEGER]: frequency

    Return Values

    This function has no return value(s).

    Code sample

    gh_rpi.gpio_set_gpio_clock(pin, freq)
                


    gh_rpi.gpio_set_pin_mode

    Description

    Sets the GPIO pin mode: input, output, PWM output, etc..

    Languages

    Lua - Python

    Parameters

  • mode [INTEGER]: pin mode: 0 (INPUT), 1 (OUTPUT), 2 (PWM_OUTPUT), 3 (GPIO_CLOCK), 4 (SOFT_PWM_OUTPUT), 5 (SOFT_TONE_OUTPUT) and 6 (PWM_TONE_OUTPUT).

    Return Values

    This function has no return value(s).

    Code sample

    GPIO_MODE_OUTPUT = 1
    gh_rpi.mgpio_set_pin_mode(GPIO_MODE_OUTPUT)
                


    gh_rpi.gpio_set_pin_mode_alt

    Description

    Special function that lets you set any pin to any mode.

    Languages

    Lua - Python

    Parameters

  • pin [INTEGER]: pin number.
  • mode [INTEGER]: mode

    Return Values

    This function has no return value(s).

    Code sample

    gh_rpi.gpio_set_pin_mode_alt(pin, mode)
                


    gh_rpi.gpio_set_pad_drive

    Description

    Sets the PAD driver value.

    Languages

    Lua - Python

    Parameters

  • group [INTEGER]: group.
  • value [INTEGER]: value.

    Return Values

    This function has no return value(s).

    Code sample

    gh_rpi.gpio_set_pad_drive(group, value)
                


    gh_rpi.gpio_set_pull_up_down_control

    Description

    Controls the internal pull-up/down resistors on a GPIO pin.

    Languages

    Lua - Python

    Parameters

  • pin [INTEGER]: pin number.
  • pud [INTEGER]: pull-up/down resistors value

    Return Values

    This function has no return value(s).

    Code sample

    gh_rpi.gpio_set_pull_up_down_control(pin, pud)
                


    gh_rpi.gpio_set_pmw_clock

    Description

    Sets the PWM clock.

    Languages

    Lua - Python

    Parameters

  • divisor [INTEGER]: frequency divisor

    Return Values

    This function has no return value(s).

    Code sample

    gh_rpi.gpio_set_pmw_clock(divisor)
                


    gh_rpi.gpio_set_pwm_mode

    Description

    Selects the native balanced mode, or standard mark:space mode.

    Languages

    Lua - Python

    Parameters

  • mode [INTEGER]: PWM mode: 0 (PWM_MODE_MS) or 1 (PWM_MODE_BAL)

    Return Values

    This function has no return value(s).

    Code sample

    gh_rpi.gpio_set_pwm_mode(mode)
                


    gh_rpi.gpio_set_pwm_range

    Description

    Sets the PWM range register.

    Languages

    Lua - Python

    Parameters

  • range [INTEGER]: PWM range

    Return Values

    This function has no return value(s).

    Code sample

    gh_rpi.gpio_set_pwm_range(range)
                


    gh_rpi.gpio_wpi_pin_to_gpio

    Description

    Translates a wiringPi pin number to native GPIO pin number.

    Languages

    Lua - Python

    Parameters

  • wpi_pin [INTEGER]: wiringPi pin number.

    Return Values

  • gpio_pin [INTEGER]: GPIO pin number.

    Code sample

    gpio_pin = gh_rpi.gpio_wpi_pin_to_gpio(wpi_pin)
                


    gh_rpi.rgbmatrix_fill_f32

    Description

    Clears all LEDs with an uniform color.

    Languages

    Lua - Python

    Parameters

  • r [REAL]: red channel (0.0 to 1.0).
  • g [REAL]: green channel (0.0 to 1.0).
  • b [REAL]: blue channel (0.0 to 1.0).

    Return Values

    This function has no return value(s).

    Code sample

    gh_rpi.rgbmatrix_fill_u8(1.0, 0, 0)
                


    gh_rpi.rgbmatrix_fill_u8

    Description

    Clears all LEDs with an uniform color.

    Languages

    Lua - Python

    Parameters

  • r [INTEGER]: red channel (0 to 255).
  • g [INTEGER]: green channel (0 to 255).
  • b [INTEGER]: blue channel (0 to 255).

    Return Values

    This function has no return value(s).

    Code sample

    gh_rpi.rgbmatrix_fill_u8(255, 0, 0)
                


    gh_rpi.rgbmatrix_get_luminance_correct

    Description

    Gets the luminance correct state.

    Languages

    Lua - Python

    Parameters

    This function has no input parameter(s).

    Return Values

  • state [INTEGER]: enabled (1) of disabled (0)

    Code sample

    state = gh_rpi.rgbmatrix_get_luminance_correct()
                


    gh_rpi.rgbmatrix_get_num_pixels

    Description

    Returns the numbers of LEDs (or pixels).

    Languages

    Lua - Python

    Parameters

    This function has no input parameter(s).

    Return Values

  • nw [INTEGER]: number of columns.
  • nh [INTEGER]: number of rows.

    Code sample

    num_leds_x, num_leds_y = gh_rpi.rgbmatrix_get_num_pixels()
                


    gh_rpi.rgbmatrix_get_pwmbits

    Description

    Gets the number of bits for color representation: from 1 bit for simple color to 11 bits for true color.

    Languages

    Lua - Python

    Parameters

    This function has no input parameter(s).

    Return Values

  • bits [INTEGER]: number of bits.

    Code sample

    bits = gh_rpi.rgbmatrix_get_pwmbits()
                


    gh_rpi.rgbmatrix_init

    Description

    Initializes the functions to deal with RGB LED matrix panels (following the HUB75 interface).

    Languages

    Lua - Python

    Parameters

  • num_rows [INTEGER]: number of rows of the LED matrix (16 or 32).
  • num_chained_displays [INTEGER]: number of chained panels.

    Return Values

  • ret [INTEGER]: return code: 1 (ok) or 0 (error).

    Code sample

    ret = gh_rpi.rgbmatrix_init(32, 1)
                


    gh_rpi.rgbmatrix_set_luminance_correct

    Description

    Map brightness of output linearly to input with CIE1931 profile.

    Languages

    Lua - Python

    Parameters

    This function has no input parameter(s).

    Return Values

  • state [INTEGER]: enabled (1) of disabled (0)

    Code sample

    gh_rpi.rgbmatrix_set_luminance_correct(1)
                


    gh_rpi.rgbmatrix_set_pixel_f32

    Description

    Sets the color of a particular LED (or pixel).

    Languages

    Lua - Python

    Parameters

  • x [INTEGER]: x coordinate of the LED.
  • y [INTEGER]: y coordinate of the LED.
  • r [REAL]: red channel (0.0 to 1.0).
  • g [REAL]: green channel (0.0 to 1.0).
  • b [REAL]: blue channel (0.0 to 1.0).

    Return Values

    This function has no return value(s).

    Code sample

    gh_rpi.rgbmatrix_set_pixel_f32(7, 8,   1.0, 0, 0)
                


    gh_rpi.rgbmatrix_set_pixel_u8

    Description

    Sets the color of a particular LED (or pixel).

    Languages

    Lua - Python

    Parameters

  • x [INTEGER]: x coordinate of the LED.
  • y [INTEGER]: y coordinate of the LED.
  • r [INTEGER]: red channel (0 to 255).
  • g [INTEGER]: green channel (0 to 255).
  • b [INTEGER]: blue channel (0 to 255).

    Return Values

    This function has no return value(s).

    Code sample

    gh_rpi.rgbmatrix_set_pixel_u8(7, 8,   255, 0, 0)
                


    gh_rpi.rgbmatrix_set_pwmbits

    Description

    Sets the number of bits for color representation: from 1 bit for simple color to 11 bits for true color.

    Languages

    Lua - Python

    Parameters

  • bits [INTEGER]: number of bits.

    Return Values

    This function has no return value(s).

    Code sample

    gh_rpi.rgbmatrix_set_pwmbits(11)
                


    gh_rpi.rgbmatrix_terminate

    Description

    Terminates and cleanup functions to deal with RGB LED matrix panels.

    Languages

    Lua - Python

    Parameters

    This function has no input parameter(s).

    Return Values

    This function has no return value(s).

    Code sample

    gh_rpi.rgbmatrix_terminate()