Bus Pirate v3

class electronics.gateways.buspirate.BusPirate(device, baud=115200, debug=False)

Class for using a Bus Pirate as I2C, GPIO or SPI or UART gateway. The code uses the Bus Pirate in bitbang mode (This doesn’t mean the pins are bitbanged but that the communication is in binary mode instead of an ascii shell) For bitbang mode to work you need at least the v2.6 firmware. I’m testing this code on a Bus Pirate v3.5, other devices probably work.

Example:
>>> from electronics.gateways import BusPirate
>>> # Open the Bus Pirate at the first USB-serial port
>>> gw = BusPirate("/dev/ttyUSB0") 
>>> # It is also possible to specify the baudrate
>>> other_pirate = BusPirate("/dev/ttyUSB1", baud=9600) 

The Bus Pirate supports multiple modes. This module will make sure the Bus Pirate is in the correct mode as soon as you use a read or write command. You can specify the peripheral configuration as attributes on the gateway instance. The configuration will be applied when switching the Bus Pirate mode. You can also switch the peripheral configuration at runtime with the set_peripheral command.

Example:
>>> from electronics.gateways import BusPirate
>>> from electronics.devices import LM75
>>> # Open the Bus Pirate
>>> gw = BusPirate("/dev/ttyUSB0") 
>>> # Enable the power supply and the pull-ups in the next mode switch
>>> gw.power = True 
>>> gw.pullup = True 
>>> # Add a device so the config will apply
>>> sensor = LM75(gw) 
>>> # The power and pullup is now enabled.
>>> # Changing peripherals at runtime:
>>> gw.set_peripheral(pullup=False, aux=True) 
>>> # The pullup is now  disabled and the aux pin set to VCC
Parameters:
  • device – The path to the unix device created when plugging in the Bus Pirate.
  • baud – The Bus Pirate baudrate. The default is 115200
get_aux_pin()

Get reference to the aux output on the Bus Pirate :return: DigitalOutputPin instance

get_chip_select_pin()

Get reference to the chip select output on the Bus Pirate :return: DigitalOutputPin instance

set_peripheral(power=None, pullup=None, aux=None, chip_select=None)

Set the peripheral config at runtime. If a parameter is None then the config will not be changed.

Parameters:
  • power – Set to True to enable the power supply or False to disable
  • pullup – Set to True to enable the internal pull-up resistors. False to disable
  • aux – Set the AUX pin output state
  • chip_select – Set the CS pin output state
switch_mode(new_mode)

Explicitly switch the Bus Pirate mode

Parameters:new_mode – The mode to switch to. Use the buspirate.MODE_* constants