Bus Pirate v3¶
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.
>>> 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.
>>> 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
- device – The path to the unix device created when plugging in the Bus Pirate.
- baud – The Bus Pirate baudrate. The default is 115200
Get reference to the aux output on the Bus Pirate :return: DigitalOutputPin instance
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.
- 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
Explicitly switch the Bus Pirate mode
Parameters: new_mode – The mode to switch to. Use the buspirate.MODE_* constants