Skip to main content
Reacgen Biosystems

Python API reference

Complete API for the turbidvision Python client library.

The package exposes the TurbidVision client plus the Status, Snapshot, LatestReading, and TriggeredReading dataclasses and a TurbidVisionError exception. Read methods return nan or None when a value is unavailable; command methods raise TurbidVisionError on a transport failure. For the underlying register addresses, see the I²C interface reference.

Construction

TurbidVision(bus: int | SMBus = 1, address: int = 0x69)

bus is either an I²C bus number (e.g. 1 for /dev/i2c-1) or an already-open smbus2.SMBus. When a number is given, this object owns the bus and opens/closes it on open()/close() or context entry/exit. A passed-in SMBus instance is used as-is and never closed for you.

Lifecycle and connection

MethodReturnsDescription
open()TurbidVisionOpen the bus when this object owns it. Returns self. Called automatically on context entry.
close()NoneClose the bus if this object owns it. A passed-in SMBus instance is never closed for you.
__enter__() / __exit__()TurbidVisionContext-manager protocol: opens on entry, closes on exit. Use a 'with' block.
busSMBusProperty returning the underlying open bus. Raises TurbidVisionError if the bus is not open.
is_present()boolTrue if the sensor responds (status register reads OK).

Measurement reads

Each returns a float in the column unit, or nan when the value is unavailable.

MethodRegisterDescription
measured_reflectance()0x10Raw reflectance ratio (unitless).
normalized_reflectance()0x11Reflectance normalized to the initial reference (and blank, if set).
calibrated_density()0x12Unfiltered density in g/L from the calibration lookup table.
growth_rate()0x13Kalman filter specific growth rate in 1/h.
laser_power_mw()0x14Laser optical output power in mW.
filtered_calibrated_density()0x16Kalman-filtered density in g/L.
filtered_calibrated_growth_rate()0x17Filtered volumetric growth rate in g/L/h.
calibrated_absolute_growth_rate()0x18Unfiltered volumetric growth rate in g/L/h.

Raw register reads

MethodReturnsDescription
read_float(reg)floatRead a 32-bit little-endian float. Returns nan on a non-OK status.
read_uint32(reg)int | NoneRead a 32-bit little-endian unsigned int. Returns None on error.
read_status()StatusRead and decode the live status byte (0x20). Raises TurbidVisionError on a non-OK status.
error_flags()int | NoneRead the system error/warning vector (0x21). Returns the bitmask (0 = no faults) or None on error.
reading_number()int | NoneMonotonic reading counter (0x30). None on error.
read_all()SnapshotRead every measurement register plus the status byte and error flags.

Atomic host readings

These methods return normalized reflectance and the calibrated value in one coherent result with age, quality, diagnostic, calibration flag, and unit metadata. A one-shot is observational and does not change the normal reading counter, rolling average, Growth Model, datalog, or normal capture cadence.

MethodReturnsDescription
latest_reading()LatestReadingReturn one coherent latest normal-cadence sample from register 0x31, including its age, calibration flag, calibration unit, normalized reflectance, and calibrated value.
triggered_reading()TriggeredReadingRead the pending or completed one-shot result latch at register 0x32 without starting a new capture.
trigger_reading(timeout=35.0, poll_interval=0.05)TriggeredReadingRequest a fresh observational capture and block until its new sequence completes. Raises TimeoutError on timeout and TurbidVisionError when the completed sample is invalid.

Commands

Each returns None and raises TurbidVisionError on a transport failure. Job, blank, and calibration commands run asynchronously on the sensor; poll the status byte to confirm completion.

MethodDescription
start_job()Start the OD job (control 0x01). Resets the register bank to NaN.
stop_job()Stop the OD job and turn off the laser (control 0x02).
take_blank()Capture a blank reference (control 0x03). Stop the job first.
take_cal_reading()Capture a calibration reading against a known standard (control 0x04).
deactivate_laser()Stop the laser power controller and turn the laser off (control 0x05).
erase_initial()Erase the stored initial reference (control 0x06).
clear_errors()Clear the latching error-class flags in register 0x21 (control 0x07).
set_laser_power_pct(pct)Set the laser target as a percentage of maximum (0.0 to 100.0) and activate the controller. Writes register 0x50.

Polling

MethodReturnsDescription
wait_for_status(mask, timeout=35.0, poll_interval=0.2, clear=False)boolBlock until (status & mask) is set, or cleared when clear is True. Returns True on success, False on timeout.
wait_until(predicate, timeout=35.0, poll_interval=0.2)boolBlock until predicate(status) is True. predicate takes a Status. Returns False on timeout.

Data classes

Status

