Exemplo n.º 1
0
    def __init__(self, bus_n, bus_addr=0x18, output='csv'):

        # i2c bus
        self.bus = I2C(bus_n=bus_n, bus_addr=bus_addr)

        self.state_mapper = {0: "closed", 1: "open"}

        # information about this device
        self.device = DeviceData("Qwiic Relay")
        self.device.description = ("Sparkfun Single Pole Double Throw Relay")
        self.device.urls = "https://learn.sparkfun.com/tutorials/qwiic-single-relay-hookup-guide/all"
        self.device.active = None
        self.device.error = None
        self.device.bus = repr(self.bus)
        self.device.manufacturer = "Sparkfun"
        self.device.version_hw = "1"
        self.device.version_sw = "1"

        self.application = "test"

        del self.device.accuracy
        del self.device.precision
        del self.device.dtype

        # data recording method

        self.writer_output = output
        self.csv_writer = CSVWriter("Qwiic Relay", time_format='std_time_ms')
        self.csv_writer.device = self.device.__dict__
        self.csv_writer.header = ["sample_id", "state"]

        self.json_writer = JSONWriter("Qwiic Relay", time_format='std_time_ms')
        self.json_writer.device = self.device.__dict__
        self.json_writer.header = ["sample_id", "state"]
Exemplo n.º 2
0
    def __init__(self, bus_n, bus_addr=0x18, output='csv', name='Qwiic_1xRelay'):

        # i2c bus
        self.bus = I2C(bus_n=bus_n, bus_addr=bus_addr)

        self.state_mapper = {0: "closed", 1: "open"}
        
        # information about this device
        self.metadata = Meta(name=name)
        self.metadata.description = 'Sparkfun Single Pole Double Throw Relay'
        self.metadata.urls = 'https://learn.sparkfun.com/tutorials/qwiic-single-relay-hookup-guide/all'
        self.metadata.manufacturer = 'Sparkfun'
        
        self.metadata.header    = ["description", "state"]
        self.metadata.dtype     = ['str', 'str']
        self.metadata.units     = None
        self.metadata.accuracy  = None 
        self.metadata.precision = None
        
        self.metadata.bus_n = bus_n
        self.metadata.bus_addr = hex(bus_addr)

        # data recording method
        self.writer_output = output
        self.csv_writer = CSVWriter(metadata=self.metadata, time_format='std_time_ms')
        self.json_writer = JSONWriter(metadata=self.metadata, time_format='std_time_ms')
Exemplo n.º 3
0
    def __init__(self, bus_n, bus_addr=0x0F, output='csv'):

        # i2c bus
        self.bus = I2C(bus_n=bus_n, bus_addr=bus_addr)

        # PWM clock frequency
        self.frequency = 31372

        # speed can be -255 to 255
        self.motor_1_speed = 0
        self.motor_2_speed = 0

        # direction of DC motor
        self.direction = ""

        # driver mode, 'dc' or 'step'
        self.mode = "dc"

        # phase of the motor being used, only applies in stepper mode
        self.phase = None

        # step code initialize
        self.step_codes_cw = None
        self.step_codes_ccw = None

        # motor phase steps, default to 2 phase
        self.set_phase(phase=2)

        # number of steps commanded
        self.steps = 0

        # running total steps, for positioning microsteps
        self.step_count = 0

        # information about this device
        self.device = DeviceData('Grove Motor Driver')
        self.device.description = ('I2C DC and stepper motor controller')
        self.device.urls = 'http://wiki.seeedstudio.com/Grove-I2C_Motor_Driver_V1.3/'
        self.device.active = None
        self.device.error = None
        self.device.bus = repr(self.bus)
        self.device.manufacturer = 'Seeed Studio'
        self.device.version_hw = '1.3'
        self.device.version_sw = '1.0'
        self.device.accuracy = None
        self.device.precision = '1 microstep'
        self.device.calibration_date = None

        # data recording method
        self.writer_output = output
        self.csv_writer = CSVWriter(self.device.name, time_format='std_time_ms')
        self.csv_writer.device = self.device.values()
        self.csv_writer.header = ['description', 'freq',
                                  'm1_speed', 'm2_speed', 'm_direction',
                                  'mode', 'phase', 'steps']

        self.json_writer = JSONWriter(self.device.name, time_format='std_time_ms')
        self.json_writer.device = self.device.values()
        self.json_writer.header = self.csv_writer.header
Exemplo n.º 4
0
    def __init__(self, output='json'):

        # TODO: make safe for MicroPython, leave here for now in Conda
        from collections import deque
        from math import sin, pi

        from meerkat.data import CSVWriter, JSONWriter

        # data bus placeholder
        self.bus = None
        self.bus_addr = None

        # what kind of data output to file
        self.output = output

        # types of verbose printing
        self.verbose = False
        self.verbose_data = False

        # thread safe deque for sharing and plotting
        self.q_maxlen = 300
        self.q = deque(maxlen=self.q_maxlen)
        self.q_prefill_zeros = False

        # realtime/stream options
        self.go = False
        self.unlimited = False
        self.max_samples = 1000

        # information about this device
        self.device = DeviceData('Software Test')
        self.device.description = 'Dummy data for software testing'
        self.device.urls = None
        self.device.manufacturer = None
        self.device.version_hw = None
        self.device.version_sw = None
        self.device.accuracy = None
        self.device.precision = None
        self.device.bus = None
        self.device.state = 'Test Not Running'
        self.device.active = False
        self.device.error = None
        self.device.dtype = None
        self.device.calibration_date = None

        # data writer
        if self.output == 'csv':
            self.writer = CSVWriter('Software Test')
            #self.writer.device = self.device.values()
        elif self.output == 'json':
            self.writer = JSONWriter('Software Test')

        self.writer.header = ['index', 'degrees', 'amplitude']
        self.writer.device = self.device.values()

        # example data of one 360 degree, -1 to 1 sine wave
        self._deg = [n for n in range(360)]
        self._amp = [sin(d * (pi / 180.0)) for d in self._deg]
        self._test_data = list(zip(self._deg, self._amp))
