hx711.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:HX711 作者: gandalf15 项目源码 文件源码
def __init__(self, dout_pin, pd_sck_pin, gain_channel_A=128, select_channel='A'):
        if (isinstance(dout_pin, int) and 
            isinstance(pd_sck_pin, int)):   # just chack of it is integer
            self._pd_sck = pd_sck_pin   # init pd_sck pin number
            self._dout = dout_pin       # init data pin number
        else:
            raise TypeError('dout_pin and pd_sck_pin have to be pin numbers.\nI have got dout_pin: '\
                     + str(dout_pin) + \
                    ' and pd_sck_pin: ' + str(pd_sck_pin) + '\n')

        self._gain_channel_A = 0    # init to 0 
        self._offset_A_128 = 0      # init offset for channel A and gain 128
        self._offset_A_64 = 0       # init offset for channel A and gain 64
        self._offset_B = 0      # init offset for channel B
        self._last_raw_data_A_128 = 0   # init last data to 0 for channel A and gain 128
        self._last_raw_data_A_64 = 0    # init last data to 0 for channelA and gain 64
        self._last_raw_data_B = 0   # init last data to 0 for channel B 
        self._wanted_channel = ''   # init to empty string
        self._current_channel = ''  # init to empty string
        self._scale_ratio_A_128 = 1 # init to 1
        self._scale_ratio_A_64 = 1  # init to 1
        self._scale_ratio_B = 1     # init to 1
        self._debug_mode = False    # init debug mode to False
        self._pstdev_filter = True  # pstdev filter is by default ON

        GPIO.setmode(GPIO.BCM)          # set GPIO pin mode to BCM numbering
        GPIO.setup(self._pd_sck, GPIO.OUT)  # pin _pd_sck is output only
        GPIO.setup(self._dout, GPIO.IN)     # pin _dout is input only
        self.select_channel(select_channel) # call select channel function
        self.set_gain_A(gain_channel_A)     # init gain for channel A

    ############################################################
    # select_channel function evaluates if the desired channel #
    # is valid and then sets the _wanted_channel.          #
    # If returns True then OK                  #
    # INPUTS: channel ('A'|'B')                    #
    # OUTPUTS: BOOL                        #
    ############################################################
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号