drivers.Si1133.Si1133_V1.Si1133

class drivers.Si1133.Si1133_V1.Si1133(i2c_bus: int = 0, sensor_address: int = SI1133_ADDR)

Legacy V1 driver for the Si1133 UV and ambient light sensor.

Provides basic register-level access and a single-channel UV measurement path – no polynomial calibration, no lux output. The current driver in drivers.Si1133.Si1133.Si1133 exposes a full UVI + lux pipeline and is the recommended choice for new code.

The class is a thin SMBus shim: __init__() opens the bus, begin() verifies the part ID (must be 0x33) and starts autonomous channel-0 sampling, and readUV() / getIR() pull the raw ADC counts from the HOSTOUT registers.

What it measures:
  • UV (raw) – 16-bit ADC count from channel 0 (UV photodiode).

  • IR (raw) – 24-bit ADC count assembled from HOSTOUT2-HOSTOUT4.

No physical conversion is applied; callers must apply their own scaling factors if they need engineering units.

Variables:
  • i2c_bus (int) – I2C bus number passed at construction.

  • bus (smbus2.SMBus) – Open SMBus handle used for register traffic.

  • addr (int) – 7-bit I2C address of the sensor (default SI1133_ADDR = 0x55).

Example

Construct and read raw UV counts:

>>> from drivers.Si1133.Si1133_V1 import Si1133
>>> sensor = Si1133(i2c_bus=1)
>>> sensor.begin()
>>> raw_uv = sensor.readUV()

See also

SensorBase.SensorBase.GenericSensor

Abstract base class for Oizom sensor wrappers. This raw driver is not a subclass; a higher-level wrapper module adapts it to the GenericSensor contract.

drivers.Si1133.Si1133.Si1133

Current (V2) driver. Replaces this one with calibrated UVI and lux output across four ADC channels.

Initialize the V1 driver and open the underlying SMBus.

Opens smbus2.SMBus for the requested bus number and caches the sensor address. The chip itself is not reset or configured here – call begin() afterwards.

Parameters:
  • i2c_bus (int) – I2C bus number to use (typically 0 or 1 on Raspberry Pi hardware). Defaults to 0.

  • sensor_address (int) – 7-bit I2C address of the Si1133. Defaults to SI1133_ADDR (0x55).

Returns:

None.

Raises:

Example

>>> sensor = Si1133(i2c_bus=1)
>>> sensor.addr == 0x55
True

Note

This is the V1 entry point. See drivers.Si1133.Si1133.Si1133 for the calibrated current driver.

begin() bool | None

Initialize the sensor and configure channel 0 for UV measurement.

Sequence:
  1. Read SI1133_REG_PARTID; abort with False if it does not equal 0x33.

  2. Software reset (reset()).

  3. Select channel 0 only via SI1133_PARAM_CHLIST.

  4. Program channel 0 ADC config / sensitivity / post / meascount.

  5. Issue SI1133_START to start autonomous sampling.

Parameters:

None.

Returns:

False if the part ID does not match 0x33 (sensor missing or wrong device). Otherwise returns None after configuration completes.

Return type:

bool | None

Raises:

OSError – If any underlying I2C transaction fails.

Example

>>> sensor = Si1133(i2c_bus=1)
>>> sensor.begin() is None
True

Note

Starts the chip in autonomous mode; raw counts then appear in HOSTOUT registers and can be polled with readUV()/getIR(). For calibrated values, use drivers.Si1133.Si1133.Si1133.begin() instead.

getIR() int

Read the raw 24-bit IR ADC value from the host output registers.

Reads SI1133_REG_HOSTOUT2, SI1133_REG_HOSTOUT3, and SI1133_REG_HOSTOUT4 and assembles them big-endian into a 24-bit value.

Parameters:

None.

Returns:

Raw IR ADC value assembled from HOSTOUT2-HOSTOUT4.

Return type:

int

Raises:

OSError – If any I2C read fails.

Example

>>> sensor = Si1133(i2c_bus=1)
>>> sensor.begin()
>>> raw_ir = sensor.getIR()

Note

The implementation discards the value returned by the first read8() (HOSTOUT2) before shifting, so the assembled result effectively contains only HOSTOUT3 and HOSTOUT4. Bug-for-bug preserved here for backwards compatibility; use drivers.Si1133.Si1133.Si1133 for a corrected implementation.

printout() int

Print all host output register values (HOSTOUT0-HOSTOUT9) for debugging.

Reads SI1133_REG_HOSTOUT0 through SI1133_REG_HOSTOUT9 and prints each to stdout. Intended only for interactive bring-up.

Parameters:

None.

Returns:

Value of the last register read (HOSTOUT9).

Return type:

int

Raises:

OSError – If any I2C read fails.

Example

