示例#1
0
    def __init__(self, test=False):
        ADS1115 = int(settings["ADS1115"])  # 16-bit ADC

        ADS1115_ADDRESS = int(settings["ADS1115_ADDRESS"], 16)
        ADS1115_GAIN = float(settings["ADS1115_GAIN"])
        ADS1115_SPS = int(settings["ADS1115_SPS"])

        self.REFERENTIAL_VOLTAGE = float(settings["REFERENTIAL_VOLTAGE"])
        self.gain = int(ADS1115_GAIN)
        self.sps = int(ADS1115_SPS)

        # Select the sample rate
        self.sps = 250  # 250 samples per second

        # Initialise the ADC using the default mode (use default I2C address)
        # Set this to ADS1015 or ADS1115 depending on the ADC you are using!
        self.ads1115 = ADS1x15(ic=ADS1115, address=ADS1115_ADDRESS)

        self.instaneousWindDirection = 0
        self._windDirectionQueue = []
        self._windDirectionHistoryInterval = 60 * 10  # 10 minutes
        self.readWindDirection()

        if test == False:
            # start wind reading thread
            self.th = Thread(target=self.startReadingWind)
            self.th.daemon = True
            self.th.start()
示例#2
0
sys.path.append('./SDL_Pi_GroveDigitalExtender')

from SDL_Adafruit_ADS1x15 import ADS1x15

import extendedPlants

import RPi.GPIO as GPIO

################
#4 Channel ADC ADS1115 setup Plant #1
################
# Set this to ADS1015 or ADS1115 depending on the ADC you are using!
ADS1115 = 0x01  # 16-bit ADC

ads1115 = ADS1x15(ic=ADS1115, address=0x48)

# Select the gain
gain = 6144  # +/- 6.144V
#gain = 4096  # +/- 4.096V

# Select the sample rate
sps = 250  # 250 samples per second
# determine if device present
try:
    value = ads1115.readRaw(0, gain, sps)  # AIN0 wired to AirQuality Sensor
    time.sleep(1.0)
    value = ads1115.readRaw(0, gain, sps)  # AIN0 wired to AirQuality Sensor

    config.ADS1115_Present = True
示例#3
0
        display = Adafruit_SSD1306.SSD1306_128_64(rst=RST, i2c_address=0x3C)
        # Initialize library.
        display.begin()
        display.clear()
        display.display()
        config.OLED_Present = True
except:
        config.OLED_Present = False

################
#4 Channel ADC ADS1115 setup
################
# Set this to ADS1015 or ADS1115 depending on the ADC you are using!
ADS1115 = 0x01  # 16-bit ADC

ads1115 = ADS1x15(ic=ADS1115, address=0x48)

# Select the gain
gain = 6144  # +/- 6.144V
#gain = 4096  # +/- 4.096V

# Select the sample rate
sps = 250  # 250 samples per second
# determine if device present
try:
       value = ads1115.readRaw(0, gain, sps) # AIN0 wired to AirQuality Sensor
       time.sleep(1.0)
       value = ads1115.readRaw(0, gain, sps) # AIN0 wired to AirQuality Sensor

       config.ADS1115_Present = True
# gain = 512   # +/- 0.512V
# gain = 256   # +/- 0.256V

# Select the sample rate
# sps = 8    # 8 samples per second
# sps = 16   # 16 samples per second
# sps = 32   # 32 samples per second
# sps = 64   # 64 samples per second
# sps = 128  # 128 samples per second
sps = 250  # 250 samples per second
# sps = 475  # 475 samples per second
# sps = 860  # 860 samples per second

# Initialise the ADC using the default mode (use default I2C address)
# Set this to ADS1015 or ADS1115 depending on the ADC you are using!
adc = ADS1x15(ic=ADS1115)
while (1):

	# Read channel 1 in single-ended mode using the settings above

        print ("channel 0")
	volts = adc.readADCSingleEnded(0, gain, sps) / 1000
	print "%.6f" % (volts)
	time.sleep(0.5)

        print ("channel 1")
	# To read channel 3 in single-ended mode, +/- 1.024V, 860 sps use:
	volts = adc.readADCSingleEnded(1, gain, sps) / 1000
	print "%.6f" % (volts)
	time.sleep(0.5)
示例#5
0
    def __init__(self, pinAnem, pinRain, intAnem, intRain, ADMode):

        GPIO.setup(pinAnem, GPIO.IN)
        GPIO.setup(pinRain, GPIO.IN)

        # when a falling edge is detected on port pinAnem, regardless of whatever
        # else is happening in the program, the function callback will be run

        #GPIO.add_event_detect(pinAnem, GPIO.RISING, callback=self.serviceInterruptAnem)
        #GPIO.add_event_detect(pinRain, GPIO.RISING, callback=self.serviceInterruptRain)
        GPIO.add_event_detect(pinAnem,
                              GPIO.RISING,
                              callback=self.serviceInterruptAnem,
                              bouncetime=40)
        GPIO.add_event_detect(pinRain,
                              GPIO.RISING,
                              callback=self.serviceInterruptRain,
                              bouncetime=40)

        ADS1015 = 0x00  # 12-bit ADC
        ADS1115 = 0x01  # 16-bit ADC
        # Select the gain
        self.gain = 6144  # +/- 6.144V
        #self.gain = 4096  # +/- 4.096V

        # Select the sample rate
        self.sps = 250  # 250 samples per second

        # Initialise the ADC using the default mode (use default I2C address)
        # Set this to ADS1015 or ADS1115 depending on the ADC you are using!
        self.ads1015 = ADS1x15(ic=ADS1015, address=0x48)

        # determine if device present
        try:
            value = self.ads1015.readRaw(
                1, self.gain,
                self.sps)  # AIN1 wired to wind vane on WeatherPiArduino
            time_.sleep(1.0)
            value = self.ads1015.readRaw(
                1, self.gain,
                self.sps)  # AIN1 wired to wind vane on WeatherPiArduino

            # now figure out if it is an ADS1015 or ADS1115
            if ((0x0F & value) == 0):
                config.ADS1015_Present = True
                config.ADS1115_Present = False
                # check again (1 out 16 chance of zero)
                value = self.ads1015.readRaw(
                    0, self.gain,
                    self.sps)  # AIN1 wired to wind vane on WeatherPiArduino
                if ((0x0F & value) == 0):
                    config.ADS1015_Present = True
                    config.ADS1115_Present = False

                else:
                    config.ADS1015_Present = False
                    config.ADS1115_Present = True
                    self.ads1015 = ADS1x15(ic=ADS1115, address=0x48)
            else:
                config.ADS1015_Present = False
                config.ADS1115_Present = True
                self.ads1015 = ADS1x15(ic=ADS1115, address=0x48)

        except TypeError as e:
            print "Type Error"
            config.ADS1015_Present = False
            config.ADS1115_Present = False

        SDL_Pi_WeatherRack._ADMode = ADMode