Skip to main content
Reacgen Biosystems

Arduino API reference

Complete API for the TurbidVision Arduino/ESP32 C++ client library.

Everything is exposed through one class, TurbidVision, built on the standard Wire library. Named reads return NAN on a failed or unavailable read; command methods return true only if the write was ACKed. For the underlying register addresses and semantics, see the I²C interface reference.

Construction

TurbidVision(uint8_t address = 0x69, TwoWire &wire = Wire);

Construct a client for the given 7-bit address on the given Wirebus. Both arguments default, so TurbidVision sensor; targets 0x69 on the default bus. The constant TURBIDVISION_DEFAULT_ADDRESS is 0x69.

Connection

MethodReturnsDescription
begin(bool initWire = true, uint32_t clockHz = 400000)boolInitialize. When initWire is true, calls wire.begin() and sets the bus clock to clockHz. For custom ESP32 pins, call Wire.begin(sda, scl) yourself and pass initWire = false. Returns true if the sensor ACKs on the bus.
isConnected()boolTrue if the sensor ACKs its address on the bus.

Measurement reads

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

MethodRegisterDescription
measuredReflectance()0x10Raw reflectance ratio (unitless).
normalizedReflectance()0x11Reflectance normalized to the initial reference (and blank, if set).
calibratedDensity()0x12Unfiltered density in g/L from the calibration lookup table.
growthRate()0x13Kalman filter specific growth rate in 1/h.
laserPowerMw()0x14Laser optical output power in mW.
filteredCalibratedDensity()0x16Kalman-filtered density in g/L.
filteredCalibratedGrowthRate()0x17Filtered volumetric growth rate in g/L/h.
calibratedAbsoluteGrowthRate()0x18Unfiltered volumetric growth rate in g/L/h.

Raw register reads

MethodReturnsDescription
readFloat(uint8_t reg, float &out)boolRead a float register into out. Returns false on a non-OK status.
readFloat(uint8_t reg)floatRead a float register. Returns NAN on error.
readUint32(uint8_t reg, uint32_t &out)boolRead a uint32 register into out. False on error.
readingNumber()uint32_tMonotonic reading counter (0x30). Returns 0 on error.
errorFlags()uint32_tSystem error/warning vector (0x21). Returns 0 on error or when there are no faults.
readStatus()TVStatusRead and decode the live status byte (0x20).
readAll(TVReading &out)boolFill out with every measurement register plus the reading number. out.valid is false if the reading-number read failed.

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
readLatestReading(TVLatestReading &out)boolRead one coherent latest normal-cadence sample from register 0x31, including age, calibration flag, calibration unit, normalized reflectance, and calibrated value.
readTriggeredReading(TVTriggeredReading &out)boolRead the pending or completed one-shot result latch at register 0x32 without starting a new capture.
triggerReading(TVTriggeredReading &out, uint32_t timeoutMs = 35000, uint32_t pollMs = 50)boolRequest a fresh observational capture and block for its new sequence. Returns true only when the request completes with a valid sample; out retains failure details.

Commands

Each returns bool (true if the write was ACKed). Job, blank, and calibration commands run asynchronously on the sensor; poll the status byte to confirm completion.

MethodDescription
startJob()Start the OD job (control 0x01). Resets the register bank to NaN.
stopJob()Stop the OD job and turn off the laser (control 0x02).
takeBlank()Capture a blank reference (control 0x03). Stop the job first.
takeCalReading()Capture a calibration reading against a known standard (control 0x04).
deactivateLaser()Stop the laser power controller and turn the laser off (control 0x05).
eraseInitial()Erase the stored initial reference (control 0x06).
clearErrors()Clear the latching error-class flags in register 0x21 (control 0x07).
setLaserPowerPct(float pct)Set the laser target as a percentage of maximum (0.0 to 100.0) and activate the controller. Writes register 0x50.

Polling

MethodReturnsDescription
waitForStatusBit(uint8_t mask, uint32_t timeoutMs = 35000, bool waitForClear = false, uint32_t pollMs = 200)boolPoll the status register until (status & mask) is set, or cleared when waitForClear is true. Returns true on success, false on timeout.

Output helpers

MethodReturnsDescription
printStatus(Stream &out = Serial)voidPrint the decoded status byte to out.
printReadings(Stream &out = Serial)voidPrint the reading number and all eight float registers to out.

Low-level building blocks

MethodReturnsDescription
sendCommand(uint8_t cmd)boolWrite a raw command byte to the control register (0x40). True if ACKed.
writeFloat(uint8_t reg, float value)boolWrite a float to a register. True if ACKed.

Data structures

TVStatus

Decoded result of readStatus().

