当前位置: 首页>>代码示例>>Python>>正文


Python ABEHelpers.get_smbus方法代码示例

本文整理汇总了Python中ABE_helpers.ABEHelpers.get_smbus方法的典型用法代码示例。如果您正苦于以下问题:Python ABEHelpers.get_smbus方法的具体用法?Python ABEHelpers.get_smbus怎么用?Python ABEHelpers.get_smbus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ABE_helpers.ABEHelpers的用法示例。


在下文中一共展示了ABEHelpers.get_smbus方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Init_IOPi

# 需要导入模块: from ABE_helpers import ABEHelpers [as 别名]
# 或者: from ABE_helpers.ABEHelpers import get_smbus [as 别名]
def Init_IOPi(): 
    global sensorbus    
    global buttonbus
    i2c_helper = ABEHelpers()
    i2c_bus = i2c_helper.get_smbus()
    sensorbus = IoPi(i2c_bus, 0x20) 
    # set both rows of pins to input mode
    sensorbus.set_port_direction(0, 0xFF)
    sensorbus.set_port_direction(1, 0xFF)
    #setup interrupts on bus 2, port 1
    buttonbus = IoPi(i2c_bus, 0x21)
    # Set all pins on the bus to be inputs with internal pull-ups enabled.
    buttonbus.set_port_pullups(1, 0xFF)
    buttonbus.set_port_direction(1, 0xFF)
    # Inverting the ports will allow a button connected to ground to register as 1 or on.
    buttonbus.invert_port(1, 0xFF)  # invert port 1 so a button press will register as 1
    # Set the interrupt polarity to be active low and mirroring enabled, so
    # INT A and INT B go low when an interrupt is triggered
    buttonbus.set_interrupt_polarity(0)
    #buttonbus.mirror_interrupts(1)
    # Set the interrupts default value to 0 so it will trigger when any of the pins on the bus change to 1
    buttonbus.set_interrupt_defaults(1, 0x00)
    # Set the interrupt type to be 0xFF for port B so an interrupt is
    # fired when the pin matches the default value
    buttonbus.set_interrupt_type(1, 0xFF)
    # Enable interrupts for all pins on the port
    buttonbus.set_interrupt_on_port(1, 0xFF)
    # reset the interrups on the IO Pi bus 
    buttonbus.reset_interrupts()

    GPIO.setmode(GPIO.BCM)
    # Set up GPIO 23 as an input. The pull-up resistor is disabled as the level shifter will act as a pull-up. 
    GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_OFF)
    # when a falling edge is detected on GPIO pin 23 the function button_pressed will be run  
    GPIO.add_event_detect(23, GPIO.FALLING, callback=hwbutton_pressed) 
开发者ID:zigel,项目名称:piplay,代码行数:37,代码来源:Start1.py

示例2: __init__

# 需要导入模块: from ABE_helpers import ABEHelpers [as 别名]
# 或者: from ABE_helpers.ABEHelpers import get_smbus [as 别名]
 def __init__(self, datasocket=None):
     threading.Thread.__init__(self)
     if datasocket is not None:
         self.datasocket = datasocket
     else:
         self.datasocket = None    
     self.measured_voltage = 0
     self.filament = {}
     port = '/dev/serial/by-id/usb-TTI_CPX400_Series_PSU_C2F952E5-if00'
     self.filament['device'] = CPX.CPX400DPDriver(1, device=port)
     self.filament['voltage'] = 0
     self.filament['current'] = 0
     self.filament['idle_voltage'] = 3
     self.filament['device'].set_current_limit(4)
     self.filament['device'].output_status(True)
     self.bias = {}
     self.bias['device'] = CPX.CPX400DPDriver(2, device=port)
     self.bias['grid_voltage'] = 0
     self.bias['grid_current'] = 0
     self.bias['device'].output_status(True)
     self.looptime = 0
     self.update_setpoint(0.1)
     i2c_helper = ABEHelpers()
     bus = i2c_helper.get_smbus()
     self.adc = DeltaSigma(bus, 0x68, 0x69, 18)
     self.adc.set_pga(1)  # This shold be 8, but amplifier seems broken on the available device
     self.running = True
     self.wanted_voltage = 0
     self.emission_current = 999
     self.pid = pid.PID(2, 0.03, 0, 9)
     self.pid.update_setpoint(self.setpoint)
开发者ID:neilanderson,项目名称:PyExpLabSys,代码行数:33,代码来源:emission_control.py

示例3: __init__

