Library API

ScienceLab

Convenience module that creates instances of every instrument for you.

Every PSLab instrument can be imported and instantiated individually. However, if you need to use several at once the ScienceLab class provides a convenient collection.

class pslab.sciencelab.ScienceLab[source]

Bases: pslab.serial_handler.SerialHandler

Aggregate interface for the PSLab’s instruments.

logic_analyzer
Type

pslab.LogicAnalyzer

oscilloscope
Type

pslab.Oscilloscope

waveform_generator
Type

pslab.WaveformGenerator

pwm_generator
Type

pslab.PWMGenerator

multimeter
Type

pslab.Multimeter

power_supply
Type

pslab.PowerSupply

i2c
Type

pslab.I2CMaster

nrf
Type

pslab.peripherals.NRF24L01

enable_uart_passthrough(baudrate: int, persist=False)[source]

Relay all data received by the device to TXD/RXD.

If a period > 0.5 seconds elapses between two transmit/receive events, the device resets and resumes normal mode. This timeout feature has been implemented in lieu of a hard reset option.

Can be used to load programs into secondary microcontrollers with bootloaders such ATMEGA or ESP8266

Parameters
  • baudrate (int) – Baudrate of the UART bus.

  • persist (bool, optional) – If set to True, the device will stay in passthrough mode until the next power cycle. Otherwise(default scenario), the device will return to normal operation if no data is sent/received for a period greater than one second at a time.

read_log()[source]

Read hardware debug log.

Returns

log – Bytes read from the hardware debug log.

Return type

bytes

read_uart()[source]

Read a single byte from the UART bus.

Returns

byte – Byte value read from the UART bus.

Return type

int

read_uart_status()[source]

Return available bytes in UART buffer.

Returns

status

Return type

int

reset()[source]

Reset the device.

Standalone mode will be enabled if an OLED is connected to the I2C port.

rgb_led(colors: List, output: str = 'RGB', order: str = 'GRB')[source]

Set shade of a WS2812B RGB LED.

Parameters
  • colors (list) – List of three values between 0-255, where each value is the intensity of red, green, and blue, respectively. When daisy chaining several LEDs, colors should be a list of three-value lists.

  • output ({"RGB", "PGC", "SQ1"}, optional) – Pin on which to output the pulse train setting the LED color. The default value, “RGB”, sets the color of the built-in WS2812B (PSLab v6 only).

  • order (str, optional) – Color order of the connected LED as a three-letter string. The built-in LED has order “GRB”, which is the default.

Examples

Set the built-in WS2812B to yellow.

>>> import pslab
>>> psl = pslab.ScienceLab()
>>> psl.rgb_led([10, 10, 0])

Set a chain of three RGB WS2812B connected to SQ1 to red, cyan, and magenta.

>>> psl.rgb_led([[10,0,0],[0,10,10],[10,0,10]], output="SQ1", order="RGB")
set_uart_baud(baudrate: int)[source]

Set the baudrate of the UART bus.

Parameters

baudrate (int) – Baudrate to set on the UART bus.

property temperature

Temperature of the MCU in degrees Celsius.

Type

float

write_uart(byte: int)[source]

Write a single byte to the UART bus.

Parameters

byte (int) – Byte value to write to the UART bus.