Exemplo n.º 5
0
    def __init__(self, bus_n, bus_addr, output='csv'):
        """Initialize worker device on i2c bus.

        Parameters
        ----------
        bus_n : int, i2c bus number on Controller
        bus_addr : int, i2c bus number of this Worker device
        """

        # i2c bus
        self.bus = I2C(bus_n=bus_n, bus_addr=bus_addr)


        # time to wait for conversions to finish
        self.short_delay   = 0.3  # seconds for regular commands
        self.long_delay    = 1.5  # seconds for readings
        self.cal_delay     = 3.0  # seconds for calibrations

        # information about this device
        self.device = DeviceData('Atlas_Base')
        self.device.description = ('')
        self.device.urls = 'www.atlas-scientific.com'
        self.device.active = None
        self.device.error = None
        self.device.bus = repr(self.bus)
        self.device.manufacturer = 'Atlas Scientific'
        self.device.version_hw = '1.0'
        self.device.version_sw = '1.0'
        self.device.accuracy = None
        self.device.precision = 'Varies'
        self.device.calibration_date = None

        """
        # data recording method
        if output == 'csv':
            self.writer = CSVWriter('Atlas_Base', time_format='std_time_ms')

        elif output == 'json':
            self.writer = JSONWriter('Atlas_Base', time_format='std_time_ms')
        else:
            pass  # holder for another writer or change in default
        self.writer.header = ['description', 'sample_n', 'not_set']
        self.writer.device = self.device.values()
        """

        # data recording information
        self.sample_id = None

        # data recording method
        self.writer_output = output
        self.csv_writer = CSVWriter("Atlas_Base", time_format='std_time_ms')
        self.csv_writer.device = self.device.__dict__
        self.csv_writer.header = ['description', 'sample_n', 'not_set']

        self.json_writer = JSONWriter("Atlas_Base", time_format='std_time_ms')
        self.json_writer.device = self.device.__dict__
        self.json_writer.header = self.csv_writer.header
Exemplo n.º 6
0
    def __init__(self, bus_n, bus_addr=0x0F, output='csv', name='Grove Motor Driver'):

        # i2c bus
        self.bus = I2C(bus_n=bus_n, bus_addr=bus_addr)

        # PWM clock frequency
        self.frequency = 31372

        # speed can be -255 to 255
        self.motor_1_speed = 0
        self.motor_2_speed = 0

        # direction of DC motor
        self.direction = ""

        # driver mode, 'dc' or 'step'
        self.mode = "dc"

        # phase of the motor being used, only applies in stepper mode
        self.phase = None

        # step code initialize
        self.step_codes_cw = None
        self.step_codes_ccw = None

        # motor phase steps, default to 2 phase
        self.set_phase(phase=2)

        # number of steps commanded
        self.steps = 0

        # running total steps, for positioning microsteps
        self.step_count = 0

        # information about this device
        self.metadata = Meta(name=name)
        self.metadata.description = ('I2C DC and stepper motor controller')
        self.metadata.urls = 'http://wiki.seeedstudio.com/Grove-I2C_Motor_Driver_V1.3/'
        self.metadata.manufacturer = 'Seeed Studio'
        
        self.metadata.header    = ['description', 'freq',
                                   'm1_speed', 'm2_speed', 'm_direction',
                                   'mode', 'phase', 'steps']
        self.metadata.dtype     = ['str', 'int', 'int', 'int', 'str', 'str', 'int', 'int']
        self.metadata.accuracy  = None
        self.metadata.precision = None
        
        self.metadata.bus_n = bus_n
        self.metadata.bus_addr = hex(bus_addr)
        
        self.writer_output = output
        self.csv_writer = CSVWriter(metadata=self.metadata, time_format='std_time_ms')
        self.json_writer = JSONWriter(metadata=self.metadata, time_format='std_time_ms')
Exemplo n.º 7
0
    def __init__(self, bus_n, bus_addr=0x68, output='csv'):

        # i2c bus
        self.bus = I2C(bus_n=bus_n, bus_addr=bus_addr)

        # Wake up the MPU-6050 since it starts in sleep mode
        # by toggling bit6 from 1 to 0, see pg 40 of RM-MPU-6000A-00 v4.2
        self.bus.write_register_8bit(self.PWR_MGMT_1, 0x00)

        # information about this device
        self.device = DeviceData('MPU-6050')
        self.device.description = ('TDK InvenSense Gyro & Accelerometer')
        self.device.urls = 'https://www.invensense.com/products/motion-tracking/6-axis/mpu-6050/'
        self.device.active = None
        self.device.error = None
        self.device.bus = repr(self.bus)
        self.device.manufacturer = 'TDK'
        self.device.version_hw = '0.1'
        self.device.version_sw = '0.1'
        self.device.gyro_accuracy = '+/-3%, +/-2% cross axis'
        self.device.gyro_precision = '16bit'
        self.device.gyro_noise = '0.05 deg/s-rms'
        self.device.accel_accuracy = '+/-0.5%, +/-2 cross axis'
        self.device.accel_precision = '16bit'
        self.device.accel_noise = 'PSD 400 ug / Hz**1/2'
        self.device.calibration_date = None
        '''
        # data recording method
        if output == 'csv':
            self.writer = CSVWriter('MPU-6050', time_format='std_time_ms')
            self.writer.header = ['description', 'sample_n', 'arange', 'grange',
                                  'ax', 'ay', 'az', 'gx', 'gy', 'gz', 'temp_C']
        elif output == 'json':
            self.writer = JSONWriter('MPU-6050', time_format='std_time_ms')
        else:
            pass  # holder for another writer or change in default
        self.writer.device = self.device.values()
        '''

        # data recording information
        self.sample_id = None

        # data recording method
        self.writer_output = output
        self.csv_writer = CSVWriter("MPU-6050", time_format='std_time_ms')
        self.csv_writer.device = self.device.__dict__
        self.csv_writer.header = [
            'description', 'sample_n', 'ax', 'ay', 'az', 'gx', 'gy', 'gz'
        ]

        self.json_writer = JSONWriter("MCP9808", time_format='std_time_ms')
        self.json_writer.device = self.device.__dict__
        self.json_writer.header = self.csv_writer.header
