< GeeXLab Reference Guide />
> 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 ()
- gh_rpi.gpio_analog_write ()
- gh_rpi.gpio_digital_read ()
- gh_rpi.gpio_digital_write ()
- gh_rpi.gpio_digital_write_byte ()
- gh_rpi.gpio_get_alt ()
- gh_rpi.gpio_get_board_info ()
- gh_rpi.gpio_init ()
- gh_rpi.gpio_phys_pin_to_gpio ()
- gh_rpi.gpio_pwm_tone_write ()
- gh_rpi.gpio_pwm_write ()
- gh_rpi.gpio_set_gpio_clock ()
- gh_rpi.gpio_set_pad_drive ()
- gh_rpi.gpio_set_pin_mode ()
- gh_rpi.gpio_set_pin_mode_alt ()
- gh_rpi.gpio_set_pmw_clock ()
- gh_rpi.gpio_set_pull_up_down_control ()
- gh_rpi.gpio_set_pwm_mode ()
- gh_rpi.gpio_set_pwm_range ()
- gh_rpi.gpio_wpi_pin_to_gpio ()
- gh_rpi.rgbmatrix_fill_f32 ()
- gh_rpi.rgbmatrix_fill_u8 ()
- gh_rpi.rgbmatrix_get_luminance_correct ()
- gh_rpi.rgbmatrix_get_num_pixels ()
- gh_rpi.rgbmatrix_get_pwmbits ()
- gh_rpi.rgbmatrix_init ()
- gh_rpi.rgbmatrix_set_luminance_correct ()
- gh_rpi.rgbmatrix_set_pixel_f32 ()
- gh_rpi.rgbmatrix_set_pixel_u8 ()
- gh_rpi.rgbmatrix_set_pwmbits ()
- gh_rpi.rgbmatrix_terminate ()
gpio_analog_read
Description
Reads an analog value of a given pin.
Syntax
value = gh_rpi.gpio_analog_read(
pin
)
Languages
Parameters
- pin [INTEGER]: pin number
Return Values
- value [INTEGER]: analog value
Code sample
value = gh_rpi.gpio_analog_read(pin)
gpio_analog_write
Description
Writes the analog value to the given pin.
Syntax
gh_rpi.gpio_analog_write(
pin,
value
)
Languages
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)
gpio_digital_read
Description
Reads the value of a given pin, returning 1 (HIGH) or 0 (LOW).
Syntax
value = gh_rpi.gpio_digital_read(
pin
)
Languages
Parameters
- pin [INTEGER]: pin number
Return Values
- value [BOOLEAN]: 1 (HIGH) or 0 (LOW)
Code sample
pin = 23
value = gh_rpi.gpio_digital_read(pin)
gpio_digital_write
Description
Writes an output bit.
Syntax
gh_rpi.gpio_digital_write(
pin,
value
)
Languages
Parameters
- pin [INTEGER]: pin number
- value [BOOLEAN]: 1 (HIGH) or 0 (LOW)
Return Values
This function has no return value(s).
Code sample
pin = 23
state = 1
gh_rpi.gpio_digital_write(pin, state)
gpio_digital_write_byte
Description
Writes an 8-bit byte to the first 8 GPIO pins.
Syntax
gh_rpi.gpio_digital_write_byte(
value
)
Languages
Parameters
- value [INTEGER]: 8-bit value
Return Values
This function has no return value(s).
Code sample
gh_rpi.gpio_digital_write_byte(value)
gpio_get_alt
Description
Returns the ALT bits for a given pin.
Syntax
x = gh_rpi.gpio_get_alt(
pin
)
Languages
Parameters
- pin [INTEGER]: pin number
Return Values
Code sample
x = gh_rpi.gpio_get_alt(pin)
gpio_get_board_info
Description
Returns information about the Raspberry Pi board.
Syntax
maker, memsize, model, rev = gh_rpi.gpio_get_board_info()
Languages
Parameters
This function has no input parameter(s).
Return Values
- maker [STRING]: maker of the board
- memsize [STRING]: memory size available on the board
- model [STRING]: model of the board
- rev [STRING]: revision of the board
Code sample
model, rev, maker, memsize = gh_rpi.gpio_get_board_info()
gpio_init
Description
Initializes the access to the RPi. Must be called once in a INIT script.
Syntax
gh_rpi.gpio_init(
pin_mode
)
Languages
Parameters
- pin_mode [ENUM]: 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)
gpio_phys_pin_to_gpio
Description
Translates a physical pin number to native GPIO pin number.
Syntax
gpio_pin = gh_rpi.gpio_phys_pin_to_gpio(
phys_pin
)
Languages
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)
gpio_pwm_tone_write
Description
Writes the given frequency on the RPi's PWM pin.
Syntax
gh_rpi.gpio_pwm_tone_write(
pin,
freq
)
Languages
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)
gpio_pwm_write
Description
Writes an output PWM value.
Syntax
gh_rpi.gpio_pwm_write(
pin,
value
)
Languages
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)
gpio_set_gpio_clock
Description
Sets the frequency of a GPIO clock pin.
Syntax
gh_rpi.gpio_set_gpio_clock(
pin,
freq
)
Languages
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)
gpio_set_pad_drive
Description
Sets the PAD driver value.
Syntax
gh_rpi.gpio_set_pad_drive(
group,
value
)
Languages
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)
gpio_set_pin_mode
Description
Sets the GPIO pin mode: input, output, PWM output, etc.
Syntax
gh_rpi.gpio_set_pin_mode(
mode
)
Languages
Parameters
- mode [ENUM]: 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)
gpio_set_pin_mode_alt
Description
Special function that lets you set any pin to any mode.
Syntax
gh_rpi.gpio_set_pin_mode_alt(
pin,
mode
)
Languages
Parameters
- pin [INTEGER]: pin number
- mode [ENUM]: mode
Return Values
This function has no return value(s).
Code sample
gh_rpi.gpio_set_pin_mode_alt(pin, mode)
gpio_set_pmw_clock
Description
Sets the PWM clock.
Syntax
gh_rpi.gpio_set_pmw_clock(
divisor
)
Languages
Parameters
- divisor [INTEGER]: frequency divisor
Return Values
This function has no return value(s).
Code sample
gh_rpi.gpio_set_pmw_clock(divisor)
gpio_set_pull_up_down_control
Description
Controls the internal pull-up/down resistors on a GPIO pin.
Syntax
gh_rpi.gpio_set_pull_up_down_control(
pin,
pud
)
Languages
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)
gpio_set_pwm_mode
Description
Selects the native balanced mode, or standard mark:space mode.
Syntax
gh_rpi.gpio_set_pwm_mode(
mode
)
Languages
Parameters
- mode [ENUM]: 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)
gpio_set_pwm_range
Description
Sets the PWM range register.
Syntax
gh_rpi.gpio_set_pwm_range(
range
)
Languages
Parameters
- range [INTEGER]: PWM range
Return Values
This function has no return value(s).
Code sample
gh_rpi.gpio_set_pwm_range(range)
gpio_wpi_pin_to_gpio
Description
Translates a wiringPi pin number to native GPIO pin number.
Syntax
gpio_pin = gh_rpi.gpio_wpi_pin_to_gpio(
wpi_pin
)
Languages
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)
rgbmatrix_fill_f32
Description
Clears all LEDs with an uniform color.
Syntax
gh_rpi.rgbmatrix_fill_f32(
r, g, b
)
Languages
Parameters
- r, g, b [REAL]: RGB color (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)
rgbmatrix_fill_u8
Description
Clears all LEDs with an uniform color.
Syntax
gh_rpi.rgbmatrix_fill_u8(
r, g, b
)
Languages
Parameters
- r, g, b [INTEGER]: RGB color (0 to 255)
Return Values
This function has no return value(s).
Code sample
gh_rpi.rgbmatrix_fill_u8(255, 0, 0)
rgbmatrix_get_luminance_correct
Description
Gets the luminance correct state.
Syntax
state = gh_rpi.rgbmatrix_get_luminance_correct()
Languages
Parameters
This function has no input parameter(s).
Return Values
- state [BOOLEAN]: 1 (enabled) or 0 (disabled)
Code sample
state = gh_rpi.rgbmatrix_get_luminance_correct()
rgbmatrix_get_num_pixels
Description
Returns the numbers of LEDs (or pixels).
Syntax
nh, nw = gh_rpi.rgbmatrix_get_num_pixels()
Languages
Parameters
This function has no input parameter(s).
Return Values
- nh [INTEGER]: number of rows
- nw [INTEGER]: number of columns
Code sample
num_leds_x, num_leds_y = gh_rpi.rgbmatrix_get_num_pixels()
rgbmatrix_get_pwmbits
Description
Gets the number of bits for color representation: from 1 bit for simple color to 11 bits for true color.
Syntax
num_bits = gh_rpi.rgbmatrix_get_pwmbits()
Languages
Parameters
This function has no input parameter(s).
Return Values
- num_bits [INTEGER]: number of bits
Code sample
bits = gh_rpi.rgbmatrix_get_pwmbits()
rgbmatrix_init
Description
Initializes the functions to deal with RGB LED matrix panels (following the HUB75 interface).
Syntax
ret = gh_rpi.rgbmatrix_init(
num_rows,
num_chained_panels
)
Languages
Parameters
- num_rows [INTEGER]: number of rows of the LED matrix (16 or 32)
- num_chained_panels [INTEGER]: number of chained panels
Return Values
- ret [BOOLEAN]: return code: 1 (success) or 0 (error)
Code sample
ret = gh_rpi.rgbmatrix_init(32, 1)
rgbmatrix_set_luminance_correct
Description
Map brightness of output linearly to input with CIE1931 profile.
Syntax
state = gh_rpi.rgbmatrix_set_luminance_correct()
Languages
Parameters
This function has no input parameter(s).
Return Values
- state [BOOLEAN]: 1 (enabled) or 0 (disabled)
Code sample
gh_rpi.rgbmatrix_set_luminance_correct(1)
rgbmatrix_set_pixel_f32
Description
Sets the color of a particular LED (or pixel).
Syntax
gh_rpi.rgbmatrix_set_pixel_f32(
x, y,
r, g, b
)
Languages
Parameters
- x, y [INTEGER]: pixel coordinates
- r, g, b [REAL]: pixel RGB color (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)
rgbmatrix_set_pixel_u8
Description
Sets the color of a particular LED (or pixel).
Syntax
gh_rpi.rgbmatrix_set_pixel_u8(
x, y,
r, g, b
)
Languages
Parameters
- x, y [INTEGER]: pixel coordinates
- r, g, b [INTEGER]: pixel RGB color (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)
rgbmatrix_set_pwmbits
Description
Sets the number of bits for color representation: from 1 bit for simple color to 11 bits for true color.
Syntax
gh_rpi.rgbmatrix_set_pwmbits(
num_bits
)
Languages
Parameters
- num_bits [INTEGER]: number of bits
Return Values
This function has no return value(s).
Code sample
gh_rpi.rgbmatrix_set_pwmbits(11)
rgbmatrix_terminate
Description
Terminates and cleanup functions to deal with RGB LED matrix panels.
Syntax
gh_rpi.rgbmatrix_terminate()
Languages
Parameters
This function has no input parameter(s).
Return Values
This function has no return value(s).
Code sample
gh_rpi.rgbmatrix_terminate()
| |