Пример #1
0
    def __init__(self, ads=None):
        if ads is None:
            if not adc is None:
                ads = adc
            else:
                try:
                    if ADS_TYPE == 1015:
                        ads = ads1015.ADS1015(board.I2C(),
                                              gain=ADC_GAIN,
                                              address=ADC_ADDR)
                    else:
                        ads = ads1115.ADS1115(board.I2C(),
                                              gain=ADC_GAIN,
                                              address=ADC_ADDR)
                # except (OSError, ValueError) as err:
                except:
                    print("[LevelSensor]  No ADS1x15 breakout detected!")
                    ads = None

        super().__init__(analog_in.AnalogIn(ads, LevelSensor.L_PIN))

        self.history = [0.0] * NSAMPLES
        self._sampleCnt = 0
        self._idx = 0

        if WARM_UP_LEVEL_SENSOR:
            for i in range(NSAMPLES * 3):
                self._level = self.readSensor()
                if PRINTS_ON:
                    print('.', end='')
                time.sleep(1)
        if PRINTS_ON:
            print('\n=== SENSORS INITIALIZED ===\n')
Пример #2
0
    def __init__(self, pi, state, queue):
        super().__init__(pi, state, queue)
        self.callbacks = {}
        self.levels = {}

        # analog inputs
        self.i2c = busio.I2C(board.SCL, board.SDA)
        self.ads = ADS.ADS1015(self.i2c)

        # power button
        gpio.setmode(gpio.BCM)
        gpio.setup(pins.ON_BUTTON, gpio.IN)
        gpio.add_event_detect(pins.ON_BUTTON,
                              gpio.RISING,
                              callback=self._toggle_power,
                              bouncetime=200)

        # analog (multiplexed) buttons
        self.buttons = AnalogIn(self.ads, ADS.P0)

        # rotary encoder
        self.last_rotary_gpio = None
        for button in (pins.POTI_1, pins.POTI_2):
            gpio.setup(button, gpio.IN)
            gpio.add_event_detect(button,
                                  gpio.BOTH,
                                  callback=self._rotary,
                                  bouncetime=20)
Пример #3
0
def IC_init():
    adc = list()
    gpioe = list()

    adc_add = list()
    gpio_add = list()

    for sysitr in range(totsys):
        sysnum = sysitr + 1
        confsec = 'EVE' + str(sysnum)
        if config[confsec].getboolean('enabled'):
            adc_add.append(config[confsec].getint('a_address'))
            if not config[confsec].getboolean('Pi_pins'):
                gpio_add.append(config[confsec].getint('m_address'))

    adc_add = list(set(adc_add))
    gpio_add = list(set(gpio_add))

    i2c = busio.I2C(board.SCL, board.SDA)

    if adc_add:
        for add in adc_add:
            adc.append(ADS.ADS1015(i2c, address=add))

    if gpio_add:
        for add in gpio_add:
            gpioe.append(adafruit_mcp230xx.MCP23017(i2c, address=add))

    return {
        'adc': adc,
        'gpioe': gpioe,
        'adc_add': adc_add,
        'gpio_add': gpio_add
    }
Пример #4
0
 def __init__(self, i2c, config, logging):
     self.logging = logging
     self.ads = ADS.ADS1015(i2c, address=int(config['init']['address'], 16))
     self.ch0 = AnalogIn(self.ads, ADS.P0)
     self.ch1 = AnalogIn(self.ads, ADS.P1)
     self.ch2 = AnalogIn(self.ads, ADS.P2)
     self.ch3 = AnalogIn(self.ads, ADS.P3)
Пример #5
0
class TemperatureController:
    stateController = {}
    temperatureConverter = TemperatureConverter()
    i2c = busio.I2C(board.SCL, board.SDA)
    ads = ADS.ADS1015(i2c)
    ads.gain = 2 / 3
    adcVoltageConstant = 5 / 26544  # Defined by the measurement without any probes attached
    meatChannel = AnalogIn(ads, ADS.P3)  # Blauw-paarsje draadjes
    bbqChannel = AnalogIn(ads, ADS.P2)  # Groen-gele draadjes

    def __init__(self, stateController):
        self.stateController = stateController
        threading.Timer(1, self.onTimer).start()

    def onTimer(self):
        threading.Timer(1, self.onTimer).start()
        bbqTemp = self.temperatureConverter.convertBbq(self.bbqChannel.value *
                                                       self.adcVoltageConstant)
        meatTemp = self.temperatureConverter.convertMeat(
            self.meatChannel.value * self.adcVoltageConstant)
        self._updateState(bbqTemp, meatTemp)

    def _updateState(self, bbqTemp, meatTemp):
        # hou deze functie zo snel mogelijk, om te voorkomen dat we stae changes uit andere threads overschrijven
        oldState = self.stateController.getState()
        newState = copy.copy(oldState)
        newState.bbqTemp = bbqTemp
        newState.meatTemp = meatTemp
        self.stateController.updateState(newState)