Exemplo n.º 8
0
    def __init__(self, bus_n, bus_addr=0x62, output='csv', sensor_id='SCD4x'):
        """Initialize worker device on i2c bus.

        Parameters
        ----------
        bus_n : int, i2c bus number on Controller
        bus_addr : int, i2c bus number of this Worker device
        output : str, writer output format, either 'csv' or 'json'
        sensor_id : str, sensor id, 'BME680' by default
        """

        # i2c bus
        self.bus = I2C(bus_n=bus_n, bus_addr=bus_addr)

        # information about this device
        self.metadata = Meta(name='SCD4x')
        self.metadata.description = 'SCD4x CO2 gas Sensor'
        self.metadata.urls = 'https://www.sensirion.com/en/environmental-sensors/carbon-dioxide-sensors/carbon-dioxide-sensor-scd4x/'
        self.metadata.manufacturer = 'Sensirion'

        self.metadata.header = [
            'system_id', 'sensor_id', 'description', 'sample_n', 'co2', 'tC',
            'rh'
        ]
        self.metadata.dtype = [
            'str', 'str', 'str', 'int', 'int', 'float', 'int'
        ]
        self.metadata.units = [
            'NA', 'NA', 'NA', 'count', 'ppm', 'degrees Celsius', 'percent'
        ]
        self.metadata.accuracy = [
            'NA', 'NA', 'NA', '1', '+/- 40 + 5%', '+/- 1.5', '+/- 0.4'
        ]
        self.metadata.precision = [
            'NA', 'NA', 'NA', 'NA', '+/- 10', '+/- 0.1', '+/- 0.4'
        ]
        self.metadata.range = [
            'NA', 'NA', 'NA', 'NA', '0-40000', '-10-60', '0-100'
        ]

        self.metadata.bus_n = bus_n
        self.metadata.bus_addr = hex(bus_addr)

        # data recording information
        self.system_id = None
        self.sensor_id = sensor_id
        self.dt = None

        self.writer_output = output
        self.csv_writer = CSVWriter(metadata=self.metadata,
                                    time_format='std_time_ms')
        self.json_writer = JSONWriter(metadata=self.metadata,
                                      time_format='std_time_ms')
Exemplo n.º 9
0
    def __init__(self, bus_n, bus_addr=0x18, output='csv', name='mcp9808'):
        """Initialize worker device on i2c bus.

        Parameters
        ----------
        bus_n : int, i2c bus number on Controller
        bus_addr : int, i2c bus number of this Worker device
        """

        # i2c bus
        self.bus = I2C(bus_n=bus_n, bus_addr=bus_addr)

        # register values and defaults
        # TODO: do the constant values need to be specified?
        self.reg_map = {
            'config': REG_CONFIG,
            'upper_temp': REG_UPPER_TEMP,
            'lower_temp': REG_LOWER_TEMP,
            'crit_temp': REG_CRIT_TEMP,
            'ambient': REG_AMBIENT_TEMP,
            'manufacturer': REG_MANUF_ID,
            'device_id': REG_DEVICE_ID
        }

        self.alert_critial = None
        self.alert_upper = None
        self.alert_lower = None

        self.manufacturer_id = None
        self.device_id = None
        self.revision = None

        # information about this device
        self.metadata = Meta(name=name)
        self.metadata.description = 'Microchip Tech digital temperature sensor'
        self.metadata.urls = 'https://www.microchip.com/datasheet/MCP9808'
        self.metadata.manufacturer = 'Adafruit Industries & Microchip Tech'

        self.metadata.header = ['description', 'sample_n', 'temp_C']
        self.metadata.dtype = ['str', 'int', 'float']
        self.metadata.units = [None, 'count', 'degrees Celcius']
        self.metadata.accuracy = [None, 1, '+/- 0.25 typical']
        self.metadata.precision = [None, 1, '0.0625 max']

        self.metadata.bus_n = bus_n
        self.metadata.bus_addr = hex(bus_addr)

        # data recording method
        self.writer_output = output
        self.csv_writer = CSVWriter(metadata=self.metadata,
                                    time_format='std_time_ms')
        self.json_writer = JSONWriter(metadata=self.metadata,
                                      time_format='std_time_ms')
Exemplo n.º 10
0
    def __init__(self, bus_n, bus_addr=0x00, output='csv'):
        """Initialize worker device on i2c bus.

        Parameters
        ----------
        bus_n : int, i2c bus number on Controller
        bus_addr : int, i2c bus number of this Worker device
        """

        # i2c bus
        self.bus = base.I2C(bus_n=bus_n, bus_addr=bus_addr)

        # print debug statements
        self.verbose = False

        # information about this device
        self.device = base.DeviceData('ExampleDevice')
        self.device.description = ('Just an example, replace')
        self.device.urls = 'www.example.com'
        self.device.active = None
        self.device.error = None
        self.device.bus = repr(self.bus)
        self.device.manufacturer = 'None'
        self.device.version_hw = '1.0'
        self.device.version_sw = '1.0'
        self.device.accuracy = None
        self.device.precision = 'replace'
        self.device.calibration_date = None

        # add device specific attributes
        self.device.other_attributes = None

        # data recording method
        if output == 'csv':
            self.writer = CSVWriter('ExampleDevice', time_format='std_time_ms')
        elif output == 'json':
            self.writer = JSONWriter('ExampleDevice',
                                     time_format='std_time_ms')
        else:
            pass  # holder for another writer or change in default
        # set writer header for device's output format, ADS1115 shown example
        self.writer.header = ['description', 'sample_n', 'voltage', 'current']
        self.writer.device = self.device.values()

        # data recording information
        self.sample_id = None

        # intialized configuration values
        self.get_config()
