Exemple #1
0
    def ADS1256_Read_data(self, reg):
        config.digital_write(self.cs_pin, GPIO.LOW)  # cs  0
        config.spi_writebyte([CMD["CMD_RREG"] | reg, 0x00])
        data = config.spi_readbytes(1)
        config.digital_write(self.cs_pin, GPIO.HIGH)  # cs 1

        return data
Exemple #2
0
    def ADS1256_WriteReg(self, _RegID, _RegValue):
        '''Write the corresponding register'''
        config.digital_write(self.cs_pin, GPIO.LOW)
        self.ADS1256_SendData(CMD['CMD_WREG'] | _RegID)
        self.ADS1256_SendData(0x00)

        self.ADS1256_SendData(_RegValue)
        config.digital_write(self.cs_pin, GPIO.HIGH)
 def ADS1256_Read_ADC_Data(self):
     config.digital_write(self.cs_pin, GPIO.LOW)#cs  0
     config.spi_writebyte([CMD['CMD_RDATA']])
     config.delay_ms(10)
     buf = config.spi_readbytes(3)
     config.digital_write(self.cs_pin, GPIO.HIGH)#cs 1
     read = (buf[0]<<16) & 0xff0000
     read |= (buf[1]<<8) & 0xff00
     read |= (buf[2]) & 0xff
     if (read & 0x800000):
         read |= 0xFF000000
     return read
Exemple #4
0
    def ADS1256_ReadReg(self, _RegID):
        '''Read  the corresponding register'''
        config.digital_write(self.cs_pin, GPIO.LOW)
        self.ADS1256_SendData(CMD['CMD_RREG'] | _RegID)
        self.ADS1256_SendData(0x00)

        config.delay_ms(1)

        read_data = config.spi_readbytes(0xff)

        config.digital_write(self.cs_pin, GPIO.HIGH)
        return read_data[0]
 def ADS1256_ConfigADC(self, gain, drate):
     self.ADS1256_WaitDRDY()
     buf = [0,0,0,0,0,0,0,0]
     buf[0] = (0<<3) | (1<<2) | (0<<1)
     buf[1] = 0x08
     buf[2] = (0<<5) | (0<<3) | (gain<<0)
     buf[3] = drate
     
     config.digital_write(self.cs_pin, GPIO.LOW)#cs  0
     config.spi_writebyte([CMD['CMD_WREG'] | 0, 0x03])
     config.spi_writebyte(buf)
     
     config.digital_write(self.cs_pin, GPIO.HIGH)#cs 1
     config.delay_ms(1) 
Exemple #6
0
    def ADS1256_Read_ADC_Data(self):
        self.ADS1256_WaitDRDY()
        config.digital_write(self.cs_pin, GPIO.LOW)  # cs  0
        config.spi_writebyte([CMD["CMD_RDATA"]])
        # config.delay_ms(10)

        buf = config.spi_readbytes(3)
        config.digital_write(self.cs_pin, GPIO.HIGH)  # cs 1
        read = (buf[0] << 16) & 0xFF0000
        read |= (buf[1] << 8) & 0xFF00
        read |= (buf[2]) & 0xFF
        if read & 0x800000:
            read &= 0xF000000
        return read
Exemple #7
0
 def ADS1256_Read_ADC_Data(self):
     self.ADS1256_WaitDRDY()
     config.digital_write(self.cs_pin, GPIO.LOW)#cs  0
     config.spi_writebyte([CMD['CMD_RDATA']])
     buf = [0,0,0]
     buf[0] = config.spi_readbytes(0xff)
     buf[1] = config.spi_readbytes(0xff)
     buf[2] = config.spi_readbytes(0xff)
     config.digital_write(self.cs_pin, GPIO.HIGH)#cs 1
     read = (buf[0]<<16) & 0xff0000
     read |= (buf[1]<<8) & 0xff00
     read |= (buf[2]) & 0xff
     if (read & 0x800000):
         read &= 0xF000000
     return read
 def ADS1263_Read_ADC2_Data(self):
     read = 0
     config.digital_write(self.cs_pin, GPIO.LOW)  #cs  0
     while (1):
         config.spi_writebyte([ADS1263_CMD['CMD_RDATA2']])
         config.delay_ms(10)
         if (config.spi_readbytes(1)[0] & 0x80 != 0):
             break
     buf = config.spi_readbytes(5)
     config.digital_write(self.cs_pin, GPIO.HIGH)  #cs 1
     read |= (buf[0] << 16) & 0xff0000
     read |= (buf[1] << 8) & 0xff00
     read |= (buf[2]) & 0xff
     CRC = buf[4]
     if (self.ADS1263_CheckSum(read, CRC) != 0):
         print("ADC2 data read error!")
     return read
