


start DUTY_CYCLEĭUTY_CYCLE is a value from 0.0 to 100.0 indicating the percent of the time that the signal will be high. Now you can call the following method to start PWM: pwm. The PWM_FREQ is a value in hertz that specifies the amount of pulse cycles per second. To utilize PWM, first create a PWM object for an output pin. Pulse-width modulation is a useful tool for controlling things like LED brightness or motor speed. setup PIN_NUM, :as => :output, :initialize => :low PWM (pulse-width modulation) setup PIN_NUM, :as => :output, :initialize => :high # or You can use the additional hash argument :initialize to set the pin's initial state like so: RPi :: GPIO. To send output to a GPIO pin, you must first initialize it as an output pin: RPi :: GPIO. setup PIN_NUM, :as => :input, :pull => :off Output setup PIN_NUM, :as => :input, :pull => :up # or (not necessary :off is the default value) setup PIN_NUM, :as => :input, :pull => :down # or You can use the additional hash argument :pull to apply a pull-up or pull-down resistor to the input pin like so: RPi :: GPIO. The pin number will differ based on your selected numbering system and which pin you want to use. To receive input from a GPIO pin, you must first initialize it as an input pin: RPi :: GPIO. Note that :bcm numbering differs between Pi models, while :board numbering does not.

:board numbering refers to the physical pin numbers on the Pi, whereas :bcm numbering refers to the Broadcom SOC channel numbering.

Pin numberingīefore you can do anything with the GPIO pins, you need to specify how you want to number them. To include the gem in a Ruby file, use the line require 'rpi_gpio'. Then you can run bundle install to automatically download and compile the gem for your system. In your Gemfile, include the line gem ' rpi_gpio ' The easiest way to download the gem is to use Bundler with a Gemfile. If anything is confusing, you can always check here for the original Python module's documentation. I aimed to make the gem's usage exactly the same as its Python counterpart - only with a few semantic differences to utilize Ruby's readability. Up-to-date with RPi.GPIO Python module version 0.6.2, so it works on all Raspberry Pi models! Sample Usage
