class Analog Port

The analog object is used to read one of the analog inputs.

Attention

Attention the analog reference voltage on all OMC-048 loggers with BL: 1.03B0 and upwards will be 5V! All other OMC-048 loggers got a 2.5V reference voltage.

Constructor

class omc048.analog_voltage(id: integer)

Create an analog object associated with one of the two analog voltage ports. Use port number 1 for 0-24V input(pin 18) and number 2 for 0-5V input(pin 19)

  • id is the analog port number.

class omc048.analog_current(id: integer)

Create an analog object associated with one of the four analog mA ports. Use port number 1 to 4 for the ports connected to respectivly pin 23 to 26.

  • id is the analog port number.

Methods

analog.read() float

Read the analog input value from the port. The returned value is in millivolts for the voltage ports and in milliampere for the mA inputs.

analog.read_raw() integer

Read the raw analog input value from the port. The returned value is the unconverted value from the ADC input ranging between –32768 and 32767. In practice this value should not be below -10.

analog.calibrate(level: integer)

Caution

Wrong calibration values will lead to incorrect ranges on the analog inputs!

Set the calibration value for specified level. The low level calibration is for 0V/0mA, the high level is for 24mA/5V/24V depending on the port.

  • level The value to calibrate. 0 for low and 1 for high.

For example applying 0mA on the first 24mA port (Pin 23), than entering analog.calibrate(0), will calibrate the 0mA value/low value to the applied current. The same applies to the upper value, apply 24mA to the first 24mA port and the 24mA value/high value will be set to the applied current.

Example

The following example prints a warning when a low voltage is reached.

import omc048

a2 = omc048.analog_voltage(2)
low_voltage = False
while True:
    if (not low_voltage) and (a2.read() < 2.8):
        low_voltage = True
        print("Low voltage warning!")

The following code shows an example printing the analogue values of both ports every second.

import omc048
import obs

start = obs.millis()
a1 = omc048.analog_voltage(1)
a2 = omc048.analog_voltage(2)

while True:
    if obs.elapsed_millis(start) > 1000:
        print(a1.read())
        print(a2.read())
        start = obs.millis()