Пример #6
0
    def __init__(self, channel):
        """
			Configure the I2C bus.

			:param channel: Channel number where the potentiometer is connected [0|1|2].
			**Authors of this class :** CHENUAUD Emmanuel and LAMBERT Vincent.\n  
		"""

        # Create the I2C bus.
        self.i2c = busio.I2C(board.SCL, board.SDA)
        # Create the ADC object using the I2C bus.
        self.adc = ADS.ADS1015(self.i2c)

        if (channel < 0 or channel > 3):
            print(
                "[AnalogDigitalConverter] Error, the channel can't be configured (Channel must be between 0 and 3) !"
            )
            return

        if (channel == 0):
            # Create single-ended input on channel 0
            self.channel = AnalogIn(self.adc, ADS.P0)

        if (channel == 1):
            # Create single-ended input on channel 1
            self.channel = AnalogIn(self.adc, ADS.P1)

        if (channel == 2):
            # Create single-ended input on channel 2
            self.channel = AnalogIn(self.adc, ADS.P2)

        if (channel == 3):
            # Create single-ended input on channel 3
            self.channel = AnalogIn(self.adc, ADS.P3)
Пример #7
0
    def __init__(self, i2c_addr=0x48, gain=1, readings_to_average=1):
        """
        A Vegetronix VH400 MoistureSensor.

            Select the gain
              gain = 2/3  # +/- 6.144V
              gain = 1  # +/- 4.096V
              gain = 2  # +/- 2.048V
              gain = 4  # +/- 1.024V
              gain = 8   # +/- 0.512V
              gain = 16   # +/- 0.256V

            Possible ADS1x15 i2c address: 0x48, 0x48, 0x4a, 0x4b
            Our default is 0x48  This will probably be hard-coded on the board.

        :param i2c_addr: i2c address of the ADS1115 chip
        :type i2c_addr: hex
        :param gain: Input gain.  This shouldn't be changed from 4096 as the VH400 has a 0-3v output
        :type gain: int
        :param readings_to_average: How many readings to we average before returning a value
        :type readings_to_average: int
        """
        ads = ADS.ADS1015(busio.I2C(board.SCL, board.SDA))
        ads.gain = gain

        self._i2c_addr = i2c_addr
        self._gain = gain
        self._chan = AnalogIn(ads, ADS.P0)
        self.readings_to_average = readings_to_average
Пример #8
0
 def __init__(self, i2c):
     self.i2c = i2c
     
     self.ads = ADS.ADS1015(i2c)
     self.chan = AnalogIn(self.ads, ADS.P0)
     self.calibration = 0
     self.percent = 0
Пример #9
0
    def __init__(self, ):

        if GPIO_OKAY:

            try:
                import board
                import busio
                import adafruit_ads1x15.ads1015 as ADS
                from adafruit_ads1x15.analog_in import AnalogIn

                # Create the I2C bus
                self.i2c = busio.I2C(board.SCL, board.SDA)

                # Create the ADC object using the I2C bus
                self.ads = ADS.ADS1015(self.i2c)
                self.ads.gain = 8

                # Create single-ended input on channel 0
                self.chan = AnalogIn(self.ads, ADS.P0)

                self.get_reading = self._get_readings

            except ValueError:
                print('connection to the i2c not successful')
                self.get_reading = self._fake_readings
        else:
            self.get_reading = self._fake_readings