>>> sensor = Si1133(i2c_bus=1)
>>> sensor.printout()

Note

Uses raw print(); in production code prefer the structured logger used by drivers.Si1133.Si1133.Si1133.

read16(reg: int) int

Read a 16-bit little-endian value from the specified register.

Performs a 2-byte SMBus block read at reg and assembles the result as block[1] << 8 | block[0].

Parameters:

reg (int) – Register address to read from.

Returns:

16-bit unsigned value (LSB first on the wire).

Return type:

int

Raises:

OSError – If the I2C transaction fails.

Example

>>> sensor = Si1133(i2c_bus=1)
>>> sensor.read16(sensor.SI1133_REG_HOSTOUT0)

Note

Currently unused by the V1 driver itself but kept for callers that prefer a single block read over two byte reads in readUV().

read8(reg: int) int

Read a single byte from the specified register.

Thin wrapper around smbus2.SMBus.read_byte_data() against the cached sensor address addr.

Parameters:

reg (int) – Register address to read from (0x00 - 0x2C per the datasheet).

Returns:

Byte value read from the register (0-255).

Return type:

int

Raises:

OSError – If the I2C transaction fails (e.g. NACK, bus error).

Example

>>> sensor = Si1133(i2c_bus=1)
>>> sensor.read8(sensor.SI1133_REG_PARTID)
51
readParam(p: int) int

Read a parameter table value from the sensor.

Issues a parameter-query command (p | SI1133_PARAM_QUERY) to SI1133_REG_COMMAND, then reads the result from SI1133_REG_RESPONSE1.

Parameters:

p (int) – Parameter table address.

Returns:

Parameter value from SI1133_REG_RESPONSE1 (0-255).

Return type:

int

Raises:

OSError – If any I2C transaction fails.

Example

>>> sensor = Si1133(i2c_bus=1)
>>> sensor.readParam(sensor.SI1133_PARAM_CHLIST)

Note

Unlike drivers.Si1133.Si1133.Si1133.SI1133_paramRead(), this V1 implementation does not wait for the chip to enter sleep or check the response counter; misuse on a busy chip can return stale values.

readUV() int

Read the raw 16-bit UV ADC value from the host output registers.

Reads SI1133_REG_HOSTOUT0 (MSB) and SI1133_REG_HOSTOUT1 (LSB) and assembles them big-endian.

Parameters:

None.

Returns:

Raw UV ADC value (16-bit unsigned).

Return type:

int

Raises:

OSError – If either I2C read fails.

Example

>>> sensor = Si1133(i2c_bus=1)
>>> sensor.begin()
>>> raw_uv = sensor.readUV()

Note

This is an uncalibrated raw count – not a UV index. For calibrated UVI use drivers.Si1133.Si1133.Si1133.readUV().

reset() None

Perform a software reset of the sensor.

Writes SI1133_RESET_SW to SI1133_REG_COMMAND and then sleeps 10 ms (per the datasheet) so the chip can complete its internal reset sequence.

Parameters:

None.

Returns:

None.

Raises:

OSError – If the register write fails.

Example

>>> sensor = Si1133(i2c_bus=1)
>>> sensor.reset()

Note

All parameter table entries return to power-on defaults after a reset; begin() reprograms channel 0 immediately afterwards.

write8(reg: int, val: int) None

Write a single byte to the specified register.

Thin wrapper around smbus2.SMBus.write_byte_data().

Parameters:
  • reg (int) – Register address to write to.

  • val (int) – Byte value to write (0-255).

Returns:

None.

Raises:

OSError – If the I2C transaction fails.

Example

>>> sensor = Si1133(i2c_bus=1)
>>> sensor.write8(sensor.SI1133_REG_COMMAND, sensor.SI1133_START)
writeParam(p: int, v: int) int

Write a value to the sensor parameter table.

Loads v into SI1133_REG_HOSTIN0, issues a parameter-set command (p | SI1133_PARAM_SET) to SI1133_REG_COMMAND, then reads SI1133_REG_RESPONSE1.

Parameters:
  • p (int) – Parameter table address.

  • v (int) – Value to write (0-255).

Returns:

Value of SI1133_REG_RESPONSE1 immediately after the write.

Return type:

int

Raises:

OSError – If any I2C transaction fails.

Example

>>> sensor = Si1133(i2c_bus=1)
>>> sensor.writeParam(sensor.SI1133_PARAM_CHLIST, 0x01)

Note

Unlike drivers.Si1133.Si1133.Si1133.SI1133_paramSet(), this V1 implementation does not wait for sleep or verify the response counter – it is best used during initial configuration when the chip is known to be idle.