Exemple #9
0
    def ADS1256_ConfigADC(
        self,
        gain=ADS1256_GAIN_E.get("ADS1256_GAIN_1"),
        drate=ADS1256_DRATE_E.get("ADS1256_30000SPS"),
    ):
        self.ADS1256_WaitDRDY()
        buf = [0, 0, 0, 0, 0, 0, 0, 0]
        buf[0] = (0 << 3) | (1 << 2) | (0 << 1)
        buf[1] = 0x08
        buf[2] = (0 << 5) | (0 << 3) | (gain << 0)
        buf[3] = drate

        config.digital_write(self.cs_pin, GPIO.LOW)  # cs  0
        config.spi_writebyte([CMD["CMD_WREG"] | 0, 0x03])
        config.spi_writebyte(buf)

        config.digital_write(self.cs_pin, GPIO.HIGH)  # cs 1
        config.delay_ms(1)
        return 0
Exemple #10
0
    def ADS1256_ReadData(self):
        read_data = 0

        config.digital_write(self.cs_pin, GPIO.LOW)

        self.ADS1256_SendData(CMD['CMD_RDATA'])
        self.ADS1256_DelayUs(10)

        buf = config.spi_readbytes(0xff)
        # print(buf
        config.digital_write(self.cs_pin, GPIO.HIGH)

        read_data = buf[0] << 16
        read_data |= buf[1] << 8
        read_data |= buf[0]

        if (read_data & 0x800000):
            read_data |= 0xFF000000
        return read_data
Exemple #11
0
 def OLED_Reset(self):
     config.digital_write(config.RST_PIN, GPIO.HIGH)
     config.Driver_Delay_ms(100)
     config.digital_write(config.RST_PIN, GPIO.LOW)
     config.Driver_Delay_ms(100)
     config.digital_write(config.RST_PIN, GPIO.HIGH)
     config.Driver_Delay_ms(100)
 def ADS1263_reset(self):
     config.digital_write(self.rst_pin, GPIO.HIGH)
     config.delay_ms(200)
     config.digital_write(self.rst_pin, GPIO.LOW)
     config.delay_ms(200)
     config.digital_write(self.rst_pin, GPIO.HIGH)
     config.delay_ms(200)
Exemple #13
0
 def OLED_WriteData(self, Data):
     if config.USE_SPI_4W == 1:
         config.digital_write(config.DC_PIN, GPIO.HIGH)
         config.digital_write(config.CS_PIN, GPIO.LOW)
         config.SPI4W_Write_Byte([Data])
         config.digital_write(config.CS_PIN, GPIO.HIGH)
     else:
         config.i2c_writebyte(Data, config.I2C_RAM)
Exemple #14
0
 def OLED_WriteReg(self, Reg):
     if config.USE_SPI_4W == 1:
         config.digital_write(config.DC_PIN, GPIO.LOW)
         config.digital_write(config.CS_PIN, GPIO.LOW)
         config.SPI4W_Write_Byte([Reg])
         config.digital_write(config.CS_PIN, GPIO.HIGH)
     else:
         config.i2c_writebyte(Reg, config.I2C_CMD)
Exemple #15
0
 def ADS1256_WriteReg(self, reg, data):
     config.digital_write(self.cs_pin, GPIO.LOW)  # cs  0
     config.spi_writebyte([CMD["CMD_WREG"] | reg, 0x00, data])
     config.digital_write(self.cs_pin, GPIO.HIGH)  # cs 1
Exemple #16
0
 def ADS1256_WriteCmd(self, reg):
     config.digital_write(self.cs_pin, GPIO.LOW)  # cs  0
     config.spi_writebyte([reg])
     config.digital_write(self.cs_pin, GPIO.HIGH)  # cs 1
 def ADS1263_ReadData(self, reg):
     config.digital_write(self.cs_pin, GPIO.LOW)  #cs  0
     config.spi_writebyte([ADS1263_CMD['CMD_RREG'] | reg, 0x00])
     data = config.spi_readbytes(1)
     config.digital_write(self.cs_pin, GPIO.HIGH)  #cs 1
     return data
 def DAC8532_Write_Data(self, Channel, Data):
     config.digital_write(self.cs_pin, GPIO.LOW)  #cs  0
     config.spi_writebyte([Channel, Data >> 8, Data & 0xff])
     config.digital_write(self.cs_pin, GPIO.HIGH)  #cs  0
