This post is going to be somewhat rambling without a clear destination, as this is my initial foray into configuring the Rpi to interact with sensors and such, and thus will be filled with my pokings and proddings. Here we go!
First, I have been using the book ‘Make: Linux for Makers’ by Aaron Newcomb, which has been helpful for tying in the linux aspects with Rpi. Aaron mentions that thereare several programming modules or libraries that you can use to control the GPIO pins on a Rpi, including RPi.GPIO, but he suggested pigpio so that’s the one I went with, too. To download that module, I used the following command in my terminal shell window on Rpi:
wget https://github.com/joan2937/pigpio/archive/master.zip
unzip master.zip
cd pigpio-master
make
sudo make install
I used a headless setup to work with these steps, and there was no problem downloading or installing these files. Here’s the link to the Python interface for the module. Pigpio runs as a daemon process in the background, and then Python class instances are created in order to control individual RPi’s pins. Here’s an example of doing that
pi1 = pigpio.pi() # pi1 accesses the local Pi's GPIO
pi2 = pigpio.pi('tom') # pi2 accesses tom's GPIO
pi3 = pigpio.pi('dick') # pi3 accesses dick's GPIO
pi1.write(4, 0) # set local Pi's GPIO 4 low
pi2.write(4, 1) # set tom's GPIO 4 to high
pi3.read(4) # get level of dick's GPIO 4
OVERVIEW
| ESSENTIAL | |
| pigpio.pi | Initialise Pi connection |
| stop | Stop a Pi connection |
| BASIC | |
| set_mode | Set a GPIO mode |
| get_mode | Get a GPIO mode |
| set_pull_up_down | Set/clear GPIO pull up/down resistor |
| read | Read a GPIO |
| write | Write a GPIO |
| PWM (overrides servo commands on same GPIO) | |
| set_PWM_dutycycle | Start/stop PWM pulses on a GPIO |
| set_PWM_frequency | Set PWM frequency of a GPIO |
| set_PWM_range | Configure PWM range of a GPIO |
| get_PWM_dutycycle | Get PWM dutycycle set on a GPIO |
| get_PWM_frequency | Get PWM frequency of a GPIO |
| get_PWM_range | Get configured PWM range of a GPIO |
| get_PWM_real_range | Get underlying PWM range for a GPIO |
| Servo (overrides PWM commands on same GPIO) | |
| set_servo_pulsewidth | Start/Stop servo pulses on a GPIO |
| get_servo_pulsewidth | Get servo pulsewidth set on a GPIO |
| INTERMEDIATE | |
| gpio_trigger | Send a trigger pulse to a GPIO |
| set_watchdog | Set a watchdog on a GPIO |
| read_bank_1 | Read all bank 1 GPIO |
| read_bank_2 | Read all bank 2 GPIO |
| clear_bank_1 | Clear selected GPIO in bank 1 |
| clear_bank_2 | Clear selected GPIO in bank 2 |
| set_bank_1 | Set selected GPIO in bank 1 |
| set_bank_2 | Set selected GPIO in bank 2 |
| callback | Create GPIO level change callback |
| wait_for_edge | Wait for GPIO level change |
| ADVANCED | |
| notify_open | Request a notification handle |
| notify_begin | Start notifications for selected GPIO |
| notify_pause | Pause notifications |
| notify_close | Close a notification |
| hardware_clock | Start hardware clock on supported GPIO |
| hardware_PWM | Start hardware PWM on supported GPIO |
| set_glitch_filter | Set a glitch filter on a GPIO |
| set_noise_filter | Set a noise filter on a GPIO |
| set_pad_strength | Sets a pads drive strength |
| get_pad_strength | Gets a pads drive strength |
| shell | Executes a shell command |
| Custom | |
| custom_1 | User custom function 1 |
| custom_2 | User custom function 2 |
| Events | |
| event_callback | Sets a callback for an event |
| event_trigger | Triggers an event |
| wait_for_event | Wait for an event |
| Scripts | |
| store_script | Store a script |
| run_script | Run a stored script |
| update_script | Set a scripts parameters |
| script_status | Get script status and parameters |
| stop_script | Stop a running script |
| delete_script | Delete a stored script |
| I2C | |
| i2c_open | Opens an I2C device |
| i2c_close | Closes an I2C device |
| i2c_write_quick | SMBus write quick |
| i2c_read_byte | SMBus read byte |
| i2c_write_byte | SMBus write byte |
| i2c_read_byte_data | SMBus read byte data |
| i2c_write_byte_data | SMBus write byte data |
| i2c_read_word_data | SMBus read word data |
| i2c_write_word_data | SMBus write word data |
| i2c_read_block_data | SMBus read block data |
| i2c_write_block_data | SMBus write block data |
| i2c_read_i2c_block_data | SMBus read I2C block data |
| i2c_write_i2c_block_data | SMBus write I2C block data |
| i2c_read_device | Reads the raw I2C device |
| i2c_write_device | Writes the raw I2C device |
| i2c_process_call | SMBus process call |
| i2c_block_process_call | SMBus block process call |
| i2c_zip | Performs multiple I2C transactions |
| I2C BIT BANG | |
| bb_i2c_open | Opens GPIO for bit banging I2C |
| bb_i2c_close | Closes GPIO for bit banging I2C |
| bb_i2c_zip | Performs multiple bit banged I2C transactions |
| I2C/SPI SLAVE | |
| bsc_xfer | I2C/SPI as slave transfer |
| bsc_i2c | I2C as slave transfer |
| SERIAL | |
| serial_open | Opens a serial device |
| serial_close | Closes a serial device |
| serial_read_byte | Reads a byte from a serial device |
| serial_write_byte | Writes a byte to a serial device |
| serial_read | Reads bytes from a serial device |
| serial_write | Writes bytes to a serial device |
| serial_data_available | Returns number of bytes ready to be read |
| SERIAL BIT BANG (read only) | |
| bb_serial_read_open | Open a GPIO for bit bang serial reads |
| bb_serial_read_close | Close a GPIO for bit bang serial reads |
| bb_serial_invert | Invert serial logic (1 invert, 0 normal) |
| bb_serial_read | Read bit bang serial data from a GPIO |
| SPI | |
| spi_open | Opens a SPI device |
| spi_close | Closes a SPI device |
| spi_read | Reads bytes from a SPI device |
| spi_write | Writes bytes to a SPI device |
| spi_xfer | Transfers bytes with a SPI device |
| SPI BIT BANG | |
| bb_spi_open | Opens GPIO for bit banging SPI |
| bb_spi_close | Closes GPIO for bit banging SPI |
| bb_spi_xfer | Transfers bytes with bit banging SPI |
| FILES | |
| file_open | Opens a file |
| file_close | Closes a file |
| file_read | Reads bytes from a file |
| file_write | Writes bytes to a file |
| file_seek | Seeks to a position within a file |
| file_list | List files which match a pattern |
| WAVES | |
| wave_clear | Deletes all waveforms |
| wave_add_new | Starts a new waveform |
| wave_add_generic | Adds a series of pulses to the waveform |
| wave_add_serial | Adds serial data to the waveform |
| wave_create | Creates a waveform from added data |
| wave_create_and_pad | Creates a waveform of fixed size from added data |
| wave_delete | Deletes a waveform |
| wave_send_once | Transmits a waveform once |
| wave_send_repeat | Transmits a waveform repeatedly |
| wave_send_using_mode | Transmits a waveform in the chosen mode |
| wave_chain | Transmits a chain of waveforms |
| wave_tx_at | Returns the current transmitting waveform |
| wave_tx_busy | Checks to see if a waveform has ended |
| wave_tx_stop | Aborts the current waveform |
| wave_get_cbs | Length in cbs of the current waveform |
| wave_get_max_cbs | Absolute maximum allowed cbs |
| wave_get_micros | Length in microseconds of the current waveform |
| wave_get_max_micros | Absolute maximum allowed micros |
| wave_get_pulses | Length in pulses of the current waveform |
| wave_get_max_pulses | Absolute maximum allowed pulses |
| UTILITIES | |
| get_current_tick | Get current tick (microseconds) |
| get_hardware_revision | Get hardware revision |
| get_pigpio_version | Get the pigpio version |
| pigpio.error_text | Gets error text from error number |
| pigpio.tickDiff | Returns difference between two ticks |