BITS_16 = 64
BITS_24 = 0
COUNT0 = 64
COUNT1 = 128
F_LARGE_IR = 2
F_LARGE_WHITE = 12
F_MEDIUM_IR = 1
F_SMALL_IR = 0
F_UV = 24
F_UV_DEEP = 25
F_WHITE = 11
RATE_LONG = 32
RATE_NORMAL = 0
RATE_SHORT = 96
RATE_VLONG = 64
SI1133_FORCE = 17
SI1133_PARAM_ADCCONFIG0 = 2
SI1133_PARAM_ADCCONFIG1 = 6
SI1133_PARAM_ADCCONFIG20 = 10
SI1133_PARAM_ADCCONFIG3 = 14
SI1133_PARAM_ADCCONFIG4 = 18
SI1133_PARAM_ADCCONFIG5 = 22
SI1133_PARAM_ADCPSOT0 = 4
SI1133_PARAM_ADCPSOT1 = 8
SI1133_PARAM_ADCPSOT2 = 12
SI1133_PARAM_ADCPSOT3 = 16
SI1133_PARAM_ADCPSOT4 = 20
SI1133_PARAM_ADCPSOT5 = 24
SI1133_PARAM_ADCSENS0 = 3
SI1133_PARAM_ADCSENS1 = 7
SI1133_PARAM_ADCSENS2 = 11
SI1133_PARAM_ADCSENS3 = 15
SI1133_PARAM_ADCSENS4 = 19
SI1133_PARAM_ADCSENS5 = 23
SI1133_PARAM_BURST = 43
SI1133_PARAM_CHLIST = 1
SI1133_PARAM_I2CADDR = 0
SI1133_PARAM_MEASCONFIG0 = 5
SI1133_PARAM_MEASCONFIG1 = 9
SI1133_PARAM_MEASCONFIG2 = 13
SI1133_PARAM_MEASCONFIG3 = 17
SI1133_PARAM_MEASCONFIG4 = 21
SI1133_PARAM_MEASCONFIG5 = 25
SI1133_PARAM_MEASCOUNT0 = 28
SI1133_PARAM_MEASCOUNT1 = 29
SI1133_PARAM_MEASCOUNT2 = 30
SI1133_PARAM_MEASRATEH = 26
SI1133_PARAM_MEASRATEL = 27
SI1133_PARAM_QUERY = 64
SI1133_PARAM_SET = 128
SI1133_PARAM_THRESHOLD0_H = 37
SI1133_PARAM_THRESHOLD0_L = 38
SI1133_PARAM_THRESHOLD1_H = 39
SI1133_PARAM_THRESHOLD1_L = 40
SI1133_PARAM_THRESHOLD2_H = 41
SI1133_PARAM_THRESHOLD2_L = 42
SI1133_PAUSE = 18
SI1133_REG_COMMAND = 11
SI1133_REG_HOSTIN0 = 10
SI1133_REG_HOSTIN1 = 9
SI1133_REG_HOSTIN2 = 8
SI1133_REG_HOSTIN3 = 7
SI1133_REG_HOSTOUT0 = 19
SI1133_REG_HOSTOUT1 = 20
SI1133_REG_HOSTOUT10 = 29
SI1133_REG_HOSTOUT11 = 30
SI1133_REG_HOSTOUT12 = 31
SI1133_REG_HOSTOUT13 = 32
SI1133_REG_HOSTOUT14 = 33
SI1133_REG_HOSTOUT15 = 34
SI1133_REG_HOSTOUT16 = 35
SI1133_REG_HOSTOUT17 = 36
SI1133_REG_HOSTOUT18 = 37
SI1133_REG_HOSTOUT19 = 38
SI1133_REG_HOSTOUT2 = 21
SI1133_REG_HOSTOUT20 = 39
SI1133_REG_HOSTOUT21 = 40
SI1133_REG_HOSTOUT22 = 41
SI1133_REG_HOSTOUT23 = 42
SI1133_REG_HOSTOUT24 = 43
SI1133_REG_HOSTOUT25 = 44
SI1133_REG_HOSTOUT3 = 22
SI1133_REG_HOSTOUT4 = 23
SI1133_REG_HOSTOUT5 = 24
SI1133_REG_HOSTOUT6 = 25
SI1133_REG_HOSTOUT7 = 26
SI1133_REG_HOSTOUT8 = 27
SI1133_REG_HOSTOUT9 = 28
SI1133_REG_INFO0 = 3
SI1133_REG_INFO1 = 4
SI1133_REG_IRQ_ENABLE = 15
SI1133_REG_IRQ_STATUS = 18
SI1133_REG_MFRID = 2
SI1133_REG_PARTID = 0
SI1133_REG_RESPONSE0 = 17
SI1133_REG_RESPONSE1 = 16
SI1133_REG_REVID = 1
SI1133_RESET_CMD_CTR = 0
SI1133_RESET_SW = 1
SI1133_START = 19
addr = 85
bus
i2c_bus = 0