Пример #10
0
def temperatureReading():
    # Create the I2C bus
    i2c = busio.I2C(board.SCL, board.SDA)
    # Create the ADC object using the I2C bus
    ads = ADS.ADS1015(i2c)
    # Create single-ended input on channel 0
    chan = AnalogIn(ads, ADS.P0)
    ##print(chan.value, chan.voltage)
    # setting parameters
    TEMPERATURENOMINAL = 25
    BCOEFFICIENT = 3969
    THERMISTORNOMINAL = 10000
    # RESISTOR = 8740
    # RESISTOR = 5780
    # RESISTOR = 2890
    RESISTOR = 2700
    # Create differential input between channel 0 and 1
    # chan = AnalogIn(ads, ADS.P0, ADS.P1)
    # print("{:>5}\t{:>5}".format('raw', 'v'))
    counter = 0
    numberOfValues = 20
    values = []
    # while True:
    while not (counter == (numberOfValues + 1)):
        counter = counter + 1
        try:
            # 	Vout = Vin * (R2/R1+R1)
            # 	find resistance of thermistor using adc reading.  Simple resistor divider, solving for R1 using	  	R2 = 2890
            reading = ((1023 - chan.value) / 1023) * 4095
            # print(str(chan.value) + "  " + str(reading))
            resistor = (((4095.0) / (reading)) - 1) * RESISTOR
            # solve for temperature using 		1/T = (1/To) + (1/B)*ln(R/Ro)adc 1015
            # print ("resistor " + str(resistor))

            steinhart = resistor / THERMISTORNOMINAL
            steinhart = math.log(steinhart)
            steinhart = steinhart / BCOEFFICIENT
            steinhart = steinhart + (1 / (TEMPERATURENOMINAL + 273.15))
            steinhart = 1 / steinhart
            steinhart = steinhart - 273.15

            # print ("Every Iteration Output: " + str(steinhart))
            values.append(steinhart)

            if counter == numberOfValues:
                steinhart = 0
                for value in values:
                    steinhart = steinhart + value

                steinhart = steinhart / numberOfValues
                # print("The Average Value: " + str(steinhart) + " C")
                save2db(round(steinhart, 2))
                break
                values = []

        except:
            pass

        # print("{:>5}\t{:>5.3f}".format(chan.value, chan.voltage))
        time.sleep(0.5)
Пример #11
0
    def __init__(self):
        i2c = busio.I2C(board.SCL, board.SDA)
        ads = ADS.ADS1015(i2c)
        self._chan0 = AnalogIn(ads, ADS.P0)
        self._chan1 = AnalogIn(ads, ADS.P1)
        self._chan2 = AnalogIn(ads, ADS.P2)
        self._chan3 = AnalogIn(ads, ADS.P3)

        print("ADS1015 DAQ initialized.")
    def __init__(self, channel=0):
        self.i2c = busio.I2C(board.SCL, board.SDA)

        self.ads = ADS.ADS1015(self.i2c)
        self.ads.gain = 1
        self.ads.data_rate = 128
        self.chan = AnalogIn(self.ads, ADS.P0)

        self.BPM = 0
 def __init__(self):
     self.i2c = busio.I2C(board.SCL, board.SDA)
     self.ads = ADS.ADS1015(self.i2c)
     self.chans = [
         MoistureSensorChannel(self.ads, ADS.P0),
         MoistureSensorChannel(self.ads, ADS.P1),
         MoistureSensorChannel(self.ads, ADS.P2),
         MoistureSensorChannel(self.ads, ADS.P3)
     ]
     self.cal_file(update=False)
Пример #14
0
    def __init__(self):
        # Create the I2C bus
        self.i2c = busio.I2C(board.SCL, board.SDA)

        # Create the ADC object using the I2C bus
        self.ads = ADS.ADS1015(i2c)

        # Create single-ended input on channel 0
        self.chan0 = AnalogIn(ads, ADS.P0)
        self.chan1 = AnalogIn(ads, ADS.P1)
Пример #15
0
def check_moisture():
    i2c = busio.I2C(board.SCL, board.SDA)
    ads = ADS.ADS1015(i2c)
    chan = AnalogIn(ads, ADS.P0)
    mode = GPIO.getmode()

    print(mode)
    if chan.value <= MOISTURE_LIMIT:
        print("Moisture level is low, current level is %d" % chan.value)
        irrigate()
    else:
        print("Moisture level is fine, current level is %d" % chan.value)
Пример #16
0
 def __init__(self, *args, **kwargs):
     """SnakeEyesBonnet constructor."""
     super(SnakeEyesBonnet, self).__init__(*args, **kwargs)  # Thread
     self.i2c = busio.I2C(board.SCL, board.SDA)
     self.ads = ADS.ADS1015(self.i2c)
     self.ads.gain = 1
     self.period = 1.0 / 60.0  # Polling inverval = 1/60 sec default
     self.print_values = False  # Don't print values by default
     self.channel = []
     for index in range(4):
         self.channel.append(
             AdcChannel(AnalogIn(self.ads, self.channel_dict[index])))
Пример #17
0
    def __init__(self):
        # Create the I2C bus
        self.i2c = busio.I2C(board.SCL, board.SDA)

        # Analog to Digital Converter
        self.ads = ADS.ADS1015(self.i2c)
        self.ads.gain = 1  # +/- 4.096

        # Thermal Sensor
        self.therm_sens = W1ThermSensor()

        self.setup_pins()