Exemplo n.º 11
0
    def __init__(self, bus_n, bus_addr=0x68, output='csv', name='MPU6050'):

        # i2c bus
        self.bus = I2C(bus_n=bus_n, bus_addr=bus_addr)

        # Wake up the MPU-6050 since it starts in sleep mode
        # by toggling bit6 from 1 to 0, see pg 40 of RM-MPU-6000A-00 v4.2
        self.bus.write_register_8bit(self.PWR_MGMT_1, 0x00)

        # information about this device
        self.metadata = Meta(name=name)
        self.metadata.description = 'TDK InvenSense Gyro & Accelerometer'
        self.metadata.urls = 'https://www.invensense.com/products/motion-tracking/6-axis/mpu-6050/'
        self.metadata.manufacturer = 'Adafruit Industries & TDK'

        # note: accuracy in datasheet is relative to scale factor - LSB/(deg/s) +/-3%
        # is there a better way to describe this? +/-3% below implies relative to deg/s output...
        self.metadata.header = [
            'description', 'sample_n', 'ax', 'ay', 'az', 'gx', 'gy', 'gz'
        ]
        self.metadata.dtype = [
            'str', 'int', 'float', 'float', 'float', 'float', 'float', 'float'
        ]
        self.metadata.units = [
            None, 'count', 'g', 'g', 'g', 'deg/s', 'deg/s', 'deg/s'
        ]
        self.metadata.accuracy = [
            None, 1, '+/-3%', '+/-3%', '+/-3%', '+/-3%', '+/-3%', '+/-3%'
        ]
        self.metadata.accuracy_precision_note = 'See datasheet for scale factor dependent accuracy & LSB precision'
        self.metadata.precision = None

        # specific specifications
        self.metadata.gyro_accuracy = '+/-3%, +/-2% cross axis'
        self.metadata.gyro_precision = '16bit'
        self.metadata.gyro_noise = '0.05 deg/s-rms'
        self.metadata.accel_accuracy = '+/-0.5%, +/-2 cross axis'
        self.metadata.accel_precision = '16bit'
        self.metadata.accel_noise = 'PSD 400 ug / Hz**1/2'

        self.metadata.bus_n = bus_n
        self.metadata.bus_addr = hex(bus_addr)

        # data recording classes
        self.writer_output = output
        self.csv_writer = CSVWriter(metadata=self.metadata,
                                    time_format='std_time_ms')
        self.json_writer = JSONWriter(metadata=self.metadata,
                                      time_format='std_time_ms')
Exemplo n.º 12
0
    def __init__(self,
                 bus_n,
                 bus_addr=0x69,
                 output_format='float',
                 output='csv',
                 sensor_id='SPS30'):
        """Initialize worker device on i2c bus.

        Parameters
        ----------
        bus_n : int, i2c bus number on Controller
        bus_addr : int, i2c bus number of this Worker device
        output_format : str, what format measurements will be returned in
            either 'float' or 'int'
        output : str, writer output format, either 'csv' or 'json'
        sensor_id : str, sensor id, 'BME680' by default
        """

        self.output_format = None

        # i2c bus
        self.bus = I2C(bus_n=bus_n, bus_addr=bus_addr)

        # information about this device
        self.metadata = Meta(name='SPS30')
        self.metadata.description = 'SPS30 Particulate Matter Sensor'
        self.metadata.urls = 'https://www.sensirion.com/en/environmental-sensors/particulate-matter-sensors-pm25'
        self.metadata.manufacturer = 'Sensirion'
        self.metadata.bus_n = bus_n
        self.metadata.bus_addr = hex(bus_addr)
        self.metadata.speed_warning = 0
        self.metadata.laser_error = 0
        self.metadata.fan_error = 0

        self.set_format(output_format)

        # data recording information
        self.system_id = None
        self.sensor_id = sensor_id
        self.blocking_settle_dt = 15  # seconds
        self.blocking_timeout = 30  # seconds

        self.writer_output = output
        self.csv_writer = CSVWriter(metadata=self.metadata,
                                    time_format='std_time_ms')
        self.json_writer = JSONWriter(metadata=self.metadata,
                                      time_format='std_time_ms')
Exemplo n.º 13
0
    def __init__(self, bus_n, bus_addr=0x10, output='csv', name='pa1010d'):
        """PA1010D GPS module using MTK3333 chipset
        
        Supported NMEA sentences: 'GGA', 'GSA', 'GSV', 'RMC', 'VTG'
        
        Parameters
        ----------
        bus_n : int, i2c bus number on Controller
        bus_addr : int, i2c bus number of this Worker device
        nmea_sentence : str, NMEA sentence type to save for CSV.
            JSON will save
        """

        # i2c bus
        self.bus = I2C(bus_n=bus_n, bus_addr=bus_addr)

        # maximum data in buffer size
        self._bytes_per_burst = 255
        
        # standard metadata information about this device
        self.metadata = Meta(name=name)
        
        self.metadata.description      = 'Adafruit PA1010D GPS/GNSS module'
        self.metadata.urls             = 'https://www.cdtop-tech.com/products/pa1010d'
        self.metadata.manufacturer     = 'CDTop Technology'
        self.metadata.state            = None
        
        self.metadata.header    = ['description', 'sample_n', 'nmea_sentence']
        self.metadata.dtype     = ['str', 'int', 'str']
        self.metadata.units     = None
        self.metadata.accuracy  = None
        self.metadata.precision = '<3.0 meters'
        
        self.metadata.bus_n            = bus_n
        self.metadata.bus_addr         = hex(bus_addr)
        
        # custom metadata attributes
        self.metadata.supported_nmea_sentences = ['GGA', 'GSA', 'GSV', 'RMC', 'VTG']
        
        # data recording method
        self.writer_output = output
        self.csv_writer = CSVWriter(metadata=self.metadata,
                                    time_format='std_time_ms')
        self.json_writer = JSONWriter(metadata=self.metadata,
                                      time_format='std_time_ms')