# 需要导入模块: from ABE_helpers import ABEHelpers [as 别名]
# 或者: from ABE_helpers.ABEHelpers import get_smbus [as 别名]
class dld_solar_window:
    _channel = 0
    _report_period = 5

    _thread = None
    _stop_requested = False

    _srv_ip_addr = "1.2.2.201"
    _srv_port = 8200

    def __init__(self, channel=0, report_period=the_report_period):
        self._channel = channel
        self._report_period = report_period
        self._i2c_helper = ABEHelpers()
        self._bus = self._i2c_helper.get_smbus()
        self._adc = ADCPi(self._bus, 0x68, 0x69, 12)

    def Start(self):
        self._stop_requested = False
        self._thread = threading.Thread(target=self.SamplingThread)
        self._thread.start()
        print("sampling thread initialized")

    def SamplingThread(self):
        print("sampling thread started")

        mc_socket = None

        time_last_report = time.time()
        connected = False
        while self._stop_requested != True:
            if connected == False:
                try:
                    # time.sleep(5)
                    mc_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                    mc_socket.connect((self._srv_ip_addr, self._srv_port))
                    print("connected")
                    time.sleep(1)
                except Exception as e:
                    connected = False
                    continue

            time_now = time.time()
            voltage = self._adc.read_voltage(self._channel)

            try:
                mc_socket.send("Vout:%02f\n" % (voltage))
                print("Vout:%02f\n" % (voltage))
            except Exception as e:
                connected = False
            time.sleep(5.0)

    def Stop(self):
        if self._thread == None:
            return
        self._stop_requested = True
        if self._thread.isAlive():
            self._thread.join()
        self._thread = None
开发者ID:intelmakers,项目名称:Project--Energy-Friendly-House,代码行数:61,代码来源:dld_solar_window.py

示例4: __init__

# 需要导入模块: from ABE_helpers import ABEHelpers [as 别名]
# 或者: from ABE_helpers.ABEHelpers import get_smbus [as 别名]
    def __init__(self, room, direction):
	self.room = room
	self.direction = direction
	self.channel = self.channelRoomMappings[direction][room]
        
	i2c_helper = ABEHelpers()
	bus = i2c_helper.get_smbus()
	self.adc = DeltaSigma(bus, 0x68, 0x69, 18)
开发者ID:beaf-o,项目名称:pi-blinds,代码行数:10,代码来源:voltage.py

示例5: __init__

# 需要导入模块: from ABE_helpers import ABEHelpers [as 别名]
# 或者: from ABE_helpers.ABEHelpers import get_smbus [as 别名]
	def __init__(self):

		i2c_helper = ABEHelpers()
		i2c_bus = i2c_helper.get_smbus()
		multibus = [ IoPi(i2c_bus, 0x20), IoPi(i2c_bus, 0x21)]

		self.tenminute = Digit(multibus, 1, True)
		self.minute = Digit(multibus, 8, True)
		self.tensecond = Digit(multibus, 17, True)
		self.second = Digit(multibus, 24, True)
开发者ID:briankoppelaar,项目名称:digits,代码行数:12,代码来源:timeclock.py

示例6: __init__

# 需要导入模块: from ABE_helpers import ABEHelpers [as 别名]
# 或者: from ABE_helpers.ABEHelpers import get_smbus [as 别名]
   def __init__ (self, ph7, ph4, ds):
      self.ph7 = ph7
      self.ph4 = ph4
      self.ds  = ds

      i2c_helper = ABEHelpers()
      bus = i2c_helper.get_smbus()
      self.adc = ADCPi(bus, self.i2c1, self.i2c2, self.bitrate)

      self.calcpHSlope()
开发者ID:3epnm,项目名称:phController,代码行数:12,代码来源:PH.py

示例7: __init__

# 需要导入模块: from ABE_helpers import ABEHelpers [as 别名]
# 或者: from ABE_helpers.ABEHelpers import get_smbus [as 别名]
    def __init__(self):

        i2c_helper = ABEHelpers()
        i2c_bus = i2c_helper.get_smbus()
        multibus = [IoPi(i2c_bus, 0x22), IoPi(i2c_bus, 0x23)]

        self.tenhome = Digit(multibus, 1, True)
        self.home = Digit(multibus, 8, True)
        self.tenguest = Digit(multibus, 17, True)
        self.guest = Digit(multibus, 24, True)
开发者ID:briankoppelaar,项目名称:digits,代码行数:12,代码来源:scoreboard.py

示例8: setup_adc

# 需要导入模块: from ABE_helpers import ABEHelpers [as 别名]
# 或者: from ABE_helpers.ABEHelpers import get_smbus [as 别名]
 def setup_adc(self, adr1, adr2, accu):
     print("setting up adc with accuracy <"
           + str(accu) + "> on addresses <"
           + str(adr1) + "> and <"
           + str(adr2) + ">")
     i2c_helper = ABEHelpers()
     bus = i2c_helper.get_smbus()
     adc = ADCPi(bus, adr1, adr2, accu)
     
     return adc
开发者ID:ManInAGarden,项目名称:PiADCMeasure,代码行数:12,代码来源:mainwindow.py