Decoded result of read_status(). Build one from a raw byte with the classmethod Status.from_byte(flags); str(status) gives a compact one-line summary.

FieldTypeDescription
rawintThe raw status byte.
job_runningboolOD job is active (bit 0).
has_blankboolA blank reference has been captured (bit 1).
has_initialboolInitial reference is complete (bit 2).
laser_pwrctl_runningboolLaser power controller is active (bit 3).
laser_stableboolLaser output has stabilized (bit 4).
reflectance_stableboolReflectance is stable (bit 5).
errorboolAny error/warning flag is set; read error_flags() (bit 6).
calibratedboolA usable calibration lookup table is present (bit 7).

Snapshot

Full snapshot returned by read_all(). Float fields are nan when unavailable.

FieldTypeDescription
reading_numberint | NoneMonotonic reading counter, or None on read error.
statusStatusDecoded status byte.
error_flagsint | NoneError/warning vector, or None on error.
measured_reflectancefloatnan when unavailable.
normalized_reflectancefloatnan when unavailable.
calibrated_densityfloatnan when unavailable.
growth_ratefloatnan when the Kalman filter is disabled.
laser_power_mwfloatnan when unavailable.
filtered_calibrated_densityfloatnan when the Kalman filter is disabled.
filtered_calibrated_growth_ratefloatnan when the Kalman filter is disabled.
calibrated_absolute_growth_ratefloatnan when the Kalman filter is disabled.

LatestReading

Atomic latest normal-cadence sample returned by latest_reading().

FieldTypeDescription
flagsintPacked valid, calibrated, and job-running-at-capture flags.
qualityintReading quality code.
calibration_unitint | None0 g/L, 1 OD600, 2 FNU, 3 NTU, 4 custom, or None.
diagnostic_codeintDiagnostic code associated with the sample.
reading_numberintNormal-cadence reading number.
age_msint | NoneMilliseconds since capture, or None before a sample exists.
normalized_reflectancefloatNormalized reflectance, or nan when no initial reference is available.
calibrated_valuefloatValue in calibration_unit, or nan when no usable calibration was applied.
valid / calibrated / job_running_at_capturebool propertiesConvenience properties decoded from flags.

TriggeredReading

Latched one-shot state returned by triggered_reading() and the completed sample returned by trigger_reading().

FieldTypeDescription
request_sequenceintSequence assigned to the one-shot request.
phaseint0 idle, 1 pending, or 2 complete.
flagsintPacked valid, calibrated, and job-running-at-capture flags.
qualityintReading quality code.
calibration_unitint | None0 g/L, 1 OD600, 2 FNU, 3 NTU, 4 custom, or None.
diagnostic_codeintDiagnostic code associated with the request or sample.
age_msint | NoneMilliseconds since capture, or None before a sample exists.
normalized_reflectancefloatNormalized reflectance, or nan when no initial reference is available.
calibrated_valuefloatValue in calibration_unit, or nan when no usable calibration was applied.
valid / calibrated / job_running_at_capturebool propertiesConvenience properties decoded from flags.

TurbidVisionError

Subclass of IOError, raised on an I²C transport failure or a non-OK response status.

Constants

All constants are module-level (e.g. turbidvision.STATUS_HAS_INITIAL); the STATUS_* masks are also re-exported as class attributes (sensor.STATUS_HAS_INITIAL) for convenience.

Status bit masks

Use with read_status().raw or wait_for_status().

ConstantBit
STATUS_JOB_RUNNING0
STATUS_HAS_BLANK1
STATUS_HAS_INITIAL2
STATUS_LASER_PWRCTL_RUNNING3
STATUS_LASER_STABLE4
STATUS_REFLECTANCE_STABLE5
STATUS_ERROR6
STATUS_CALIBRATED7

Error flag masks

Decode the result of error_flags() (register 0x21). Bits 0 to 4 are error-class (latching); bits 5 to 8 are warning-class.

ConstantBit
ERR_SAFETY_CRITICAL0
ERR_SAFETY_WARNING1
ERR_PI_FAILED2
ERR_LOW_HEAP3
ERR_STORAGE4
WARN_NO_BLANK5
WARN_NO_INITIAL6
WARN_WIFI_DOWN7
WARN_OTA8

Response status codes

ConstantValueMeaning
RESP_OK0x00Read succeeded; payload is valid.
RESP_UNKNOWN_REGISTER0x01Unknown register; no data follows.
RESP_WIRE_ERROR0xFFClient-side wire-error sentinel; not emitted by the sensor.

Register constants (REG_*) and command constants (CMD_*) map one-to-one to the addresses and command bytes in the I²C interface reference. For runnable scripts using this API, see the Python examples.