Exemplo n.º 14
0
    def __init__(self, bus_n, bus_addr=0x68, output='csv', name='DS3231'):
        """Initialize worker device on i2c bus.

        Parameters
        ----------
        bus_n : int, i2c bus number on Controller
        bus_addr : int, i2c bus number of this Worker device
        output : str, output data format, either 'csv' (default) or 'json'
        """

        # i2c bus
        self.bus = I2C(bus_n=bus_n, bus_addr=bus_addr)

        # information about this device
        self.metadata = Meta(name=name)
        self.metadata.description = 'Adafruit DS3221 Precision RTC'
        self.metadata.urls = 'https://datasheets.maximintegrated.com/en/ds/DS3231.pdf'
        self.metadata.manufacturer = 'Adafruit Industries'

        self.metadata.header = [
            "description", "sample_n", "rtc_time", "temp_C"
        ]
        self.metadata.dtype = ['str', 'int', 'str', 'float']
        self.metadata.units = [None, 'count', 'datetime', 'degrees Celcius']
        self.metadata.accuracy = [None, 1, '+/- 3.5 ppm', '+/- 3.0']
        self.metadata.precision = [None, 1, '1 second', 0.25]

        self.metadata.bus_n = bus_n
        self.metadata.bus_addr = hex(bus_addr)

        # python strftime specification for RTC output precision
        self.metadata.rtc_time_format = '%Y-%m-%d %H:%M:%S'

        # data recording method
        # note: using millisecond accuracy on driver timestamp, even though
        # RTC is only 1 second resolution
        self.writer_output = output
        self.csv_writer = CSVWriter(metadata=self.metadata,
                                    time_format='std_time_ms')
        self.json_writer = JSONWriter(metadata=self.metadata,
                                      time_format='std_time_ms')
Exemplo n.º 15
0
    def __init__(self, bus_n, bus_addr, output='csv', name='atlas_base'):
        """Initialize worker device on i2c bus.

        Parameters
        ----------
        bus_n : int, i2c bus number on Controller
        bus_addr : int, i2c bus number of this Worker device
        """

        # i2c bus
        self.bus = I2C(bus_n=bus_n, bus_addr=bus_addr)


        # time to wait for conversions to finish
        self.short_delay   = 0.3  # seconds for regular commands
        self.long_delay    = 1.5  # seconds for readings
        self.cal_delay     = 3.0  # seconds for calibrations

        # data recording information
        self.sample_id = None
        
        # information about this device
        self.metadata = Meta(name=name)
        self.metadata.description = 'Base class for Atlas Scientific Devices'
        self.metadata.urls = 'www.atlas-scientific.com'
        self.metadata.manufacturer = 'Atlas Scientific'
        
        self.metadata.header    = None
        self.metadata.dtype     = None
        self.metadata.units     = None
        self.metadata.accuracy  = None 
        self.metadata.precision = None
        
        self.metadata.bus_n = bus_n
        self.metadata.bus_addr = hex(bus_addr)

        # data recording method
        self.writer_output = output
        self.csv_writer = CSVWriter(metadata=self.metadata, time_format='std_time_ms')
        self.json_writer = JSONWriter(metadata=self.metadata, time_format='std_time_ms')
Exemplo n.º 16
0
    def __init__(self, bus_n, bus_addr=0x20, output='csv'):
        """Initialize worker device on i2c bus.

        Parameters
        ----------
        bus_n : int, i2c bus number on Controller
        bus_addr : int, i2c bus number of this Worker device
        output : str, output data format, either 'csv' (default) or 'json'
        """

        # i2c bus
        self.bus = I2C(bus_n=bus_n, bus_addr=bus_addr)

        # set direction of I/O to output for all pins
        self.bus.write_register_8bit(reg_addr=0x00, data=0)

        self.reg_olat = None

        # information about this device
        self.metadata = Meta('MCP23008')
        self.metadata.description = '8 channel I2C relay board by Peter Jakab'
        self.metadata.urls = 'https://jap.hu/electronic/relay_module_i2c.html'
        self.metadata.manufacturer = 'Peter Jakab'

        self.metadata.header = ['description', 'sample_n', 'relay_state']
        self.metadata.dtype = ['str', 'int', 'str']
        self.metadata.accuracy = None
        self.metadata.precision = None

        self.metadata.bus_n = bus_n
        self.metadata.bus_addr = hex(bus_addr)

        self.writer_output = output
        self.csv_writer = CSVWriter(metadata=self.metadata,
                                    time_format='std_time_ms')
        self.json_writer = JSONWriter(metadata=self.metadata,
                                      time_format='std_time_ms')
Exemplo n.º 17
0
    def __init__(self, bus_n, bus_addr=0x00, output='json', name='software_test'):

        # data bus placeholder
        self.bus = 'fake I2C bus object on bus {} and address {}'.format(bus_n, bus_addr)

        # types of verbose printing
        self.verbose = False
        self.verbose_data = False

        # thread safe deque for sharing and plotting
        self.q_maxlen = 300
        self.q = deque(maxlen=self.q_maxlen)
        self.q_prefill_zeros = False

        # realtime/stream options
        self.go = False
        self.unlimited = False
        self.max_samples = 1000

        ## Metadata information about this device
        self.metadata = Meta(name=name)

        # device/source specific descriptions
        self.metadata.description  = 'dummy_data'
        
        # URL(s) for data source reference
        self.metadata.urls         = 'www.example.com'
        
        # manufacturer of device/source of data
        self.metadata.manufacturer = 'Nikola Tesla Company'
        
        ## data output descriptions
        # names of each kind of data value being recorded
        self.metadata.header       = ['description', 'sample_n', 'degree', 'amplitude']
        
        # data types (int, float, etc) for each data value
        self.metadata.dtype        = ['str', 'int', 'float', 'float']
        
        # measured units of data values
        self.metadata.units        = [None, 'count', 'degrees', 'real numbers']
        
        # accuracy in units of data values
        self.metadata.accuracy     = [None, 1, 0.2, 0.2] 
        
        # precision in units of data values
        self.metadata.precision    = [None, 1, 0.1, 0.1]
        
        # I2C bus the device is on
        self.metadata.bus_n = bus_n
        
        # I2C bus address the device is on
        self.metadata.bus_addr = bus_addr

        ## Data writers for this device
        self.writer_output = output
        self.csv_writer = CSVWriter(metadata=self.metadata, time_format='std_time_ms')
        self.json_writer = JSONWriter(metadata=self.metadata, time_format='std_time_ms')
        
        # synthetic data
        self._deg = list(range(360))
        self._amp = [sin(d * (pi/180.0)) for d in self._deg]
        self._test_data = list(zip(self._deg, self._amp))