Exemple #19
0
    def ADS1256_CfgADC(self, _gain, _drate):
        '''The configuration parameters of ADC, gain and data rate'''
        self.Gain = _gain
        self.DataRate = _drate

        self.ADS1256_WaitDRDY()

        # Storage ads1256 register configuration parameters
        buf = [0x00, 0x00, 0x00, 0x00]
        '''Status register define
        			Bits 7-4 ID3, ID2, ID1, ID0  Factory Programmed Identification Bits (Read Only)

        			Bit 3 ORDER: Data Output Bit Order
        				0 = Most Significant Bit First (default)
        				1 = Least Significant Bit First
        			Input data  is always shifted in most significant byte and bit first. Output data is always shifted out most significant
        			byte first. The ORDER bit only controls the bit order of the output data within the byte.

        			Bit 2 ACAL : Auto-Calibration
        				0 = Auto-Calibration Disabled (default)
        				1 = Auto-Calibration Enabled
        			When Auto-Calibration is enabled, self-calibration begins at the completion of the WREG command that changes
        			the PGA (bits 0-2 of ADCON register), DR (bits 7-0 in the DRATE register) or BUFEN (bit 1 in the STATUS register)
        			values.

        			Bit 1 BUFEN: Analog Input Buffer Enable
        				0 = Buffer Disabled (default)
        				1 = Buffer Enabled

        			Bit 0 DRDY :  Data Ready (Read Only)
        				This bit duplicates the state of the DRDY pin.

        			ACAL=1  enable  calibration
        '''
        # //buf[0] = (0 << 3) | (1 << 2) | (1 << 1);//enable the internal buffer
        buf[0] = (0 << 3) | (1 << 2) | (0 << 1)
        # 0000 0100: MSBF, Auto-cal, Buffer disabled, Data Ready

        # MUX: Input multiplexer Control register (Address 01h)
        # Bits 7-4: Positive Input Channel (0-7 = AIN0-7, 1xxx = AINCOM)
        # Bits 3-0: Negative Input Channel (0-7 = AIN0-7, 1xxx = AINCOM)
        buf[1] = 0x08  # Positive Input Channel: AIN0, Negative Input Channel: AINCOM
        '''
            ADCON: A/D Control Register (Address 02h)
        			Bit 7 Reserved, always 0 (Read Only)
        			Bits 6-5 CLK1, CLK0 : D0/CLKOUT Clock Out Rate Setting
        				00 = Clock Out OFF
        				01 = Clock Out Frequency = fCLKIN (default)
        				10 = Clock Out Frequency = fCLKIN/2
        				11 = Clock Out Frequency = fCLKIN/4
        				When not using CLKOUT, it is recommended that it be turned off. These bits can only be reset using the RESET pin.

        			Bits 4-3 SDCS1, SCDS0: Sensor Detect Current Sources
        				00 = Sensor Detect OFF (default)
        				01 = Sensor Detect Current = 0.5 A
        				10 = Sensor Detect Current = 2 A
        				11 = Sensor Detect Current = 10 A
        				The Sensor Detect Current Sources can be activated to verify  the integrity of an external sensor supplying a signal to the
        				ADS1255/6. A shorted sensor produces a very small signal while an open-circuit sensor produces a very large signal.

        			Bits 2-0 PGA2, PGA1, PGA0: Programmable Gain Amplifier Setting
        				000 = 1 (default)
        				001 = 2
        				010 = 4
        				011 = 8
        				100 = 16
        				101 = 32
        				110 = 64
        				111 = 64
        '''
        buf[2] = (0 << 5) | (0 << 3) | (
            _gain << 0)  # Clock out off, Sensor detect off, gain = 1
        # //ADS1256_WriteReg(REG_ADCON, (0 << 5) | (0 << 2) | (GAIN_1 << 1));	/*choose 1: gain 1 ;input 5V/
        buf[3] = self.DataRate  # ADS1256_DRATE_E[_drate]

        config.digital_write(self.cs_pin, GPIO.LOW)
        self.ADS1256_SendData(
            CMD['CMD_WREG']
            | 0)  # Write register, starting with register address 0
        self.ADS1256_SendData(0x03)
        # number of bytes to be sent: 4 (writing 4 registers), set the number = 4 - 1

        self.ADS1256_SendData(buf[0])  # Set the status register
        self.ADS1256_SendData(buf[1])  # Set the input channel parameters
        self.ADS1256_SendData(buf[2])  # Set the ADCON control register,gain
        self.ADS1256_SendData(buf[3])  # Set the output rate

        print("send data  = ", buf[0], buf[1], buf[2], buf[3])
        config.digital_write(self.cs_pin, GPIO.HIGH)
Exemple #20
0
 def ADS1256_WriteCmd(self, _cmd):
     '''Sending a single byte order'''
     config.digital_write(self.cs_pin, GPIO.LOW)  # cs  0
     self.ADS1256_SendData(_cmd)
     config.digital_write(self.cs_pin, GPIO.HIGH)  # cs  0