RaspberryPi and Hardware Control


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.piInitialise Pi connection
stopStop a Pi connection
BASIC
set_modeSet a GPIO mode
get_modeGet a GPIO mode
set_pull_up_downSet/clear GPIO pull up/down resistor
readRead a GPIO
writeWrite a GPIO
PWM (overrides servo commands on same GPIO)
set_PWM_dutycycleStart/stop PWM pulses on a GPIO
set_PWM_frequencySet PWM frequency of a GPIO
set_PWM_rangeConfigure PWM range of a GPIO
get_PWM_dutycycleGet PWM dutycycle set on a GPIO
get_PWM_frequencyGet PWM frequency of a GPIO
get_PWM_rangeGet configured PWM range of a GPIO
get_PWM_real_rangeGet underlying PWM range for a GPIO
Servo (overrides PWM commands on same GPIO)
set_servo_pulsewidthStart/Stop servo pulses on a GPIO
get_servo_pulsewidthGet servo pulsewidth set on a GPIO
INTERMEDIATE
gpio_triggerSend a trigger pulse to a GPIO
set_watchdogSet a watchdog on a GPIO
read_bank_1Read all bank 1 GPIO
read_bank_2Read all bank 2 GPIO
clear_bank_1Clear selected GPIO in bank 1
clear_bank_2Clear selected GPIO in bank 2
set_bank_1Set selected GPIO in bank 1
set_bank_2Set selected GPIO in bank 2
callbackCreate GPIO level change callback
wait_for_edgeWait for GPIO level change
ADVANCED
notify_openRequest a notification handle
notify_beginStart notifications for selected GPIO
notify_pausePause notifications
notify_closeClose a notification
hardware_clockStart hardware clock on supported GPIO
hardware_PWMStart hardware PWM on supported GPIO
set_glitch_filterSet a glitch filter on a GPIO
set_noise_filterSet a noise filter on a GPIO
set_pad_strengthSets a pads drive strength
get_pad_strengthGets a pads drive strength
shellExecutes a shell command
Custom
custom_1User custom function 1
custom_2User custom function 2
Events
event_callbackSets a callback for an event
event_triggerTriggers an event
wait_for_eventWait for an event
Scripts
store_scriptStore a script
run_scriptRun a stored script
update_scriptSet a scripts parameters
script_statusGet script status and parameters
stop_scriptStop a running script
delete_scriptDelete a stored script
I2C
i2c_openOpens an I2C device
i2c_closeCloses an I2C device
i2c_write_quickSMBus write quick
i2c_read_byteSMBus read byte
i2c_write_byteSMBus write byte
i2c_read_byte_dataSMBus read byte data
i2c_write_byte_dataSMBus write byte data
i2c_read_word_dataSMBus read word data
i2c_write_word_dataSMBus write word data
i2c_read_block_dataSMBus read block data
i2c_write_block_dataSMBus write block data
i2c_read_i2c_block_dataSMBus read I2C block data
i2c_write_i2c_block_dataSMBus write I2C block data
i2c_read_deviceReads the raw I2C device
i2c_write_deviceWrites the raw I2C device
i2c_process_callSMBus process call
i2c_block_process_callSMBus block process call
i2c_zipPerforms multiple I2C transactions
I2C BIT BANG
bb_i2c_openOpens GPIO for bit banging I2C
bb_i2c_closeCloses GPIO for bit banging I2C
bb_i2c_zipPerforms multiple bit banged I2C transactions
I2C/SPI SLAVE
bsc_xferI2C/SPI as slave transfer
bsc_i2cI2C as slave transfer
SERIAL
serial_openOpens a serial device
serial_closeCloses a serial device
serial_read_byteReads a byte from a serial device
serial_write_byteWrites a byte to a serial device
serial_readReads bytes from a serial device
serial_writeWrites bytes to a serial device
serial_data_availableReturns number of bytes ready to be read
SERIAL BIT BANG (read only)
bb_serial_read_openOpen a GPIO for bit bang serial reads
bb_serial_read_closeClose a GPIO for bit bang serial reads
bb_serial_invertInvert serial logic (1 invert, 0 normal)
bb_serial_readRead bit bang serial data from a GPIO
SPI
spi_openOpens a SPI device
spi_closeCloses a SPI device
spi_readReads bytes from a SPI device
spi_writeWrites bytes to a SPI device
spi_xferTransfers bytes with a SPI device
SPI BIT BANG
bb_spi_openOpens GPIO for bit banging SPI
bb_spi_closeCloses GPIO for bit banging SPI
bb_spi_xferTransfers bytes with bit banging SPI
FILES
file_openOpens a file
file_closeCloses a file
file_readReads bytes from a file
file_writeWrites bytes to a file
file_seekSeeks to a position within a file
file_listList files which match a pattern
WAVES
wave_clearDeletes all waveforms
wave_add_newStarts a new waveform
wave_add_genericAdds a series of pulses to the waveform
wave_add_serialAdds serial data to the waveform
wave_createCreates a waveform from added data
wave_create_and_padCreates a waveform of fixed size from added data
wave_deleteDeletes a waveform
wave_send_onceTransmits a waveform once
wave_send_repeatTransmits a waveform repeatedly
wave_send_using_modeTransmits a waveform in the chosen mode
wave_chainTransmits a chain of waveforms
wave_tx_atReturns the current transmitting waveform
wave_tx_busyChecks to see if a waveform has ended
wave_tx_stopAborts the current waveform
wave_get_cbsLength in cbs of the current waveform
wave_get_max_cbsAbsolute maximum allowed cbs
wave_get_microsLength in microseconds of the current waveform
wave_get_max_microsAbsolute maximum allowed micros
wave_get_pulsesLength in pulses of the current waveform
wave_get_max_pulsesAbsolute maximum allowed pulses
UTILITIES
get_current_tickGet current tick (microseconds)
get_hardware_revisionGet hardware revision
get_pigpio_versionGet the pigpio version
pigpio.error_textGets error text from error number
pigpio.tickDiffReturns difference between two ticks

, ,

Leave a comment