Пример #18
0
def setup_rpi(registry):
    from controller.device import SwimPumpDevice, TempSensorDevice, TankSensorDevice
    from controller.device import ArduinoDevice, EZOSensorDevice, LcdDevice

    # Relay
    import RPi.GPIO as GPIO
    setup_gpio(registry, GPIO)

    # Initialize I2C bus.
    import board
    import busio
    i2c = busio.I2C(board.SCL, board.SDA)

    # ADC
    import adafruit_ads1x15.ads1015 as ADS
    # Create the ADC object using the I2C bus
    adc = ADS.ADS1015(i2c)
    # With a gain of 2/3 and a sensor output of 0.25V-5V, the values should be around 83 and 1665
    params = ((int, "channel"), (float, "gain"), (int, "low"), (int, "high"))
    registry.add_sensor(
        TankSensorDevice("tank", adc,
                         *[t(config["adc", n]) for t, n in params]))

    # DAC
    import adafruit_mcp4725
    dac = adafruit_mcp4725.MCP4725(i2c)
    registry.add_pump(
        SwimPumpDevice("swim", GPIO, int(config["pins", "swim"]), dac))

    # pH, ORP
    registry.add_sensor(EZOSensorDevice("ph", config["serial", "ph"]))
    registry.add_sensor(EZOSensorDevice("orp", config["serial", "orp"]))

    # Arduino (cover, water)
    registry.add_device(ArduinoDevice("arduino", config["serial", "arduino"]))

    # LCD
    registry.add_device(LcdDevice("lcd", config["serial", "lcd"]))

    # 1-wire
    # 28-031634d04aff
    # 28-0416350909ff
    # 28-031634d54bff
    # 28-041635088bff
    registry.add_sensor(
        TempSensorDevice("temperature_pool", config["1-wire", "pool"]))
    registry.add_sensor(
        TempSensorDevice("temperature_air", config["1-wire", "air"]))
    registry.add_sensor(
        TempSensorDevice("temperature_local", config["1-wire", "local"]))
    registry.add_sensor(
        TempSensorDevice("temperature_ncc", config["1-wire", "ncc"]))
    def __init__(self):
        i2c_bus = busio.I2C(board.SCL, board.SDA)
        adc = ADC.ADS1015(i2c_bus)
        self.adc_channel_0 = AnalogIn(adc, ADC.P0)
        self.rdg_buffer = []

        # Spawn ApneaMonitor Thread
        self.ApneaMonitor = Thread(
            target=self.update_buffer,
            name='ApneaMontor',
        )
        self.ApneaMonitor.daemon = True
        self.ApneaMonitor.start()
Пример #20
0
    def __init__(self):
        self.i2c = busio.I2C(board.SCL, board.SDA)
        self.station_id = "Amsterdam"

        self.cpu = CPUTemperature()
        self.sht = adafruit_shtc3.SHTC3(self.i2c)
        self.lps = adafruit_lps2x.LPS22(self.i2c, 0x5c)

        self.tcs = adafruit_tcs34725.TCS34725(self.i2c)
        self.tcs.integration_time = 200

        self.icm = adafruit_icm20x.ICM20948(self.i2c, 0x68)
        self.ads = ADS.ADS1015(self.i2c)
Пример #21
0
    def init_geophone(self):
        global chan

        # Create the I2C bus
        i2c = busio.I2C(board.SCL, board.SDA)

        # Create the ADC object using the I2C bus
        ads = ADS.ADS1015(i2c)

        # Create differential input between channel 0 and 1
        chan = AnalogIn(ads, ADS.P0, ADS.P1)

        return chan
Пример #22
0
def setup_adc():
    # Create the I2C bus
    i2c = busio.I2C(board.SCL, board.SDA)

    # Create the ADC object using the I2C bus
    ads = ADS.ADS1015(i2c)

    # Create single-ended input on all channels
    chan0 = AnalogIn(ads, ADS.P0)
    chan1 = AnalogIn(ads, ADS.P1)
    chan2 = AnalogIn(ads, ADS.P2)
    chan3 = AnalogIn(ads, ADS.P3)
    return chan0, chan1, chan2, chan3
Пример #23
0
def get_value():
    # Create the I2C bus
    i2c = busio.I2C(board.SCL, board.SDA)

    # Create the ADC object using the I2C bus
    ads = ADS.ADS1015(i2c)

    # Create single-ended input on channel 0
    chan = AnalogIn(ads, ADS.P3)

    humidityPercent = (3.3 -
                       chan.voltage) / 2.4 * 100  #Soil Humidity Percentage

    return humidityPercent