示例9: __init__

# 需要导入模块: from ABE_helpers import ABEHelpers [as 别名]
# 或者: from ABE_helpers.ABEHelpers import get_smbus [as 别名]
	def __init__(self, configfilename):

		config = ConfigParser.RawConfigParser()
		config.read(configfilename)
		inverted_logic = config.getboolean(self.__class__.__name__, 'inverted_logic')

		i2c_helper = ABEHelpers()
		i2c_bus = i2c_helper.get_smbus()
		multibus = [ IoPi(i2c_bus, 0x20), IoPi(i2c_bus, 0x21)]

		self.tendigit = Digit(multibus, 1, inverted_logic)
		self.digit = Digit(multibus, 8, inverted_logic)
开发者ID:tdrimmelen,项目名称:digits,代码行数:14,代码来源:shotclock.py

示例10: init_servos

# 需要导入模块: from ABE_helpers import ABEHelpers [as 别名]
# 或者: from ABE_helpers.ABEHelpers import get_smbus [as 别名]
def init_servos(address):
    i2c_helper = ABEHelpers()
    bus = i2c_helper.get_smbus()
    pwm = PWM(bus, address)
    pwm.set_pwm_freq(60)
    pwm.output_enable()

    # cycle the arms on channels 0, 2, 4
    print("cycling through all valid positions")
    for x in (175, 300, 425, 550):
        pwm.set_pwm(0, 0, x)
        sleep(1)
        pwm.set_pwm(2, 0, x)
        sleep(1)
        pwm.set_pwm(4, 0, x)
        sleep(2)
    return pwm
开发者ID:joshjh,项目名称:steelie-clock,代码行数:19,代码来源:move_arm.py

示例11: main

# 需要导入模块: from ABE_helpers import ABEHelpers [as 别名]
# 或者: from ABE_helpers.ABEHelpers import get_smbus [as 别名]
def main():
    """ Main function """
    logging.basicConfig(filename="logger.txt", level=logging.ERROR)
    logging.basicConfig(level=logging.ERROR)

    i2c_helper = ABEHelpers()
    bus = i2c_helper.get_smbus()
    adc_instance = DeltaSigma(bus, 0x68, 0x69, 18)

    tempreader = TemperatureReader(adc_instance)
    tempreader.daemon = True
    tempreader.start()

    codenames = ["cooling_water_hot", "cooling_water_cold"]
    loggers = {}
    for i in range(0, 2):
        loggers[codenames[i]] = ValueLogger(tempreader, comp_val=0.5, channel=i)
        loggers[codenames[i]].start()
    socket = DateDataPullSocket("hall_cooling_water_temp", codenames, timeouts=2.0)
    socket.start()

    live_socket = LiveSocket("hall_waterpressure", codenames)
    live_socket.start()

    db_logger = ContinuousDataSaver(
        continuous_data_table="dateplots_hall",
        username=credentials.user,
        password=credentials.passwd,
        measurement_codenames=codenames,
    )
    db_logger.start()

    time.sleep(5)

    while tempreader.is_alive():
        time.sleep(0.25)
        for name in codenames:
            value = loggers[name].read_value()
            socket.set_point_now(name, value)
            live_socket.set_point_now(name, value)
            if loggers[name].read_trigged():
                print(value)
                db_logger.save_point_now(name, value)
                loggers[name].clear_trigged()
开发者ID:CINF,项目名称:PyExpLabSys,代码行数:46,代码来源:voltage_logger.py

示例12: __init__

# 需要导入模块: from ABE_helpers import ABEHelpers [as 别名]
# 或者: from ABE_helpers.ABEHelpers import get_smbus [as 别名]
class line_test:
    def __init__(self):
        """ Standard Constructor """
        logging.info("Three Point Turn constructor")
        # set up ADC
        self.i2c_helper = ABEHelpers()
        self.bus = self.i2c_helper.get_smbus()
        self.adc = ADCPi(self.bus, 0x6a, 0x6b, 12)

        self.killed = False

    def run(self, line_sensor=None):
        logging.info("Started Looking")

        while not self.killed:
            # If we have a line sensor, check it here. Bail if necesary
            #if line_sensor and (self.adc.read_voltage(line_sensor) > self.red_min):
            #    logging.info("Line Detected")
            if line_sensor:
                logging.info( str(self.adc.read_voltage(line_sensor)) )
            time.sleep(0.05)
开发者ID:hackhitchin,项目名称:piwars,代码行数:23,代码来源:line_test.py

示例13: main