Exemplo n.º 18
0
    def __init__(self, bus_n, bus_addr=0x77, output='csv', sensor_id='BME680'):
        """Initialize worker device on i2c bus.

        For register memory map, see datasheet pg 28, section 5.2

        Parameters
        ----------
        bus_n : int, i2c bus number on Controller
        bus_addr : int, i2c bus number of this Worker device
        output : str, writer output format, either 'csv' or 'json'
        sensor_id : str, sensor id, 'BME680' by default
        """

        # i2c bus
        self.bus = I2C(bus_n=bus_n, bus_addr=bus_addr)

        # Default oversampling and filter register values.
        self.refresh_rate = 1
        self.filter = 1

        # memory mapped from 8 bit register locations
        self.mode = 0b00  # 2 bits, ctrl_meas <1:0>  operation mode
        self.osrs_p = 0b001  # 3 bits, ctrl_meas <4:2>, oversample pressure
        self.osrs_t = 0b001  # 3 bits, ctrl_meas <2:0>, oversample temperature
        self.osrs_h = 0b001  # 3 bits, ctrl_hum <2:0>,  oversample humidity
        self.run_gas = 0b0  # 1 bit,  ctrl_gas_1 <4>,  run gas measurement
        self.nb_conv = 0b000  # 4 bits, ctrl_gas_1 <3:0> conversion profile number
        self.heat_off = 0b0  # 1 bit,  ctrl_gas_0 <3>,  gas heater on/off

        # profile registers
        self.gas_wait_x = None  # gas_wait registers 9-0
        self.res_heat_x = None  # res_heat registers 9-0
        self.idac_heat_x = None  # idac_heat registers 9-0

        # calibration and state
        self._temp_calibration = None
        self._pressure_calibration = None
        self._humidity_calibration = None
        self._gas_calibration = None
        self.gas_meas_index = None
        self._new_data = None
        self._gas_measuring = None
        self._measuring = None
        self._heat_range = None
        self._heat_val = None
        self._heat_stab = None
        self._range_switch_error = None

        # raw ADC values
        self._adc_pres = None
        self._adc_temp = None
        self._adc_hum = None
        self._adc_gas = None
        self._gas_range = None
        self._t_fine = None

        # valid data flags
        self._gas_valid = None
        self._head_stab = None

        # control registers
        self._r_ctrl_meas = None
        self._r_ctrl_gas_1 = None

        # the datasheet gives two options: float or int values and equations
        # this code uses integer calculations, see table 16
        self._const_array1_int = (2147483647, 2147483647, 2147483647,
                                  2147483647, 2147483647, 2126008810,
                                  2147483647, 2130303777, 2147483647,
                                  2147483647, 2143188679, 2136746228,
                                  2147483647, 2126008810, 2147483647,
                                  2147483647)
        self._const_array2_int = (4096000000, 2048000000, 1024000000,
                                  512000000, 255744255, 127110228, 64000000,
                                  32258064, 16016016, 8000000, 4000000,
                                  2000000, 1000000, 500000, 250000, 125000)

        # Pressure in hectoPascals at sea level, used to calibrate altitude
        self.sea_level_pressure = 1013.25

        # calculated ambient temperature for res_heat target calculation
        self.amb_temp = None

        # sample collection metadata
        self._last_reading = 0
        self._min_refresh_time = 1 / self.refresh_rate

        # information about this device
        self.metadata = Meta(name='BME680')
        self.metadata.description = 'Bosch Humidity, Pressure, Temperature, VOC Sensor'
        self.metadata.urls = 'https://www.bosch-sensortec.com/products/environmental-sensors/gas-sensors-bme680/'
        self.metadata.manufacturer = 'Bosch Sensortec'

        self.metadata.header = [
            'system_id', 'sensor_id', 'description', 'sample_n', 'T', 'P',
            'RH', 'g_res', 'g_val', 'heat_stab'
        ]
        self.metadata.dtype = [
            'str', 'str', 'str', 'int', 'float', 'float', 'float', 'float',
            'bool', 'bool'
        ]
        self.metadata.units = [
            'NA',
            'NA',
            'NA',
            'count',
            'Celcius',
            'hectopascals',
            'percent',
            'ohms',
            'NA',
            'NA',
        ]
        self.metadata.accuracy = [
            'NA', 'NA', 'NA', '1', '+/-1.0', '+/-0.12', '+/-3', '+/-15%', 'NA',
            'NA'
        ]
        self.metadata.precision = [
            'NA', 'NA', 'NA', '1', '0.1', '0.18', '0.008', '0.08', 'NA', 'NA'
        ]
        self.metadata.bus_n = bus_n
        self.metadata.bus_addr = hex(bus_addr)

        # data recording information
        self.system_id = None
        self.sensor_id = sensor_id

        self.writer_output = output
        self.csv_writer = CSVWriter(metadata=self.metadata,
                                    time_format='std_time_ms')
        self.json_writer = JSONWriter(metadata=self.metadata,
                                      time_format='std_time_ms')
