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
| Method | Returns | Description |
|---|
| begin(bool initWire = true, uint32_t clockHz = 400000) | bool | Initialize. 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() | bool | True 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.
| Method | Register | Description |
|---|
| measuredReflectance() | 0x10 | Raw reflectance ratio (unitless). |
| normalizedReflectance() | 0x11 | Reflectance normalized to the initial reference (and blank, if set). |
| calibratedDensity() | 0x12 | Unfiltered density in g/L from the calibration lookup table. |
| growthRate() | 0x13 | Kalman filter specific growth rate in 1/h. |
| laserPowerMw() | 0x14 | Laser optical output power in mW. |
| filteredCalibratedDensity() | 0x16 | Kalman-filtered density in g/L. |
| filteredCalibratedGrowthRate() | 0x17 | Filtered volumetric growth rate in g/L/h. |
| calibratedAbsoluteGrowthRate() | 0x18 | Unfiltered volumetric growth rate in g/L/h. |
Raw register reads
| Method | Returns | Description |
|---|
| readFloat(uint8_t reg, float &out) | bool | Read a float register into out. Returns false on a non-OK status. |
| readFloat(uint8_t reg) | float | Read a float register. Returns NAN on error. |
| readUint32(uint8_t reg, uint32_t &out) | bool | Read a uint32 register into out. False on error. |
| readingNumber() | uint32_t | Monotonic reading counter (0x30). Returns 0 on error. |
| errorFlags() | uint32_t | System error/warning vector (0x21). Returns 0 on error or when there are no faults. |
| readStatus() | TVStatus | Read and decode the live status byte (0x20). |
| readAll(TVReading &out) | bool | Fill 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.
| Method | Returns | Description |
|---|
| readLatestReading(TVLatestReading &out) | bool | Read one coherent latest normal-cadence sample from register 0x31, including age, calibration flag, calibration unit, normalized reflectance, and calibrated value. |
| readTriggeredReading(TVTriggeredReading &out) | bool | Read 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) | bool | Request 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.
| Method | Description |
|---|
| 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
| Method | Returns | Description |
|---|
| waitForStatusBit(uint8_t mask, uint32_t timeoutMs = 35000, bool waitForClear = false, uint32_t pollMs = 200) | bool | Poll the status register until (status & mask) is set, or cleared when waitForClear is true. Returns true on success, false on timeout. |
Output helpers
| Method | Returns | Description |
|---|
| printStatus(Stream &out = Serial) | void | Print the decoded status byte to out. |
| printReadings(Stream &out = Serial) | void | Print the reading number and all eight float registers to out. |
Low-level building blocks
| Method | Returns | Description |
|---|
| sendCommand(uint8_t cmd) | bool | Write a raw command byte to the control register (0x40). True if ACKed. |
| writeFloat(uint8_t reg, float value) | bool | Write a float to a register. True if ACKed. |
Data structures
TVStatus
Decoded result of readStatus().
| Field | Type | Description |
|---|
| raw | uint8_t | The raw status byte. |
| jobRunning | bool | OD job is active (bit 0). |
| hasBlank | bool | A blank reference has been captured (bit 1). |
| hasInitial | bool | Initial reference is complete (bit 2). |
| laserPwrctlRunning | bool | Laser power controller is active (bit 3). |
| laserStable | bool | Laser output has stabilized (bit 4). |
| reflectanceStable | bool | Reflectance is stable (bit 5). |
| error | bool | Any error/warning flag is set; read errorFlags() (bit 6). |
| calibrated | bool | A usable calibration lookup table is present (bit 7). |
| valid | bool | False if the status read failed. |
TVReading
Full snapshot returned via readAll(TVReading&). Float fields are NAN when unavailable.
| Field | Type | Description |
|---|
| readingNumber | uint32_t | Monotonic reading counter. |
| measuredReflectance | float | NAN when unavailable. |
| normalizedReflectance | float | NAN when unavailable. |
| calibratedDensity | float | NAN when unavailable. |
| growthRate | float | NAN when the Kalman filter is disabled. |
| laserPowerMw | float | NAN when unavailable. |
| filteredCalibratedDensity | float | NAN when the Kalman filter is disabled. |
| filteredCalibratedGrowthRate | float | NAN when the Kalman filter is disabled. |
| calibratedAbsoluteGrowthRate | float | NAN when the Kalman filter is disabled. |
| valid | bool | False if the reading-number read failed. |
TVLatestReading
Atomic latest normal-cadence sample filled by readLatestReading().
| Field | Type | Description |
|---|
| flags | uint8_t | Packed valid, calibrated, and job-running-at-capture flags. |
| quality | uint8_t | Reading quality code. |
| calibrationUnit | uint8_t | 0 g/L, 1 OD600, 2 FNU, 3 NTU, 4 custom, or 0xFF none. |
| diagnosticCode | uint16_t | Diagnostic code associated with the sample. |
| readingNumber | uint32_t | Normal-cadence reading number. |
| ageMs | uint32_t | Milliseconds since capture, or 0xFFFFFFFF before a sample exists. |
| normalizedReflectance | float | Normalized reflectance, or NAN when no initial reference is available. |
| calibratedValue | float | Value in calibrationUnit, or NAN when no usable calibration was applied. |
| responseValid | bool | False if the register read failed. |
| sampleValid() / calibrated() / jobRunningAtCapture() | bool methods | Convenience accessors decoded from flags. |
TVTriggeredReading
One-shot state and result filled by readTriggeredReading() or triggerReading().
| Field | Type | Description |
|---|
| requestSequence | uint16_t | Sequence assigned to the one-shot request. |
| phase | uint8_t | 0 idle, 1 pending, or 2 complete. |
| flags | uint8_t | Packed valid, calibrated, and job-running-at-capture flags. |
| quality | uint8_t | Reading quality code. |
| calibrationUnit | uint8_t | 0 g/L, 1 OD600, 2 FNU, 3 NTU, 4 custom, or 0xFF none. |
| diagnosticCode | uint16_t | Diagnostic code associated with the request or sample. |
| ageMs | uint32_t | Milliseconds since capture, or 0xFFFFFFFF before a sample exists. |
| normalizedReflectance | float | Normalized reflectance, or NAN when no initial reference is available. |
| calibratedValue | float | Value in calibrationUnit, or NAN when no usable calibration was applied. |
| responseValid | bool | False if the register read failed. |
| sampleValid() / calibrated() / jobRunningAtCapture() | bool methods | Convenience accessors decoded from flags. |
Constants
Packed-reading flag masks
Use with TVLatestReading.flags or TVTriggeredReading.flags.
| Macro | Bit |
|---|
| TV_READING_VALID | 0 |
| TV_READING_CALIBRATED | 1 |
| TV_READING_JOB_RUNNING | 2 |
Status bit masks
Use with readStatus().raw or waitForStatusBit(). See the I²C reference for what each bit means.
| Macro | Bit |
|---|
| TV_STATUS_JOB_RUNNING | 0 |
| TV_STATUS_HAS_BLANK | 1 |
| TV_STATUS_HAS_INITIAL | 2 |
| TV_STATUS_LASER_PWRCTL_RUNNING | 3 |
| TV_STATUS_LASER_STABLE | 4 |
| TV_STATUS_REFLECTANCE_STABLE | 5 |
| TV_STATUS_ERROR | 6 |
| TV_STATUS_CALIBRATED | 7 |
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.
| Macro | Bit |
|---|
| TV_ERR_SAFETY_CRITICAL | 0 |
| TV_ERR_SAFETY_WARNING | 1 |
| TV_ERR_PI_FAILED | 2 |
| TV_ERR_LOW_HEAP | 3 |
| TV_ERR_STORAGE | 4 |
| TV_WARN_NO_BLANK | 5 |
| TV_WARN_NO_INITIAL | 6 |
| TV_WARN_WIFI_DOWN | 7 |
| TV_WARN_OTA | 8 |
Response status codes
| Macro | Value | Meaning |
|---|
| TV_RESP_OK | 0x00 | Read succeeded; data bytes are valid. |
| TV_RESP_UNKNOWN_REGISTER | 0x01 | Unknown register; no data follows. |
| TV_RESP_WIRE_ERROR | 0xFF | Client-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.