FieldTypeDescription
rawuint8_tThe raw status byte.
jobRunningboolOD job is active (bit 0).
hasBlankboolA blank reference has been captured (bit 1).
hasInitialboolInitial reference is complete (bit 2).
laserPwrctlRunningboolLaser power controller is active (bit 3).
laserStableboolLaser output has stabilized (bit 4).
reflectanceStableboolReflectance is stable (bit 5).
errorboolAny error/warning flag is set; read errorFlags() (bit 6).
calibratedboolA usable calibration lookup table is present (bit 7).
validboolFalse if the status read failed.

TVReading

Full snapshot returned via readAll(TVReading&). Float fields are NAN when unavailable.

FieldTypeDescription
readingNumberuint32_tMonotonic reading counter.
measuredReflectancefloatNAN when unavailable.
normalizedReflectancefloatNAN when unavailable.
calibratedDensityfloatNAN when unavailable.
growthRatefloatNAN when the Kalman filter is disabled.
laserPowerMwfloatNAN when unavailable.
filteredCalibratedDensityfloatNAN when the Kalman filter is disabled.
filteredCalibratedGrowthRatefloatNAN when the Kalman filter is disabled.
calibratedAbsoluteGrowthRatefloatNAN when the Kalman filter is disabled.
validboolFalse if the reading-number read failed.

TVLatestReading

Atomic latest normal-cadence sample filled by readLatestReading().

FieldTypeDescription
flagsuint8_tPacked valid, calibrated, and job-running-at-capture flags.
qualityuint8_tReading quality code.
calibrationUnituint8_t0 g/L, 1 OD600, 2 FNU, 3 NTU, 4 custom, or 0xFF none.
diagnosticCodeuint16_tDiagnostic code associated with the sample.
readingNumberuint32_tNormal-cadence reading number.
ageMsuint32_tMilliseconds since capture, or 0xFFFFFFFF before a sample exists.
normalizedReflectancefloatNormalized reflectance, or NAN when no initial reference is available.
calibratedValuefloatValue in calibrationUnit, or NAN when no usable calibration was applied.
responseValidboolFalse if the register read failed.
sampleValid() / calibrated() / jobRunningAtCapture()bool methodsConvenience accessors decoded from flags.

TVTriggeredReading

One-shot state and result filled by readTriggeredReading() or triggerReading().

FieldTypeDescription
requestSequenceuint16_tSequence assigned to the one-shot request.
phaseuint8_t0 idle, 1 pending, or 2 complete.
flagsuint8_tPacked valid, calibrated, and job-running-at-capture flags.
qualityuint8_tReading quality code.
calibrationUnituint8_t0 g/L, 1 OD600, 2 FNU, 3 NTU, 4 custom, or 0xFF none.
diagnosticCodeuint16_tDiagnostic code associated with the request or sample.
ageMsuint32_tMilliseconds since capture, or 0xFFFFFFFF before a sample exists.
normalizedReflectancefloatNormalized reflectance, or NAN when no initial reference is available.
calibratedValuefloatValue in calibrationUnit, or NAN when no usable calibration was applied.
responseValidboolFalse if the register read failed.
sampleValid() / calibrated() / jobRunningAtCapture()bool methodsConvenience accessors decoded from flags.

Constants

Packed-reading flag masks

Use with TVLatestReading.flags or TVTriggeredReading.flags.

MacroBit
TV_READING_VALID0
TV_READING_CALIBRATED1
TV_READING_JOB_RUNNING2

Status bit masks

Use with readStatus().raw or waitForStatusBit(). See the I²C reference for what each bit means.

MacroBit
TV_STATUS_JOB_RUNNING0
TV_STATUS_HAS_BLANK1
TV_STATUS_HAS_INITIAL2
TV_STATUS_LASER_PWRCTL_RUNNING3
TV_STATUS_LASER_STABLE4
TV_STATUS_REFLECTANCE_STABLE5
TV_STATUS_ERROR6
TV_STATUS_CALIBRATED7

Error flag masks

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

MacroBit
TV_ERR_SAFETY_CRITICAL0
TV_ERR_SAFETY_WARNING1
TV_ERR_PI_FAILED2
TV_ERR_LOW_HEAP3
TV_ERR_STORAGE4
TV_WARN_NO_BLANK5
TV_WARN_NO_INITIAL6
TV_WARN_WIFI_DOWN7
TV_WARN_OTA8

Response status codes

MacroValueMeaning
TV_RESP_OK0x00Read succeeded; data bytes are valid.
TV_RESP_UNKNOWN_REGISTER0x01Unknown register; no data follows.
TV_RESP_WIRE_ERROR0xFFClient-side wire-error sentinel; not emitted by the sensor.

Register macros (TV_REG_*) and command macros (TV_CMD_*) map one-to-one to the addresses and command bytes in the I²C interface reference. For runnable sketches using this API, see the Arduino examples.