# 需要导入模块: from ABE_helpers import ABEHelpers [as 别名]
# 或者: from ABE_helpers.ABEHelpers import get_smbus [as 别名]
def main():
    monitor = PeakMonitor(SINK_NAME, METER_RATE)
    i2c_helper = ABEHelpers()
    bus = i2c_helper.get_smbus()

    pwm = PWM(bus, 0x40)

    # Set PWM frequency to 60 Hz
    pwm.set_pwm_freq(60)
    pwm.output_enable()
    
    for sample in monitor:
        sample = sample >> DISPLAY_SCALE
        step = ((4000 - 0) / 100.0)
        sample = int(step * sample)

        print ' %3d' % sample

        sys.stdout.flush()

	pwm.set_pwm(8, 0, (randint(0,1) * sample))
	pwm.set_pwm(7, 0, (randint(0,1) * sample))
	pwm.set_pwm(6, 0, (randint(0,1) * sample))
开发者ID:ajaskaFIN,项目名称:iot-hackday-puhuvapaa,代码行数:25,代码来源:peak_detect.py

示例14: main

# 需要导入模块: from ABE_helpers import ABEHelpers [as 别名]
# 或者: from ABE_helpers.ABEHelpers import get_smbus [as 别名]
def main():

    i2c_helper = ABEHelpers()
    bus = i2c_helper.get_smbus()
    adc = ADCPi(bus, 0x68, 0x69, 18)

    if not os.path.isfile(db_name):
        createdb()
 
    while (True):
        temp = 0
        light = 0
        moisture = 0

        for x in range(0, 60):
            # read from adc channels and write to the log file
            temp = temp + (adc.read_voltage(1) - 0.5) * 100
            light = light + adc.read_voltage(2)
            moisture = moisture + adc.read_voltage(3)
            time.sleep(0.4)

        # Average temp
        temp = temp / 60
        # Correct temp
        temp = temp - 1.2
	
        # Average light
        light = light / 60

        # Average moisture
        moisture =  moisture / 60

        print("temp,light,moisture")
        print(temp)
        print(light)
        print(moisture)
        writetodb("%02f" % temp, "%02f" % light, "%02f" % moisture)
开发者ID:naffots,项目名称:ADCPi_SQL,代码行数:39,代码来源:palm_tree_measurement.py

示例15: __init__

# 需要导入模块: from ABE_helpers import ABEHelpers [as 别名]
# 或者: from ABE_helpers.ABEHelpers import get_smbus [as 别名]
class Proximity:
    def __init__(self, drive):
        """ Standard Constructor """
        logging.info("Straight Line Speed constructor")
        # set up ADC
        self.i2c_helper = ABEHelpers()
        self.bus = self.i2c_helper.get_smbus()
        self.adc = ADCPi(self.bus, 0x6a, 0x6b, 12)

        # define fixed values
        self.stopped = 0
        self.full_forward = 0.5
        self.slow_forward = 0.1
        self.full_reverse = -0.5
        self.slow_reverse = -0.1

        self.left_steering = -0.25
        self.right_steering = 0.25
        self.straight = 0
        self.distance_sensor = 1

        # Voltage value we are aiming for (2 was close, 0.5 was further away)
        self.nominal_voltage = 0.5
        self.min_dist_voltage = 2.0
        self.max_dist_voltage = 0.4

        # Drivetrain is passed in
        self.drive = drive
        self.killed = False

    def stop(self):
        """Simple method to stop the challenge"""
        self.killed = True

    def run(self):
        """ Main call to run the three point turn script """
        # Drive forward for a set number of seconds keeping distance equal
        logging.info("forward to turning point")
        self.move_segment( total_timeout=10.0 )

        # Final set motors to neutral to stop
        self.drive.set_neutral()
        self.stop()

    def move_segment( self, total_timeout=0 ):
        logging.info("move_segment called with arguments: {0}".format(locals()))
        # Note Line_sensor=0 if no line sensor exit required
        # calculate timeout times
        now = datetime.now()
        end_timeout = now + timedelta(seconds=total_timeout)

        # Throttle is static and does not change
        throttle = self.full_forward
        # Steering starts at zero (straight forward)
        steering = self.straight

        while not self.killed and (datetime.now() < end_timeout):
            # If we have a line sensor, check it here. Bail if necesary
            if distance_sensor:
                voltage = self.adc.read_voltage(distance_sensor)
                voltage_diff = voltage - self.nominal_voltage
                steering = interp(
                        voltage_diff,
                        [self.min_dist_voltage, self.max_dist_voltage]
                        [self.left_steering, self.right_steering],
                    )
                )

            # Had to invert throttle and steering channels to match RC mode
            logging.info("mixing channels: {0} : {1}".format(throttle, steering))
            self.drive.mix_channels_and_assign(steering, throttle)
            time.sleep(0.05)

        logging.info("Finished manoeuvre")
开发者ID:markmellors,项目名称:piwars,代码行数:76,代码来源:proximity.py


注:本文中的ABE_helpers.ABEHelpers.get_smbus方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。