In / Out
ADS1115
- class crappy.inout.ads1115.Ads1115(backend: str, device_address: int = 72, i2c_port: int = 1, sample_rate: int = 128, v_range: float = 2.048, multiplexer: str = 'A1', dry_pin: Optional[Union[str, int]] = None, gain: float = 1, offset: float = 0, ft232h_ser_num: Optional[str] = None)[source]
A class for controlling Adafruit’s ADS1115 16-bits ADC.
The Ads1115 InOut block is meant for reading output values from a 16-bits ADS1115 ADC, using the I2C protocol. The output is in Volts by default, but a
gain
and anoffset
can be specified.- __init__(backend: str, device_address: int = 72, i2c_port: int = 1, sample_rate: int = 128, v_range: float = 2.048, multiplexer: str = 'A1', dry_pin: Optional[Union[str, int]] = None, gain: float = 1, offset: float = 0, ft232h_ser_num: Optional[str] = None) None [source]
Checks arguments validity.
- Parameters
backend (
str
) –The backend for communicating with the ADS1115. Should be one of:
'Pi4', 'ft232h', 'blinka'
The ‘Pi4’ backend is optimized but only works on boards supporting the
smbus2
module, like the Raspberry Pis. The ‘blinka’ backend may be less performant and requires installing Adafruit’s modules, but these modules are compatible with and maintained on a wide variety of boards. The ‘ft232h’ backend allows controlling the ADS1115 from a PC using Adafruit’s FT232H USB to I2C adapter. See Crappy for embedded hardware for details.device_address (
int
, optional) – The I2C address of the ADS1115. The default address is 0x48, but it is possible to change this setting using the ADDR pin.i2c_port (
int
, optional) – The I2C port over which the ADS1115 should communicate. On most Raspberry Pi models the default I2C port is 1.sample_rate (
int
, optional) –The sample rate for data conversion (in SPS). Available sample rates are:
8, 16, 32, 64, 128, 250, 475, 860
v_range (
float
, optional) –The value (in Volts) of the measured signal corresponding to the 0x7FFF output in bits, i.e. that saturates the sensor. A signal of
-v_range
Volts gives a 0x8000 output in bits. Availablev_range
values are:0.256, 0.512, 1.024, 2.048, 4.096, 6.144
multiplexer (
str
, optional) –Choice of the inputs to consider. Single-input modes actually measure Ax - GND. The available
multiplexer
values are:'A0', 'A1', 'A2', 'A3', 'A0 - A1', 'A0 - A3', 'A1 - A3', 'A2 - A3'
dry_pin (
int
orstr
, optional) – Optionally, reads the end of conversion signal from a GPIO rather than from an I2C message. Speeds up the reading and decreases the traffic on the bus, but requires one extra wire. With the backend ‘Pi4’, give the index of the GPIO in BCM convention. With the ‘ft232h’ backend, give the name of the GPIO in the format Dx or Cx. This feature is not available with the ‘blinka’ backend.gain (
float
, optional) –Allows to tune the output value according to the formula:
output = gain * tension + offset.
offset (
float
, optional) –Allows to tune the output value according to the formula:
output = gain * tension + offset.
ft232h_ser_num (
str
, optional) – If backend is ‘ft232h’, the serial number of the FT232H to use for communication.
Warning
AINx voltages should not be higher than VDD+0.3V nor lower than GND-0.3V. Setting high
v_range
values does not allow measuring voltages higher than VDD !!
Agilent 34420A
- class crappy.inout.agilent34420A.Agilent34420a(mode: bytes = b'VOLT', device: str = '/dev/ttyUSB0', baudrate: int = 9600, timeout: float = 1)[source]
Sensor class for Agilent34420A devices.
This class contains method to measure values of resistance or voltage on Agilent34420A devices.
Note
May work for other devices too, but not tested.
If you have issues with this class returning a lot of ‘bad serial’, make sure you have the last version of
serial
.
Comedi
- class crappy.inout.comedi.Comedi(**kwargs)[source]
Comedi object, for IO with cards using comedi driver.
Note
The channel-specific args can be given as a list to set it for each channel or as a single value to apply it to every channel.
- Parameters
(str (- device) – “/dev/comedi0”): The address of the device.
default – “/dev/comedi0”): The address of the device.
(int (- out_subdevice) – 0): The id of the subdevice.
default – 0): The id of the subdevice.
(list (- channels) – [0]): The list of the input channels.
default – [0]): The list of the input channels.
(list/int (- out_range_num) – 0): The range to use on each channel.
default – 0): The range to use on each channel.
(list/float (- out_offset) – 1): The return value for each chan will be multiplied by the gain.
default – 1): The return value for each chan will be multiplied by the gain.
(list/float – 0): The offset will be added to the return value for each chan.
default – 0): The offset will be added to the return value for each chan.
(list/bool (- make_zero) – True): If True, the value read at the beginning will be removed to the offset to take it as a reference.
default – True): If True, the value read at the beginning will be removed to the offset to take it as a reference.
(list – []): The list of the output channels.
default – []): The list of the output channels.
(list/int – 0): The range to use on each output.
default – 0): The range to use on each output.
(list/float – 1): The output value for each chan will be multiplied by the gain.
default – 1): The output value for each chan will be multiplied by the gain.
(list/float – 0): The offset will be added to the output value for each chan.
default – 0): The offset will be added to the output value for each chan.
(int – 1): The id of the output subdevice.
default – 1): The id of the output subdevice.
- get_data(channel: str = 'all') list [source]
To read the value on input_channels.
Note
If channel is specified, it will only read and return these channels.
‘all’ (default) will read all opened channels.
DaQMX
- class crappy.inout.daqmx.Daqmx(device: str = 'Dev1', channels: Optional[Union[list, str]] = None, gain: Union[list, float] = 1, offset: Union[list, float] = 0, range: Union[float, list] = 5, make_zero: Union[list, bool] = True, nperscan: int = 1000, sample_rate: float = 10000, out_channels: Optional[Union[list, str]] = None, out_gain: Union[list, float] = 1, out_offset: Union[list, float] = 0, out_range: Union[list, float] = 5)[source]
Class to use DAQmx devices.
- __init__(device: str = 'Dev1', channels: Optional[Union[list, str]] = None, gain: Union[list, float] = 1, offset: Union[list, float] = 0, range: Union[float, list] = 5, make_zero: Union[list, bool] = True, nperscan: int = 1000, sample_rate: float = 10000, out_channels: Optional[Union[list, str]] = None, out_gain: Union[list, float] = 1, out_offset: Union[list, float] = 0, out_range: Union[list, float] = 5) None [source]
Sets the args and initializes the parent class.
- Parameters
device (
str
, optional) – Name of the device to open.channels (
list
, optional) – Names or ids of the channels to read.gain (
list
, optional) – Gains to apply to each reading.offset (
list
, optional) – Offset to apply to each reading.range (
list
, optional) –Max value for the reading. Should be a
list
offloat
in:0.5, 1., 2.5, 5.
Refer to the niDAQ api for more details.
make_zero (
list
, optional) – IfTrue
, the average value on the channel at opening will be evaluated and subtracted to the actual reading.nperscan (
int
, optional) – If using streamer mode, number of readings to acquire on eachget_stream()
call.sample_rate (
float
, optional) – If using streamer mode, frequency of acquisition when callingget_stream()
.out_channels (
list
, optional) – Names or ids of the output channels.out_gain (
list
, optional) – Gains to apply to the commands.out_offset (
list
, optional) – Offset to apply to the commands.out_range (
list
, optional) –Max value of the output. Should be a
list
offloat
in:0.5, 1., 2.5, 5.
Refer to the niDAQ api for more details.
Note
If an argument supposed to be a
list
is given as a single value, this value will be applied to all channels.
- check_vars() None [source]
Turns the settings into
list
of the same length, each index standing for one channel.
- get_data() list [source]
Returns a
tuple
of lengthlen(self.channels) + 1
.First element is the time, others are readings of each channel.
- get_single(npoints: Optional[int] = None) list [source]
Reads the analog voltage on specified channels.
- set_cmd(*args: float) None [source]
Set the output(s) to the specified value.
Note
Takes n arguments, n being the number of channels opened at
__init__()
. The ith argument is the value to set to the ith channel.
Fake Inout
GPIO PWM
- class crappy.inout.gpio_pwm.Gpio_pwm(pin_out: int, duty_cycle: Optional[float] = None, frequency: Optional[float] = None)[source]
Class for performing PWM on a Raspberry Pi.
The Gpio_pwn InOut block is meant for controlling a PWM output from a Raspberry Pi GPIO. It allows to control the duty cycle, the frequency, or both at the same time. When controlling both, the duty cycle should be first and the frequency second in the list of inputs.
Warning
Only works on Raspberry Pi !
- __init__(pin_out: int, duty_cycle: Optional[float] = None, frequency: Optional[float] = None) None [source]
Checks the arguments validity.
- Parameters
pin_out (
int
) – The GPIO pin to be controlled (BCM convention).duty_cycle (
float
) – If provided, sets a fixed duty cycle for the entire assay. Only the frequency can then be tuned. If not provided, the block will expect the duty cycle values to be given as the first input. It will also start the PWM with a duty cycle of 0% before the first value is received and set.frequency (
float
) – If provided, sets a fixed PWM frequency for the entire assay. Only the duty cycle can then be tuned. If not provided, the block will expect the frequency values to be given as the first input if theduty_cycle
argument is provided, or else as the second input. It will also start the PWM with a frequency of 10kHz before the first value is received and set.
Note
duty_cycle
: The duty cycle inputs are clamped between 0 and 100.frequency
: The frequency inputs are clamped between 10Hz and 1MhZ. Sending other values to the bloc doesn’t raise any error, but the assay may not run as expected.Hardware PWM pins: On the Raspberry Pi 4, only the GPIO pins 12, 13, 18 and 19 support hardware PWM. Trying to get a PWM output from other pins might work but may decrease the available frequency range.
GPIO switch
- class crappy.inout.gpio_switch.Gpio_switch(pin_out: int)[source]
Class for setting a GPIO high or low.
The Gpio_switch InOut block is meant for switching a Raspberry Pi GPIO high or low according to the input signal value. When the input signal is 1 the GPIO is turned high, when the signal is 0 it is turned low. Any value other than 0 and 1 raises an error.
Warning
Only works on Raspberry Pi !
GSM
- class crappy.inout.gsm.Gsm(numbers: list, port: str = '/dev/ttyUSB0', baudrate: int = 115200)[source]
Block for sending messages by SMS to given phone numbers.
Important
This block should be associated with a modifier to manage the messages to send.
InOut
- class crappy.inout.inout.MetaIO(name: str, bases: tuple, dict_: dict)[source]
Metaclass that will define all IO objects.
All IO classes should be of this type.
To do so, simply add
__metaclass__ = MetaIO
in the class definition. (Obviously, you must import this Metaclass first.)MetaIO is a MetaClass: we will NEVER do
c = MetaIO(...)
.The
__init__()
is used to init the classes of type MetaIO (with__metaclass__ = MetaIO
as a class attribute) and NOT an instance of MetaClass.
Kollmorgen
- class crappy.inout.kollmorgen.Koll(data: str = 'position', axis: Union[str, int] = 'all', speed: float = 360, acc: float = 3600, decc: float = 3600, labels: Optional[list] = None, host: str = '192.168.0.109', port: int = 502)[source]
Class to communicate to Kollmorgen devices via Crappy.
- class crappy.inout.kollmorgen.KollMorgenVariator(host: str = '192.168.0.109', port: int = 502)[source]
Main class to test communication with kollmorgen variator.
Every variable and its address has been defined in the Kollmorgen Integrated Suite.
To add or remove some, update the dictionaries of
__init__()
.There are 3 motors, so the tens are for each motor, the units for the address.
- __init__(host: str = '192.168.0.109', port: int = 502) None [source]
Sets the variator and defines the bits.
- clear_errors() None [source]
If errors occurred, it must be clear in order to continue the program.
- set_accelerations(motor: int, **kwargs) None [source]
To set acceleration, deceleration (for positioning) and fast deceleration (boolean stop).
- set_position(motor: int, position: float) None [source]
To set a position (in degrees), absolute value.
- set_rotation(motor: int, rotation: float) None [source]
To set a rotation (in degrees) of the motor axis. Rotation is signed.
- set_speed(motor: int, speed: float) None [source]
Writes to variator desired speed (signed), and its direction. Applies to every motor movement (rotations, positioning…).
Labjack T7
- class crappy.inout.labjackT7.Labjack_t7(device: str = 'ANY', connection: str = 'ANY', identifier: str = 'ANY', channels: Optional[list] = None, write_at_open: Optional[list] = None, no_led: bool = False)[source]
Class for LabJack T7 devices.
It can use any channel as input/output, it can be used with an IOBlock.
This class is NOT capable of streaming. For higher frequency, see T7 Streamer class.
The keyword argument
channels
is used to specify the channels.Each channel must be represented as a
dict
including all the parameters. See below for more details on the parameters of the channels.- __init__(device: str = 'ANY', connection: str = 'ANY', identifier: str = 'ANY', channels: Optional[list] = None, write_at_open: Optional[list] = None, no_led: bool = False) None [source]
Sets the args and initializes the parent class.
- Parameters
device (
str
, optional) –The type of the device to open. Possible values include:
'ANY', 'T7', 'T4', 'DIGIT'
Only tested with ‘T7’ in Crappy.
connection (
str
, optional) –How is the Labjack connected ? Possible values include:
'ANY', 'TCP', 'USB', 'ETHERNET', 'WIFI'
identifier (
str
, optional) – Something to identify the Labjack. It can be a serial number, an IP address, or a device name.channels (
list
, optional) – Channels to use and their settings. It must be alist
ofdict
.write_at_open (
list
, optional) – If you need to write specific names or registers when opening the channel, you can give them as alist
oftuple
. They will be written in the order of the list.no_led (
list
, optional) – IfTrue
, turns off the LED on the Labjack. This led can cause noise on the channels AIN0 and AIN1.
Note
channels
keys:name (
str
): The name of the channel according to Labjack’s naming convention. Ex: ‘AIN0’. This will be used to define the direction (in/out) and the available settings.- It can be:
AINx: An analog input, if gain and/or offset is given, the integrated slope mechanism will be used with the extended features registers. It can also be used for thermocouples (see below). You can use any EF by using the
write_at_open
andto_read
keys if necessary.(T)DACx: An analog output, you can specify gain and/or offset.
(E/F/C/M IOx): Digital in/outputs. You can specify the direction.
gain (
float
, default: 1): A numeric value that will multiply the given value for inputs and outputs.offset (
float
, default: 0): Will be added to the value.For inputs:
returned_value = gain * measured_value + offset
For outputs:
set_value = gain * given_value + offset.
Where measured_value and set_values are in Volts.
make_zero (
bool
): AIN only, ifTrue
the input value will be evaluated at startup and the offset will be adjusted to return 0 (or the offset if any).direction (
bool
): DIO only, ifTrue
(or 1), the port will be used as an output else as an input.resolution (
int
, default: 1): The resolution of the acquisition, see Labjack documentation for more details. The bigger this value the better the resolution, but the lower the speed. The possible range is either 1 to 8 or to 12 according to the model.range (
float
, default: 10): The range of the acquisition in Volts. A range of x means that values can be read between -x and x Volts. The possible values are:0.01, 0.1, 1, 10
limits (
tuple
, default: None): To clamp the output values to a given range. Thetuple
should contain two values: the min and the max limit.thermocouple (
str
): The type of thermocouple (AIN only). Possible values are:'E', 'J', 'K', 'R', 'T', 'S', 'C'
If specified, it will use the EF to read a temperature directly from the thermocouples.
write_at_open (
list
): If you need to write specific names or registers when opening the channel, you can give them as alist
oftuple
. They will be written in the order of the list.The tuples can either be (name (str), value (int/float)) or (register (int), type (int), value (float/int)).
Warning
DO NOT CONSIDER the
limits
KEY AS A SAFETY IMPLEMENTATION. It should not go beyond/below the given values, but this is not meant to replace hardware safety!
- __setitem__(chan: str, val: float) None [source]
Allows setting of an output chan by calling
lj[chan] = val
.
- set_cmd(*cmd: float) None [source]
Converts the tension value to a digital value and send it to the output.
Note
Once a value has been written, it will not be written again until it changes! This is meant to lower the communication and Labjack activity.
It relies on the fact that these registers will not change between writes (Which is true unless the card runs a lua script writing the same registers as the user).
Labjack UE9
- class crappy.inout.labjackUE9.Labjack_ue9(channels: Union[int, list] = 0, gain: Union[float, list] = 1, offset: Union[float, list] = 0, make_zero: Union[bool, list] = True, resolution: Union[int, list] = 12)[source]
Can read data from a LabJack UE9.
Important
Streamer mode and DAC are not supported yet.
MCP9600
- class crappy.inout.mcp9600.Mcp9600(backend: str, thermocouple_type: str, i2c_port: int = 1, device_address: int = 103, adc_resolution: int = 18, sensor_resolution: float = 0.0625, filter_coefficient: int = 0, mode: str = 'Hot Junction Temperature', ft232h_ser_num: Optional[str] = None)[source]
Class for controlling Adafruit’s MCP9600 thermocouple reader.
The Mcp9600 InOut block is meant for reading temperature from an MCP9600 board, using the I2C protocol. The output is in °C, except for one operating mode that returns Volts.
- __init__(backend: str, thermocouple_type: str, i2c_port: int = 1, device_address: int = 103, adc_resolution: int = 18, sensor_resolution: float = 0.0625, filter_coefficient: int = 0, mode: str = 'Hot Junction Temperature', ft232h_ser_num: Optional[str] = None) None [source]
Checks arguments validity.
- Parameters
backend (
str
) –The backend for communicating with the MCP9600. Should be one of:
'Pi4', 'ft232h', 'blinka'
The ‘Pi4’ backend is optimized but only works on boards supporting the
smbus2
module, like the Raspberry Pis. The ‘blinka’ backend may be less performant and requires installing Adafruit’s modules, but these modules are compatible with and maintained on a wide variety of boards. The ‘ft232h’ backend allows controlling the ADS1115 from a PC using Adafruit’s FT232H USB to I2C adapter. See Crappy for embedded hardware for details.thermocouple_type (
str
) –The type of thermocouple plugged in the MCP9600. The available types are:
'J', 'K', 'T', 'N', 'S', 'E', 'B', 'R'
i2c_port (
int
, optional) – The I2C port over which the MCP9600 should communicate. On most Raspberry Pi models the default I2C port is 1.device_address (
int
, optional) – The I2C address of the MCP9600. The default address is 0x67, but it is possible to change this setting using a specific setup involving the ADDR pin.adc_resolution (
int
, optional) –The number of bits the ADC output is encoded on. The greater the resolution, the lower the sample rate. The available resolutions are:
12, 14, 16, 18
sensor_resolution (
float
, optional) – The temperature measurement resolution in °C. It should be either 0.0625 or 0.25. Setting the resolution to 0.25 will increase the sample rate, but the output temperature will be encoded on two bits less.filter_coefficient (
int
, optional) – The MCP9600 features an integrated filter (see its documentation for the exact filter formula). When set to 0, the filter is inactive. It is maximal when set to 7. When active, the filter will prohibit fast temperature changes, thus limiting noise and smoothening the signal.mode (
str
, optional) –Four different values can be accessed when measuring a temperature: the temperature of the thermocouple (hot junction temperature), the temperature of the MCP9600 board (cold junction temperature), the temperature calculated from the ADC data and thermocouple type but not yet cold junction-compensated (junction temperature delta), and the raw ADC measurement of the voltage difference in the thermocouple (raw data ADC, in Volts). The available modes are thus:
'Hot Junction Temperature', 'Junction Temperature Delta', 'Cold Junction Temperature', 'Raw Data ADC'
ft232h_ser_num (
str
, optional) – If backend is ‘ft232h’, the serial number of the ft232h to use for communication.
MPRLS
- class crappy.inout.mprls.Mprls(backend: str, eoc_pin: Optional[Union[str, int]] = None, device_address: int = 24, i2c_port: int = 1, ft232h_ser_num: Optional[str] = None)[source]
The Mprls inout is meant for reading pressure from Adafruit’s Mprls pressure sensor.
It communicates over I2C with the sensor.
- __init__(backend: str, eoc_pin: Optional[Union[str, int]] = None, device_address: int = 24, i2c_port: int = 1, ft232h_ser_num: Optional[str] = None) None [source]
Initializes the parent class and opens the I2C bus.
- Parameters
backend (
str
) –Should be one of :
'Pi4', 'blinka', 'ft232h'
The ‘Pi4’ backend is optimized but only works on boards supporting the
smbus2
module, like the Raspberry Pis. The ‘blinka’ backend may be less performant and requires installing Adafruit’s modules, but these modules are compatible with and maintained on a wide variety of boards. The ‘ft232h’ backend allows controlling the MPRLS from a PC using Adafruit’s FT232H USB to I2C adapter. See Crappy for embedded hardware for details.eoc_pin (
int
orstr
, optional) – Optionally, reads the end of conversion signal from a GPIO rather than from an I2C message. Speeds up the reading and decreases the traffic on the bus, but requires one extra wire. With the backend ‘Pi4’, give the index of the GPIO in BCM convention. With the ‘ft232h’ backend, give the name of the GPIO in the format Dx or Cx. With the backend ‘blinka’, it should be a string but the syntax varies according to the board. Refer to blinka’s documentation for more information.device_address (
int
, optional) – The I2C address of the MPRLS. The address of the devices sold by Adafruit is 0x18, but other suppliers may sell it with another address.i2c_port (
int
, optional) – The I2C port over which the MPRLS should communicate. On most Raspberry Pi models the default I2C port is 1.ft232h_ser_num (
str
, optional) – If backend is ‘ft232h’, the serial number of the FT232H to use for communication.
NAU7802
- class crappy.inout.nau7802.Nau7802(backend: str, i2c_port: int = 1, device_address: int = 42, gain_hardware: int = 128, sample_rate: int = 80, int_pin: Optional[Union[str, int]] = None, gain: float = 1, offset: float = 0, ft232h_ser_num: Optional[str] = None)[source]
Class for controlling Sparkfun’s NAU7802 load cell conditioner.
The Nau7802 InOut block is meant for reading output values from a NAU7802 load cell conditioner, using the I2C protocol. The output is in Volts by default, but can be converted to Newtons using
gain
andoffset
.- __init__(backend: str, i2c_port: int = 1, device_address: int = 42, gain_hardware: int = 128, sample_rate: int = 80, int_pin: Optional[Union[str, int]] = None, gain: float = 1, offset: float = 0, ft232h_ser_num: Optional[str] = None) None [source]
Checks the validity of the arguments..
- Parameters
backend (
str
) –The backend for communicating with the NAU7802. Should be one of:
'Pi4', 'ft232h'
to use the device from a Raspberry Pi or from a PC through an FT232H USB to I2C converter, respectively. See Crappy for embedded hardware for details.
i2c_port (
int
, optional) – The I2C port over which the NAU7802 should communicate. On most Raspberry Pi models the default I2C port is 1.device_address (
int
, optional) – The I2C address of the NAU7802. It is impossible to change this address, so it is not possible to have several NAU7802 on the same i2c bus.gain_hardware (
int
, optional) –The gain to be used by the programmable gain amplifier. Setting a high gain allows reading small voltages with a better precision, but it might saturate the sensor for higher voltages. Available gains are:
1, 2, 4, 8, 16, 32, 64, 128
sample_rate (
int
, optional) –The sample rate for data conversion. The higher the rate, the greater the noise. Available sample rates are:
10, 20, 40, 80, 320
int_pin (
int
orstr
, optional) – Optionally, reads the end of conversion signal from a GPIO rather than from an I2C message. Speeds up the reading and decreases the traffic on the bus, but requires one extra wire. With the backend ‘Pi4’, give the index of the GPIO in BCM convention. With the ‘ft232h’ backend, give the name of the GPIO in the format Dx or Cx.gain (
float
, optional) –Allows to tune the output value according to the formula:
output = gain * tension + offset.
offset (
float
, optional) –Allows to tune the output value according to the formula:
output = gain * tension + offset.
ft232h_ser_num (
str
, optional) – If backend is ‘ft232h’, the serial number of the ft232h to use for communication.
NI DaQMX
- class crappy.inout.ni_daqmx.Nidaqmx(channels: Optional[list] = None, samplerate: float = 100, nsamples: Optional[int] = None)[source]
Opens National Instrument devices using the NiDAQmx driver (Windows only).
This class can open ai, ao and dio channels on NI devices. It supports continuous streaming on ai channels only. Streaming is not supported with ai channels of different types.
It uses the
nidaqmx
python module by NI.- __init__(channels: Optional[list] = None, samplerate: float = 100, nsamples: Optional[int] = None) None [source]
Builds the different channels lists.
- Parameters
channels (
list
, optional) –A
list
ofdict
describing all the channels to open. See the note below for details.Note
For dio, use DevX/d[i/o] Y to select port(Y//8)/line(Y%8) on DevX.
samplerate (
float
, optional) – If using stream mode, the samplerate of the stream.nsamples (
int
, optional) – If using stream mode, the stream array will be returned after readingnsamples
samples. Defaults tosamplerate // 5
.
Note
Open DaQ
- class crappy.inout.open_daq.Opendaq(channels: Union[int, list] = 1, port: str = '/dev/ttyUSB0', gain: Union[float, int] = 1, offset: Union[float, list] = 0, cmd_label: str = 'cmd', out_gain: float = 1, out_offset: float = 0, make_zero: Union[bool, list] = True, mode: str = 'single', nsamples: int = 20)[source]
Can read data from an OpenDAQ card.
Opsens
PiJuice
- class crappy.inout.piJuice.Pijuice(i2c_port: int = 1, address: int = 20, backend: str = 'Pi4')[source]
Block getting various information about a piJuice power platform, including the charge level and the power supply status.
Warning
Only available on Raspberry Pi !
- __init__(i2c_port: int = 1, address: int = 20, backend: str = 'Pi4') None [source]
Checks arguments validity.
- Parameters
backend (
str
, optional) –Should be one of :
'Pi4', 'pijuice'
The ‘Pi4’ backend is based on the
smbus2
module, while the ‘pijuice’ backend is based on thepijuice
.i2c_port (
int
, optional) – The I2C port over which the PiJuice should communicate.address (
int
, optional) – The I2C address of the piJuice. The default address is 0x14.
- get_data() dict [source]
Reads all the available information on the battery status.
- Returns
dict
–Returns a dict containing:
the timeframe in seconds as a
float
in labelt(s)
the battery status as a
str
in labelbattery_status
the USB status as a
str
in labelUSB_status
the GPIO status as a
str
in labelGPIO_status
the charge level as an
int
in labelcharge_level
the battery temperature in °C as an
int
in labelbattery_temperature
the battery voltage in mV as an
int
in labelbattery_voltage
the battery current in mA as an
int
in labelbattery_current
the GPIO voltage in mV as an
int
in labelGPIO_voltage
the GPIO current in mA as an
int
in labelGPIO_current
Spectrum
- class crappy.inout.spectrum.Spectrum(device: bytes = b'/dev/spcm0', channels: Optional[list] = None, ranges: Optional[list] = None, samplerate: int = 100000, buff_size: int = 67108864, notify_size: int = 65536, split_chan: bool = False)[source]
Acquire data from a Spectrum device.
- __init__(device: bytes = b'/dev/spcm0', channels: Optional[list] = None, ranges: Optional[list] = None, samplerate: int = 100000, buff_size: int = 67108864, notify_size: int = 65536, split_chan: bool = False) None [source]
Sets the args and the instance attributes.
- Parameters
(str (device) – “/dev/spcm0”): The address of the device to use.
default – “/dev/spcm0”): The address of the device to use.
(list (ranges) – [0]): The channels to open. See doc for the allowed combinations!
default – [0]): The channels to open. See doc for the allowed combinations!
(list – [10000]): The ranges of the channels in mV.
default – [10000]): The ranges of the channels in mV.
(int (notify_size) – 100000): The samplerate for all channels in Hz.
default – 100000): The samplerate for all channels in Hz.
(int – 2**16 (64MB)): The size of the memory allocated as a rolling buffer to copy the data from the card
default – 2**16 (64MB)): The size of the memory allocated as a rolling buffer to copy the data from the card
(int – 2**16 (64kB)): The size of the chunks of data to copy from the card.
default – 2**16 (64kB)): The size of the chunks of data to copy from the card.
split_chan – split_chan (bool, default: False): If False, it will return a single 2D array, else each chan will be a 1D array.
T7 Streamer
- class crappy.inout.t7Streamer.T7_streamer(device: str = 'ANY', connection: str = 'ANY', identifier: str = 'ANY', channels: Optional[list] = None, scan_rate: int = 100000, scan_per_read: int = 10000, resolution: int = 1)[source]
Class to use stream mode with Labjack T7 devices.
Note
For single modes, see Labjack T7.
You can use IOBlock with
streamer=True
to read data at high frequency from the Labjack. Streamer mode makes the Labjack unavailable for any other operation (single acquisition, DAC or DIO).You can specify each channel as a
dict
, allowing to set channel-specific settings such as gain, offset (computed on the host machine as this feature is not available on board with streamer mode), range and ability to zero the reading at startup.- __init__(device: str = 'ANY', connection: str = 'ANY', identifier: str = 'ANY', channels: Optional[list] = None, scan_rate: int = 100000, scan_per_read: int = 10000, resolution: int = 1) None [source]
Sets the args and initializes the parent class.
- Parameters
device (
str
, optional) –The type of the device to open. Possible values include:
'ANY', 'T7', 'T4', 'DIGIT'
Only tested with ‘T7’ in Crappy.
connection (
str
, optional) –How is the Labjack connected ? Possible values include:
'ANY', 'TCP', 'USB', 'ETHERNET', 'WIFI'
identifier (
str
, optional) – Something to identify the Labjack. It can be a serial number, an IP address, or a device name.channels (
list
, optional) – Channels to use and their settings. It must be alist
ofdict
.scan_rate (
int
, optional) – The acquisition frequency in Hz for the channels. Note that the sample rate (scan_rate * num of chan) cannot exceed 100000. If it is too high it will be lowered to the highest possible value.scan_per_read (
int
, optional) – The number of points to read during each loop.resolution (
int
, optional) – The resolution index for all channels. The bigger this value the better the resolution, but the lower the speed. The possible range is either 1 to 8 or to 12 according to the model.
Note
channels
keys:name (
str
): The name of the channel according to Labjack’s naming convention. Ex: ‘AIN0’. This will be used to define the direction (in/out) and the available settings.- It can be:
AINx: An analog input, if gain and/or offset is given, the integrated slope mechanism will be used with the extended features registers. It can also be used for thermocouples (see below). You can use any EF by using the
write_at_open
andto_read
keys if necessary.(T)DACx: An analog output, you can specify gain and/or offset.
(E/F/C/M IOx): Digital in/outputs. You can specify the direction.
gain (
float
, default: 1): A numeric value that will multiply the given value for inputs and outputs.offset (
float
, default: 0): Will be added to the value.For inputs:
returned_value = gain * measured_value + offset
For outputs:
set_value = gain * given_value + offset.
Where measured_value and set_values are in Volts.
make_zero (
bool
): AIN only, ifTrue
the input value will be evaluated at startup and the offset will be adjusted to return 0 (or the offset if any).range (
float
, default: 10): The range of the acquisition in Volts. A range of x means that values can be read between -x and x Volts. The possible values are:0.01, 0.1, 1, 10