Exemplo n.º 19
0
    def __init__(self, bus_n, bus_addr=0x40, output='csv', name='ina219'):
        """Initialize worker device on i2c bus.

        Parameters
        ----------
        bus_n : int, i2c bus number on Controller
        bus_addr : int, i2c bus number of this Worker device
        """

        # i2c bus
        self.bus = base.I2C(bus_n=bus_n, bus_addr=bus_addr)

        self.reg_config = None
        self.reg_shunt_voltage = None
        self.reg_bus_voltage = None
        self.reg_power = None
        self.reg_calibration = None

        self.reg_map = {
            'config': 0x00,
            'shunt_voltage': 0x01,
            'bus_voltage': 0x02,
            'power': 0x03,
            'current': 0x04,
            'calibration': 0x05
        }

        # bus voltage range
        self.bv_reg_to_bv = {0: 16, 1: 32}

        # programable gain amplifier
        self.pga_reg_to_gain = {0: 1, 1: 2, 2: 4, 3: 8}
        self.pga_gain_to_reg = {1: 0, 2: 1, 4: 2, 8: 3}
        self.pga_reg_str_range = {
            1: "+/- 40 mV",
            2: "+/- 80 mV",
            4: "+/- 160 mV",
            8: "+/- 320 mV"
        }

        # print debug statements
        self.verbose = False

        # data recording information
        self.sample_id = None

        # information about this device
        self.metadata = Meta(name=name)
        self.metadata.description = 'Texas Instruments Bidirectional Current Monitor'
        self.metadata.urls = 'www.ti.com/product/ADS1115'
        self.metadata.manufacturer = 'Adafruit Industries & Texas Instruments'

        self.metadata.header = [
            'description', 'sample_n', 'voltage', 'current'
        ]
        self.metadata.dtype = ['str', 'int', 'float', 'float']
        self.metadata.units = [None, 'count', 'volt', 'amp']
        self.metadata.accuracy = [None, 1, '+/-0.2%', '+/-0.2%']
        self.metadata.precision = [None, 1, '4 mV', '10uV accross shunt']
        self.metadata.accuracy_note = 'values for model INA291A'

        self.metadata.bus_n = bus_n
        self.metadata.bus_addr = hex(bus_addr)

        # chip defaults on power up or reset command
        self.metadata.bus_voltage_range = self.bv_reg_to_bv[1]
        self.metadata.gain = self.pga_reg_to_gain[0b11]
        self.metadata.gain_string = self.pga_reg_str_range[self.metadata.gain]

        self.metadata.bus_adc_resolution = 12
        self.metadata.bus_adc_averaging = None

        self.metadata.shunt_adc_resolution = 12
        self.metadata.shunt_adc_averaging = None

        self.metadata.mode = 7
        self.mode_to_str = {
            0: "power down",
            1: "shunt voltage, triggered",
            2: "bus voltage, triggered",
            3: "shunt and bus voltages, triggered",
            4: "ADC off (disabled)",
            5: "shunt voltage, continuous",
            6: "bus voltage, continuous",
            7: "shunt and bus voltages, continuous"
        }
        self.metadata.mode_description = self.mode_to_str[self.metadata.mode]

        # Adafruit INA219 breakout board as a 0.1 ohm 1% 2W resistor
        self.metadata.r_shunt = 0.1

        # data recording method
        self.writer_output = output
        self.csv_writer = CSVWriter(metadata=self.metadata,
                                    time_format='std_time_ms')
        self.json_writer = JSONWriter(metadata=self.metadata,
                                      time_format='std_time_ms')

        # intialized configuration values
        self.get_config()
Exemplo n.º 20
0
    def __init__(self, bus_n, bus_addr=0x48, output='csv', name='ADS1115'):
        """Initialize worker device on i2c bus.

        Parameters
        ----------
        bus_n : int, i2c bus number on Controller
        bus_addr : int, i2c bus number of this Worker device
        """

        # i2c bus
        self.bus = I2C(bus_n=bus_n, bus_addr=bus_addr)

        # time to wait for conversion to finish
        self.delay = 0.009  # units = seconds

        # register values and defaults
        self.conversion_value = 40000  # higher than any conversion result
        self.config_value = None  # 0x8583 default
        self.lo_thres_value = None  # 0x8000 default
        self.hi_thres_value = None  # 0x7fff default

        self.reg_map = {
            'conversion': 0b00,
            'config': 0b01,
            'lo_thresh': 0b10,
            'hi_thresh': 0b11
        }

        # config register attributes and chip defaults
        self.comp_que_value = 0b11
        self.comp_lat_value = 0b0
        self.comp_pol_value = 0b0
        self.comp_mode_value = 0b0
        self.dr_value = 0b100
        self.mode_value = 0b1
        self.pga_value = 0b010
        self.mux_value = 0b000
        self.os_value = 0b0

        # voltage measurement
        self.pga_float = -999
        self.volts = -999

        # attribute converters
        self.str_mux = {
            '01': 0b000,
            '03': 0b001,
            '13': 0b010,
            '23': 0b011,
            '0G': 0b100,
            '1G': 0b101,
            '2G': 0b110,
            '3G': 0b111
        }
        self.bin_mux = {v: k for k, v in self.str_mux.items()}

        self.str_pga = {
            '6.144': 0b000,
            '4.096': 0b001,
            '2.048': 0b010,
            '1.024': 0b011,
            '0.512': 0b100,
            '0.256': 0b101
        }
        self.bin_pga = {v: float(k) for k, v in self.str_pga.items()}
        self.str_mode = {'continuous': 0b0, 'single': 0b1}
        self.bin_mode = {v: k for k, v in self.str_mode.items()}
        self.str_data_rate = {
            8: 0b000,
            16: 0b001,
            32: 0b010,
            64: 0b011,
            128: 0b100,
            250: 0b101,
            475: 0b110,
            860: 0b111
        }
        self.bin_data_rate = {v: k for k, v in self.str_data_rate.items()}
        self.str_comp_mode = {'trad': 0b0, 'window': 0b1}
        self.bin_comp_mode = {v: k for k, v in self.str_comp_mode.items()}
        self.str_comp_pol = {'1': 0b00, '2': 0b01, '3': 0b10, 'off': 0b11}
        self.bin_comp_pol = {v: k for k, v in self.str_comp_pol.items()}
        self.str_comp_lat = {'off': 0b0, 'on': 0b1}
        self.bin_comp_lat = {v: k for k, v in self.str_comp_lat.items()}
        self.str_comp_que = {'1': 0b00, '2': 0b01, '3': 0b10, 'off': 0b11}
        self.bin_comp_que = {v: k for k, v in self.str_comp_que.items()}

        # information about this device
        self.metadata = Meta(name=name)
        self.metadata.description = ('Texas Instruments 16-bit 860SPS' +
                                     ' 4-Ch Delta-Sigma ADC with PGA')
        self.metadata.urls = 'www.ti.com/product/ADS1115'
        self.metadata.manufacturer = 'Texas Instruments'

        self.metadata.header = ['description', 'sample_n', 'mux', 'voltage']
        self.metadata.dtype = ['str', 'int', 'str', 'float']
        self.metadata.units = [None, 'count', 'str', 'volts']
        self.metadata.accuracy = [None, 1, None, '+/- 3 LSB']
        self.metadata.precision = [None, 1, None, '16 bit']

        self.metadata.bus_n = bus_n
        self.metadata.bus_addr = hex(bus_addr)

        # current settings of this device
        self.metadata.pga_gain = self.pga_float

        # data recording information
        self.sample_id = None

        self.writer_output = output
        self.csv_writer = CSVWriter(metadata=self.metadata,
                                    time_format='std_time_ms')
        self.json_writer = JSONWriter(metadata=self.metadata,
                                      time_format='std_time_ms')

        # initialize class attributes from device registry
        self.get_config()
