RaspberryPi library

Index:

Functions:

delay

delay

Synopsis
Pauses execution for the specified microseconds.
Usage
(delay microseconds)
Returns
result
Where
  • microseconds is number: the number of microseconds to pause the execution.
  • result is number: the number of microseconds that the execution was paused.
Description
Pauses the execution of the current thread for the specified microseconds.
Examples
(delay 500)
500
gpio-mode

gpio-mode

Synopsis
Sets the operating mode of a GPIO pin.
Usage
(gpio-mode pin_num mode)
Returns
result
Where
  • pin_num is number: the number of the GPIO pin according to this pin numbering scheme: http://pi4j.com/pin-numbering-scheme.html.
  • mode is string: the operating mode of the pin, that can be: "in" for input, "out" for output, "pwm" for harware pwm, "up" for pull-up, "down" for pull-down, "tri" for tri-state and "off" to disable the pin.
  • result is string: the operating mode set for the pin.
Description
Sets the operating mode for the given GPIO pin.
Examples
(gpio-mode 21 "out")
"out"
gpio-pulse-in

gpio-pulse-in

Synopsis
Measure the duration of a pulse.
Usage
(gpio-pulse-in pin_num level timeout)
Returns
ellapsed
Where
  • pin_num is number: the number of the GPIO pin according to this pin numbering scheme: http://pi4j.com/pin-numbering-scheme.html.
  • level is number: the level of the pulse, 0 for LOW and 1 for HIGH.
  • timeout is number[0..1]: the maximum time to wait for a pin change in microseconds.
  • ellapsed is number: the duration of the pulse in microseconds or -1 if the value of the pin do not change for timeout microseconds.
Description
Returns the duration of a pulse of value level in the specified pin measured in microseconds. If the initial value of the pin is different from level, this function will wait for a pin change a maximum time of timeout. If timeout is exceeded, -1 will be returned.
Examples
(gpio-pulse-in 2 1 1000)
452
gpio-pwm

gpio-pwm

Synopsis
Sets the PWM duty cycle value for a GPIO pin.
Usage
(gpio-pwm pin_num value)
Returns
result
Where
  • pin_num is number: the pin number that will generate the hardware PWM signal. Not all pins in the RaspberryPi suports hardware PWM (see RaspberryPi documentation for more details).
  • value is number: a value between 0 and the range previously set with the function gpio-pwmc.
  • result is number: the value set in pin_num.
Description
This function modifies the duty cycle of the PWM signal in the specified pin. The duty cycle % of the signal will be 100 * value / range, where the range is set with the function gpio-pwmc. Prior to use this function (gpio-mode pin_num "pwm") and (gpio-pwmc clock range) must be called.
Examples
(gpio-pwm 24 50)
50
Related functions
gpio-pwmc

gpio-pwmc

Synopsis
Sets the hardware PWM signal parameters.
Usage
(gpio-pwmc clock range)
Returns
frequency
Where
  • clock is number: the internal clock divider, a value between 2 and 4095.
  • range is number[0..1]: the range of the PWM signal, a value less than 4096. By default, range is 100.
  • frequency is number: the frequency (in Hz) of the PWM signal that is equal to 19.2e6 / clock / range.
Description
This functions setups the frequency and range of all hardware PWM pins of the Raspberry Pi. The frequency of the PWM signal is the result of dividing the internal 19.2Mhz clock by clock and by range.
Examples
(gpio-pwmc 8 100)
24000
Related functions
gpio-read

gpio-read

Synopsis
Reads a GPIO pin.
Usage
(gpio-read pin_num)
Returns
result
Where
Description
Reads the value of the specified GPIO pin.
Examples
(gpio-read 2)
1
gpio-write

gpio-write

Synopsis
Writes in a GPIO pin.
Usage
(gpio-write pin_num value)
Returns
result
Where
  • pin_num is number: the number of the GPIO pin according to this pin numbering scheme: http://pi4j.com/pin-numbering-scheme.html.
  • value is number: the value to write in the pin. It can be 0 or false for LOW, or 1 or true for HIGH.
  • result is number: the value set in the pin.
Description
Writes the given value in the specified GPIO pin.
Examples
(gpio-write 2 0)
0
melody

melody

Synopsis
Plays a melody.
Usage
(melody pin_num note_tempo_list)
Returns
null
Where
  • pin_num is number: the number of the GPIO pin according to this pin numbering scheme: http://pi4j.com/pin-numbering-scheme.html.
  • note_tempo_list is list: a list that contains the tones (Hz) and tempos (ms) of the melody to play: (tone1 tempo1 tone2 tempo2 ...).
Description
This function generates a variable PWM signal in the specified pin which frequency (tone) and duration (tempo) is taken from the tone_tempo_list. Typically a buzzer or speaker is connected to pin_num to play the sound.
Examples
(melody 2 1000 300 2000 500 1500 400)
null
soft-pwm

soft-pwm

Synopsis
Generates a software PWM signal in a GPIO pin.
Usage
(soft-pwm pin_num value range)
Returns
result
Where
  • pin_num is number: the number of the GPIO pin according to this pin numbering scheme: http://pi4j.com/pin-numbering-scheme.html.
  • value is number: a value between 0 and range that determines the duty cycle of the signal.
  • range is number[0..1]: the duration of a cycle in units of 10us. For example, range 100 = 100 * 10us = 0.01s (100Hz). When omitted, the range is not changed.
  • result is number: the value set for the signal generation.
Description
The frequency of the generated signal is 1 / (range * 0.0001s) Hz, and the duty cycle % is 100 * value / range. A typical range of 100, generates a signal with a frequency of 100Hz. The range can be omitted if you only want to set the value to modify the duty cycle of the signal. When range is 0 the signal generation is interrupted.
Examples
(soft-pwm 3 25 200)
25
(soft-pwm 3 35)
35
(soft-pwm 3 0 0)
0
Top