-
Notifications
You must be signed in to change notification settings - Fork 0
Pica
Markus Grönholm edited this page Jun 11, 2026
·
6 revisions
python -mpip install pyserial alshain
import alshain
import serial
import sys
# Serial port as first command line parameter
com = serial.Serial( sys.argv[1], alshain.BAUDRATE, timeout = 0.25 )
dev = alshain.Pica( com, address = 1 )
# Enable photometer source
dev.write( alshain.Pica.Parameters.PULSE_ENABLE, 1 )
# Read results
print( dev.read( alshain.Pica.Parameters.RESULT ) )# Pica measures constantly, measurement loop can be started and stopped
dev.write( alshain.Pica.Parameters.PULSE_ENABLE, 0 ) # Stop measurements
dev.write( alshain.Pica.Parameters.PULSE_ENABLE, 1 ) # Start measurements
# Read latest result
dev.read( alshain.Pica.Parameters.RESULT ) # Measured signal in volts (floating point)
# Raw readings from pulsed measurements can be queried
dev.read( alshain.Pica.Parameters.V_LOW ) # Signal from lower pulse
dev.read( alshain.Pica.Parameters.V_HIGH ) # Signal from higher pulse
dev.read( alshain.Pica.Parameters.V_DIFF ) # Difference between higher and lower pulse (V_HIGH - V_LOW)
# Lowpass filter frequency, Pica readout has a digital 4th order lowpass filter (default: 0.5 Hz)
dev.write( alshain.Pica.Parameters.LOWPASS_FREQ, 3.0 ) # Set lowpass filter cutoff frequency to 3.0 Hz
# Set sensor head temperature, used for temperature compensation (default 21.0 C)
dev.write( alshain.Pica.Parameters.SENSOR_TEMPERATURE, 30.2 ) # Set sensor temperature to 30.2 C
# Set offset DAC voltage, used to compensate large static offsets from signal (default: 0.0V)
# Vmeasured = (Vsensor - Voffset) * range_gain
dev.write( alshain.Pica.Parameters.OFFSET_VOLTAGE, 0.85 ) # Set offset DAC to 0.85V, range: 0..2V
# Read status, error indicates that there is no viable signal measured from the sensor
dev.read( alshain.Pica.Parameters.STATUS ) # Status = 0 -> Ok, Status = 1 -> Error
# Set pulse amplitude and bias, Pica sends out two pulses when measuring, low and high pulse
# Higher pulse amplitude yields more signal at the risk of saturating the reflections are too high
# Higher pulse bias yields better rejection from electrical and environmental disturbances
# Amplitudes of these pulses are I_low = PULSE_BIAS and I_high = PULSE_BIAS + PULSE_AMPLITUDE
# PULSE_BIAS + PULSE_AMPLITUDE < 4095
# (defaults: PULSE_BIAS = 1024, PULSE_AMPLITUDE = 2048)
dev.write( alshain.Pica.Parameters.PULSE_BIAS, 1024 ) # Set pulse bias to 1024 -> I_low = 1024
dev.write( alshain.Pica.Parameters.PULSE_AMPLITUDE, 2048 ) # Set pulse amplitude to 2048
# Measurement range can be adjusted to better match measured signal values (default: ±1024 mV)
dev.write( alshain.Pica.Parameters.MEASUREMENT_RANGE, alshain.Pica.Options.RANGE_1024MV ) # Set range to ±1024 mV
dev.write( alshain.Pica.Parameters.MEASUREMENT_RANGE, alshain.Pica.Options.RANGE_512MV ) # Set range to ±512 mV
dev.write( alshain.Pica.Parameters.MEASUREMENT_RANGE, alshain.Pica.Options.RANGE_256MV ) # Set range to ±256 mV
# Pica uses staircase pulses, NRZ controls if drive voltage returns to zero after measurement pulse (default: 0)
dev.write( alshain.Pica.Parameters.PULSE_NRZ, 0 ) # Zero voltage after measurement pulse
dev.write( alshain.Pica.Parameters.PULSE_NRZ, 1 ) # Drive voltage stays at lower pulse height between measurements
# Pica readout has an analog output, output voltage (or current, depending on the model) can be mapped
# between ANALOG_OUT_MIN and ANALOG_OUT_MAX
# (defaults: ANALOG_OUT_MIN = 0, ANALOG_OUT_MAX = 1.0)
dev.write( alshain.Pica.Parameters.ANALOG_OUT_MIN, 0.0 ) # RESULT = 0 -> analog out -> minimum (ie. 0V or 4mA)
dev.write( alshain.Pica.Parameters.ANALOG_OUT_MAX, 0.75 ) # RESULT = 0.75 -> analog out = maximum (ie 3.3V or 20mA)
# Uptime counts milliseconds from power on
dev.read( alshain.Pica.Parameters.UPTIME )
# Current firmware version can be queries
dev.read( alshain.Pica.Parameters.FIRMWARE_VER )
# Read device serial number
dev.read( alshain.Pica.Parameters.SERIAL_NUMBER )
# Raw measurements (V_DIFF) can be calibrated to provide more meaningful values
# (such as OD600 etc) by applying a calibration polynomial to measured signal
# RESULT = COEFF_0 + V_DIFF * COEFF_1 + V_DIFF^2 * COEFF_2 + V_DIFF^3 * COEFF_3
# (default: linear 1:1 mapping from measurement to result)
dev.write( alshain.Pica.Parameters.CALIB_COEFF_0, 0.0 ) # 0th order coefficient (constant)
dev.write( alshain.Pica.Parameters.CALIB_COEFF_1, 1.0 ) # 1st order coefficient (linear)
dev.write( alshain.Pica.Parameters.CALIB_COEFF_2, 0.0 ) # 2nd order coefficient (quadratic)
dev.write( alshain.Pica.Parameters.CALIB_COEFF_3, 0.0 ) # 3rd order coefficient (cubic)