Exemplo n.º 21
0
    def __init__(self, bus_n, bus_addr=0x60, output='csv', name='mcp4728'):
        """Initialize worker device on i2c bus.
        
        Note 1
        ------
        Default I2C bus address is 0x60 = 0b1100000
        
        From the dataset, section 5.3:
        The first part of the address byte consists of a 4-bit device code,
        which is set to 1100 for the MCP4728 device. The device code is 
        followed by three I2C address bits (A2, A1, A0) which are 
        programmable by the users.
        
        4-bit device code: 
            0b 1 1 0 0 

        Programmable user bits:
            0b A1 A2 A3 = 0b 0 0 0 

        (a) Read the address bits using “General Call Read
        Address” Command (This is the case when the
        address is unknown). See class self.read_address().
        (b) Write I2C address bits using “Write I2C Address
        Bits” Command. The Write Address command will replace 
        the current address with a new address in both input 
        registers and EEPROM. See class method self.XXXX().
        
        Note 2
        ------
        In most I2C cases, v_dd will be either 3.3V or 5.0V. The MCP4728 can
        handle as much as 24mA current at 5V (0.12W) in short circuit. 
        By comparison, the Raspberry Pi can source at most 16mA of current 
        at 3.3V (0.05W). Unless the application output will draw a very 
        small amount of current, an external (to the I2C bus) voltage source 
        should probably be used. 
        See the Adafruit ISO1540 Bidirectional I2C Isolator as a possible solution.
        
        Note 3
        ------
        The manufacturer uses the term VDD (Vdd) for external voltage, many other 
        sources use the term VCC (Vcc). VDD is used here to be consistent with the
        datasheet, but manufacturers like Adafruit use VCC on the pinouts labels.
        
        Parameters
        ----------
        bus_n : int, i2c bus number on Controller
        bus_addr : int, i2c bus number of this Worker device
        """

        # i2c bus
        self.bus = I2C(bus_n=bus_n, bus_addr=bus_addr)
        self.udac = 0
        self.state = {'a': None, 'b': None, 'c': None, 'd': None}
        self.v_dd = None

        # information about this device
        self.metadata = Meta(name=name)
        self.metadata.description = 'MCP4728 12-bit Digitial to Analog Converter'
        self.metadata.urls = 'http://ww1.microchip.com/downloads/en/DeviceDoc/22187E.pdf'
        self.metadata.manufacturer = 'Microchip'

        self.metadata.header = [
            'description', 'channel', 'v_ref_source', 'v_dd', 'power_down',
            'gain', 'input_code', 'output_voltage'
        ]
        self.metadata.dtype = [
            'str', 'str', 'str', 'float', 'str', 'int', 'int', 'float'
        ]
        self.metadata.units = [
            None, None, None, 'volts', None, None, None, 'volts'
        ]
        self.metadata.accuracy = None
        self.metadata.precision = 'vref: gain 1 = 0.5mV/LSB, gain 2 = 1mV/LSB; vdd: vdd/4096'

        self.metadata.bus_n = bus_n
        self.metadata.bus_addr = hex(bus_addr)

        # data recording method
        self.writer_output = output
        self.csv_writer = CSVWriter(metadata=self.metadata,
                                    time_format='std_time_ms')
        self.json_writer = JSONWriter(metadata=self.metadata,
                                      time_format='std_time_ms')
Exemplo n.º 22
0
    def __init__(self, bus_n, bus_addr=0x18, output='csv'):
        """Initialize worker device on i2c bus.

        Parameters
        ----------
        bus_n : int, i2c bus number on Controller
        bus_addr : int, i2c bus number of this Worker device
        """

        # i2c bus
        self.bus = I2C(bus_n=bus_n, bus_addr=bus_addr)

        # register values and defaults
        # TODO: do the constant values need to be specified?
        self.reg_map = {
            'config': REG_CONFIG,
            'upper_temp': REG_UPPER_TEMP,
            'lower_temp': REG_LOWER_TEMP,
            'crit_temp': REG_CRIT_TEMP,
            'ambient': REG_AMBIENT_TEMP,
            'manufacturer': REG_MANUF_ID,
            'device_id': REG_DEVICE_ID
        }

        self.alert_critial = None
        self.alert_upper = None
        self.alert_lower = None

        self.manufacturer_id = None
        self.device_id = None
        self.revision = None

        # information about this device
        self.device = DeviceData('MCP9808')
        self.device.description = (
            '+/-0.5 degrees Celcius ' +
            'maximum accuracy digital temperature sensor')
        self.device.urls = 'https://www.microchip.com/datasheet/MCP9808'
        self.device.active = None
        self.device.error = None
        self.device.bus = repr(self.bus)
        self.device.manufacturer = 'Microchip'
        self.device.version_hw = '0.1'
        self.device.version_sw = '0.1'
        self.device.accuracy = '+/-0.25 (typical) C'
        self.device.precision = '0.0625 C maximum'
        self.device.units = 'Degrees Celcius'
        self.device.calibration_date = None

        # data recording information
        self.sample_id = None

        # data recording method
        self.writer_output = output
        self.csv_writer = CSVWriter("MCP9808", time_format='std_time_ms')
        self.csv_writer.device = self.device.__dict__
        self.csv_writer.header = ['description', 'sample_n', 'temperature']

        self.json_writer = JSONWriter("MCP9808", time_format='std_time_ms')
        self.json_writer.device = self.device.__dict__
        self.json_writer.header = ['description', 'sample_n', 'temperature']