Пример #24
0
    def __init__(self):
        self.running = True
        self.soilValue = 0.0

        # this system is a little more simple so we don't need to use threading events
        self.mutex = threading.Lock()
        # Create the I2C bus
        self.i2c = busio.I2C(board.SCL, board.SDA)

        # Create the ADC object using the I2C bus
        self.ads = ADS.ADS1015(self.i2c)

        # Create single-ended input on channel 0
        self.chan = AnalogIn(self.ads, ADS.P0)
Пример #25
0
    def __init__(self, pin, gpiop):
        self.i2c = busio.I2C(board.SCL, board.SDA)
        self.ads = ADS.ADS1015(self.i2c)
        self.chan = {}
        for p in pin:
            self.chan[p] = AnalogIn(self.ads, getattr(ADS, 'P' + str(p)))

        self.gpiop = gpiop
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(gpiop, GPIO.OUT)
        self.powerstate = False

        self.tempsensor = AsyncW1ThermSensor()
        self.exp_start = datetime.datetime.now()
Пример #26
0
def main():

    i2c = busio.I2C(board.SCL, board.SDA)
    ads = ADS.ADS1015(i2c)
    channel = AnalogIn(ads, ADS.P0)

    pub = rospy.Publisher('dados', Int32, queue_size=10)
    rospy.init_node('adc', anonymous=False)
    rate = rospy.Rate(1600)

    while not rospy.is_shutdown():
        dados = channel.voltage * 1000
        pub.publish(Int32(dados))
        rate.sleep()
Пример #27
0
def adc_setup():
    ## Create the I2C bus
    i2c = busio.I2C(board.SCL, board.SDA)
    #Create the ADC object using the I2C bus
    ads = ADS.ADS1015(i2c)

    # Create single-ended input on all channels
    # Connect Out pin to ADC Channel 0
    # Connect RV pin to ADC Channel 1
    # Connect TMP pin to ADC Channel 2
    a_out = AnalogIn(ads, ADS.P3)
    a_rv = AnalogIn(ads, ADS.P2)
    a_temp = AnalogIn(ads, ADS.P1)
    return a_out, a_rv, a_temp
Пример #28
0
    def __init__(self, test=False):

        self.test = test
        if not self.test:
            import busio
            import board
            import adafruit_ads1x15.ads1015 as ADS
            from adafruit_ads1x15.analog_in import AnalogIn

            i2c = busio.I2C(board.SCL, board.SDA)

            self.ads = ADS.ADS1015(i2c)
            self.chan = AnalogIn(self.ads, ADS.P0)
        self.GAIN = 2 / 3
        self.set_calibration()
Пример #29
0
    def initialize_input(self):
        import adafruit_ads1x15.ads1015 as ADS
        from adafruit_ads1x15.analog_in import AnalogIn
        from adafruit_extended_bus import ExtendedI2C

        self.analog_in = AnalogIn
        self.ads = ADS

        if self.input_dev.adc_gain == 0:
            self.adc_gain = 2/3
        else:
            self.adc_gain = self.input_dev.adc_gain

        self.adc = ADS.ADS1015(
            ExtendedI2C(self.input_dev.i2c_bus),
            address=int(str(self.input_dev.i2c_location), 16))
Пример #30
0
    def read(self):

        
        # Channels to cycle through and read, along with channel number identifier
        channels = [
            (ADS.P0, 0),
            (ADS.P1, 1),
            (ADS.P2, 2)
        ]

        # use the same timestamp for all six channels
        ts = time.time()
        data = [None] * SAMPLES
        readings = []

        # Create the I2C bus
        i2c = busio.I2C(board.SCL, board.SDA)

        ix = 0
        for addr in (0x48, 0x49):

            # Create the ADC object using the I2C bus
            ads = ADS.ADS1015(i2c, address=addr)
            ads.mode = Mode.CONTINUOUS
            ads.data_rate = RATE
            
            for ads_ch in (ADS.P0, ADS.P1, ADS.P2):
                
                sensor_id = f'{self._settings.LOGGER_ID}_rms_ch{ix + 1}'

                ads.gain = self._gain[ix]
                # Create differential input between this channel and channel 3.
                chan = AnalogIn(ads, ads_ch, ADS.P3)

                for i in range(SAMPLES):
                    data[i] = chan.voltage
                arr = np.array(data)
                arr2 = arr * arr
                rms = arr2.mean() ** 0.5
                readings.append((ts, 
                                 sensor_id, 
                                 rms * self._mult[ix], 
                                 base_reader.VALUE)
                               )
                ix += 1

        return readings