Esempio n. 1
0
class Device_ABE_DeltaSigmaPiADC:
    """
    https://github.com/abelectronicsuk/ABElectronics_Python_Libraries
    """
    def __init__(self,
                 bus=None,
                 address=None,
                 address2=None,
                 samplerate=None,
                 gain=None):
        from ABE_helpers import ABEHelpers
        from ABE_ADCDifferentialPi import ADCDifferentialPi

        if bus is None:
            i2c_helper = ABEHelpers()
            bus = i2c_helper.get_smbus()

        # Initialize the ADC device using the default addresses and sample rate 18.
        # Sample rate can be 12, 14, 16 or 18.
        self.adc = ADCDifferentialPi(bus,
                                     address=address,
                                     address2=address2,
                                     rate=samplerate)

        # Set amplifier gain to 8.
        if gain is not None:
            self.adc.set_pga(gain)

    def read(self, channel):
        # Returns the voltage from the selected ADC channel - channels 1 to 8.
        return self.adc.read_voltage(channel)
Esempio n. 2
0
def StrainGauge():
    text_file = open("strainGuage_Data.txt", "w")

    i2c_helper = ABEHelpers()
    bus = i2c_helper.get_smbus()
    adc = ADCDifferentialPi(bus, i2cAddr1, i2cAddr2, bitRate)

    adc.set_pga(
        1)  # Set the gain of the PDA on the chip (Parameters: gain - 1,2,4,8)

    prev_voltage = 0

    for i in range(10000):
        voltage = adc.read_voltage(channel)  # voltage output from strain Gauge

        changeInVoltage = voltage - prev_voltage
        prev_voltage = voltage

        #print( str(changeInVoltage * 1000) )

        text_file.write(str(voltage) + "\n")