def __init__(self, width, height, rst, dc=None, sclk=None, din=None, cs=None, gpio=None, spi=None, i2c_bus=None, i2c_address=SSD1306_I2C_ADDRESS, i2c=None): self._log = logging.getLogger('SSD1306.SSD1306Base') self._spi = None self._i2c = None self.width = width self.height = height self._pages = height / 8 self._buffer = [0] * (width * self._pages) # Default to platform GPIO if not provided. self._gpio = gpio if self._gpio is None: #self._gpio = GPIO.get_platform_gpio() self._gpio = GPIO.pi() # Setup reset pin. self._rst = rst #self._gpio.setup(self._rst, GPIO.OUT) self._gpio.set_mode(self._rst, GPIO.OUTPUT) # Handle hardware SPI if spi is not None: self._log.debug('Using hardware SPI') self._spi = spi self._spi.set_clock_hz(8000000) # Handle software SPI elif sclk is not None and din is not None and cs is not None: self._log.debug('Using software SPI') self._spi = SPI.BitBang(self._gpio, sclk, din, None, cs) # Handle hardware I2C elif i2c is not None: self._log.debug('Using hardware I2C with custom I2C provider.') self._i2c = i2c.get_i2c_device(i2c_address) else: self._log.debug('Using hardware I2C with platform I2C provider.') import I2C if i2c_bus is None: self._i2c = I2C.get_i2c_device(i2c_address) else: self._i2c = I2C.get_i2c_device(i2c_address, busnum=i2c_bus) # Initialize DC pin if using SPI. if self._spi is not None: if dc is None: raise ValueError('DC pin must be provided when using SPI.') self._dc = dc #self._gpio.setup(self._dc, GPIO.OUT) self._gpio.setmode(self._dc, GPIO.OUTPUT)
def __init__(self, address=SI1145_ADDR, busnum=I2C.get_default_bus()): self._logger = logging.getLogger('SI1145') # Create I2C device. self._device = I2C.Device(address, busnum) #reset device self._reset() # Load calibration values. self._load_calibration()
def __init__(self, width, height, rst, dc=None, sclk=None, din=None, cs=None, gpio=None, spi=None, i2c_bus=None, i2c_address=SSD1306_I2C_ADDRESS, i2c=None): self._log = logging.getLogger('Adafruit_SSD1306.SSD1306Base') self._spi = None self._i2c = None self.width = width self.height = height self._pages = height // 8 self._buffer = [0] * (width * self._pages) # Default to platform GPIO if not provided. self._gpio = gpio if self._gpio is None: self._gpio = GPIO.get_platform_gpio() # Setup reset pin. self._rst = rst if not self._rst is None: self._gpio.setup(self._rst, GPIO.OUT) # Handle hardware SPI #if spi is not None: # self._log.debug('Using hardware SPI') # self._spi = spi # self._spi.set_clock_hz(8000000) # Handle software SPI #elif sclk is not None and din is not None and cs is not None: # self._log.debug('Using software SPI') # self._spi = SPI.BitBang(self._gpio, sclk, din, None, cs) # Handle hardware I2C elif i2c is not None: self._log.debug('Using hardware I2C with custom I2C provider.') self._i2c = i2c.get_i2c_device(i2c_address) else: self._log.debug('Using hardware I2C with platform I2C provider.') import I2C if i2c_bus is None: self._i2c = I2C.get_i2c_device(i2c_address) else: self._i2c = I2C.get_i2c_device(i2c_address, busnum=i2c_bus)
def __init__(self, address=0x18, bus=-1, debug=False): self.isDebug = debug self.debug("Initialising LIS3DH") self.i2c = I2C.Device(address, busnum=bus) self.address = address try: val = self.i2c.readU8(self.REG_WHOAMI) if val!=self.DEVICE_ID: raise Exception("Device ID incorrect - expected 0x%X, got 0x%X at address 0x%X" % (self.DEVICE_ID, val, self.address)) self.debug("Successfully connected to LIS3DH at address 0x%X" % (self.address)) except Exception as e: print ("Error establishing connection with LIS3DH") print (e) # Enable all axis self.setAxisStatus(self.AXIS_X, True) self.setAxisStatus(self.AXIS_Y, True) self.setAxisStatus(self.AXIS_Z, True) # Set 400Hz refresh rate self.setDataRate(self.DATARATE_400HZ) self.setHighResolution() self.setBDU() self.setRange(self.RANGE_2G)
def __init__(self): """ Initializes the accelerometer and magnetomter chip in hybrid mode. Both Accel and mangnetometer functionality are available. param none: :returns: none """ self._address = FXOS8700CQR1_ADDRESS self._device = I2C.Device(self._address, 1) #self._device.writeList(CTRL_REG2, [RST_MASK]) #Reset sensor, and wait for reboot to complete time.sleep(1) self.standbyMode() while ((self._device.readU8(CTRL_REG2) & RST_MASK) == True): pass self._device.write8(M_CTRL_REG1, (HYBRID_ACTIVE | M_OSR2_MASK | M_OSR1_MASK | M_OSR0_MASK)) #OSR=max, Hybrid Mode self._device.write8( M_CTRL_REG2, M_HYB_AUTOINC_MASK ) #Enable Hyb Mode Auto Increments in order to read all data self._device.write8( CTRL_REG4, INT_EN_DRDY_MASK) #Enable interrupts for DRDY (TO, Aug 2012) self._device.write8(XYZ_DATA_CFG, FULL_SCALE_2G) #Full Scale of +/-2g self._device.write8( CTRL_REG1, (HYB_ASLP_RATE_25HZ | HYB_DATA_RATE_50HZ) ) #System Output Data Rate of 200Hz (5ms), Sleep Mode Poll Rate of 50Hz (20ms)
def __init__(self, address=0x20, busnum=I2C.get_default_bus(), cols=16, lines=2): """Initialize the character LCD plate. Can optionally specify a separate I2C address or bus number, but the defaults should suffice for most needs. Can also optionally specify the number of columns and lines on the LCD (default is 16x2). """ # Configure MCP23017 device. self._mcp = MCP.MCP23017(address=address, busnum=busnum) # Set LCD R/W pin to low for writing only. self._mcp.setup(LCD_PLATE_RW, GPIO.OUT) self._mcp.output(LCD_PLATE_RW, GPIO.LOW) # Set buttons as inputs with pull-ups enabled. for button in (SELECT, RIGHT, DOWN, UP, LEFT): self._mcp.setup(button, GPIO.IN) self._mcp.pullup(button, True) # Initialize LCD (with no PWM support). super(Adafruit_CharLCDPlate, self).__init__(LCD_PLATE_RS, LCD_PLATE_EN, LCD_PLATE_D4, LCD_PLATE_D5, LCD_PLATE_D6, LCD_PLATE_D7, cols, lines, LCD_PLATE_RED, LCD_PLATE_GREEN, LCD_PLATE_BLUE, enable_pwm=False, gpio=self._mcp)
def __init__(self, address=BME680_ADDR, i2c_ch=I2C_CHANNEL): """Initialise BME680 sensor instance and verify device presence. :param address: i2c address of BME680 :param i2c_device: Optional SMBus-compatible instance for i2c transport """ BME680Data.__init__(self) self.address = address self._device = I2C.Device(address, i2c_ch) self.chip_id = self._get_regs(BME_CONST.CHIP_ID_ADDR, 1) if self.chip_id != BME_CONST.CHIP_ID: raise RuntimeError( 'BME680 Not Found. Invalid CHIP ID: 0x{0:02x}'.format( self.chip_id)) self.soft_reset() self.set_power_mode(BME_CONST.SLEEP_MODE) self._get_calibration_data() self.set_humidity_oversample(BME_CONST.OS_2X) self.set_pressure_oversample(BME_CONST.OS_4X) self.set_temperature_oversample(BME_CONST.OS_8X) self.set_filter(BME_CONST.FILTER_SIZE_3) self.set_gas_status(BME_CONST.ENABLE_GAS_MEAS) self.set_temp_offset(0) self.get_sensor_data() self.set_gas_heater_temperature(320) self.set_gas_heater_duration(150) self.select_gas_heater_profile(0) self.get_sensor_data()
def __init__(self): import I2C #Adjust in order to made address change easier !!! self.i2cConnection = I2C.I2C(0x04) #Check if there is an Arduino if self.i2cConnection.testConnection() is False: print "Something found on I2C, but no Arduino with the good sketch" sys.exit(1)
def __init__(self, address=TC9548A_I2CADDR_DEFAULT, bus=-1, debug=False, i2c=None, **kwargs): self.isDebug = debug self.debug("Initialising TC9548A") # Assume we're using platform's default I2C bus if none is specified. if i2c is None: import I2C self.i2c = I2C # Require repeated start conditions for I2C register reads. Unfortunately # the MPR121 is very sensitive and requires repeated starts to read all # the registers. I2C.require_repeated_start() # Save a reference to the I2C device instance for later communication. self._device = self.i2c.get_i2c_device(address, **kwargs) self.address = address self.activeChannel = None self.SetActiveChannel(0)
def __init__(self, mode=BMP180_STANDARD, address=BMP180_I2CADDR, busnum=I2C.get_default_bus()): self._logger = logging.getLogger('BMP.BMP180') # Check that mode is valid. if mode not in [BMP180_ULTRALOWPOWER, BMP180_STANDARD, BMP180_HIGHRES, BMP180_ULTRAHIGHRES]: raise ValueError('Unexpected mode value {0}. Set mode to one of BMP180_ULTRALOWPOWER, BMP180_STANDARD, BMP180_HIGHRES, or BMP180_ULTRAHIGHRES'.format(mode)) self._mode = mode # Create I2C device. self._device = I2C.Device(address, busnum) # Load calibration values. self._load_calibration()
def __init__(self, pi, bus, device): self.bus = bus self.pi = pi self.h = I2C.I2C(pi, bus, device) self.h.write_byte(self.__PWR_MGMT_1, 0x00) self.h.write_byte(self.__SMPLRT_DIV, 0x07) self.h.write_byte(self.__CONFIG, 0b01000000) self.h.write_byte(self.__GYRO_CONFIG, 0b00000000) # 250dps, self.h.write_byte(self.__ACCEL_CONFIG, 0b00000000) # 2g-scale #self.h.write_byte(self.__ACCEL_CONFIG2, 0b00000000) # low pass self.gyro = Gyro() self.accel = Accel() self.magn = Magn() self.temp = Temp() self.h.write_byte(0x37,0x02) # enable i2c master bypass self.h_magn = I2C.I2C(self.pi, self.bus, self.__MAGN_ADDR)
def __init__(self, address=LIS3DH_I2CADDR_DEFAULT, bus=-1, debug=False, i2c=None, **kwargs): self.isDebug = debug self.debug("Initialising LIS3DH") # Assume we're using platform's default I2C bus if none is specified. if i2c is None: print("is none") import I2C self.i2c = I2C # Require repeated start conditions for I2C register reads. Unfortunately # the MPR121 is very sensitive and requires repeated starts to read all # the registers. I2C.require_repeated_start() else: self.i2c = i2c # Save a reference to the I2C device instance for later communication. print(dir(self.i2c)) self._device = self.i2c.get_i2c_device(address, **kwargs) print(dir(self._device)) #self.i2c = I2C(address, busnum=bus) self.address = address try: val = self._device.readU8(self.REG_WHOAMI) if val!=self.DEVICE_ID: raise Exception("Device ID incorrect - expected 0x%X, got 0x%X at address 0x%X" % (self.DEVICE_ID, val, self.address)) self.debug("Successfully connected to LIS3DH at address 0x%X" % (self.address)) except Exception as e: print "Error establishing connection with LIS3DH" print e # Enable all axis self.setAxisStatus(self.AXIS_X, True) self.setAxisStatus(self.AXIS_Y, True) self.setAxisStatus(self.AXIS_Z, True) # Set 400Hz refresh rate self.setDataRate(self.DATARATE_400HZ) self.setHighResolution() self.setBDU() self.setRange(self.RANGE_2G)
def begin(self, address=MPR121_I2CADDR_DEFAULT, i2c=None, **kwargs): """Initialize communication with the MPR121. Can specify a custom I2C address for the device using the address parameter (defaults to 0x5A). Optional i2c parameter allows specifying a custom I2C bus source (defaults to platform's I2C bus). Returns True if communication with the MPR121 was established, otherwise returns False. """ # Assume we're using platform's default I2C bus if none is specified. if i2c is None: import I2C i2c = I2C # Require repeated start conditions for I2C register reads. Unfortunately # the MPR121 is very sensitive and requires repeated starts to read all # the registers. I2C.require_repeated_start() # Save a reference to the I2C device instance for later communication. self._device = i2c.get_i2c_device(address, **kwargs) return self._reset()
def __init__(self, address=SI1145_ADDR, i2c_ch=I2C_CHANNEL): self._logger = logging.getLogger('SI1145') # Create I2C device. self._device = I2C.Device(address, i2c_ch) # reset device self._reset() # Load calibration values. self._load_calibration()
def __init__(self): """ Configure sensor for capacitive touch. :param none: :returns: none """ self._address = CAP1203ADDR self._logger = logging.getLogger('CAP1203') # Create I2C device. self._device = I2C.Device(self._address, 1) self.Initialize()
def __init__(self, address=0x6a, debug=0, pause=0.8): self.i2c = I2C.get_i2c_device(address) self.address = address dataToWrite = 0 #Start Fresh! dataToWrite |= 0x03 # set at 50hz, bandwidth dataToWrite |= 0x00 # 2g accel range dataToWrite |= 0x10 # 13hz ODR self.i2c.write8( 0X10, dataToWrite ) #writeRegister(LSM6DS3_ACC_GYRO_CTRL2_G, dataToWrite); accel_center_x = self.i2c.readS16(0X28) accel_center_y = self.i2c.readS16(0x2A) accel_center_z = self.i2c.readS16(0x2C)
def __init__(self): """ Initializes I2C bus if not initizalized and configures sensor in active mode. :param none: :returns none: """ self._address = MPL3115A2_ADDRESS self._logger = logging.getLogger('MPL3115A2') # Create I2C device. self._device = I2C.Device(self._address, 1) self.initialize()
def invoke(self, arg, from_tty): argv = gdb.string_to_argv(arg) i2c_addr = int(argv[1], 0) reg_addr = int(argv[2], 0) if len(argv) > 3: reg_size = int(argv[3], 0) else: reg_size = 1 dbg = I2C.I2CDebugger(rv, argv[0]) print("I2C bus {}, device {:#04x}".format(argv[0], i2c_addr)) for reg in range(reg_addr, reg_addr + reg_size): value = dbg.read(i2c_addr, reg) print("{:#04x}: {:#04x}".format(reg, value))
def main(): i2c = I2C.i2cMaster() i2c.init(100,0,0) i2c.Start() i2c.WriteByte(0x46) i2c.WriteByte(0x10) i2c.Stop() time.sleep(0.180) i2c.Start() i2c.WriteByte(0x47) r1 = i2c.ReadAck() r2 = i2c.ReadNack() i2c.Stop() print r1 print r2
def __init__(self, backlight = LCD_ADDR_BACKLIGHT , character = LCD_ADDR_CHARACTER , busnum = I2C.get_default_bus() ): self._logger = logging.getLogger('LCD') # Create I2C device. self._backlight = I2C.Device( backlight, busnum ) self._character = I2C.Device( character, busnum ) #reset device #self._reset() # Load calibration values. #self._load_calibration() self.on() self.clear()
def __init__(self, address=SI1145_ADDR, busnum=I2C.get_default_bus()): self._logger = logging.getLogger('SI1145') self._device = I2C.Device(address, busnum) self._reset() self._load_calibration()
elif (self.range.name == MMA8451_RANGE_4_G): self.divider = 2048 elif (self.range.name == MMA8451_RANGE_2_G): self.divider = 4096 else: print 'problem with range!!!!' sys.exit() def update_3_g(self): x = self.joinbits(MMA8451_REG_OUT_X_MSB, MMA8451_REG_OUT_X_LSB) y = self.joinbits(MMA8451_REG_OUT_Y_MSB, MMA8451_REG_OUT_Y_LSB) z = self.joinbits(MMA8451_REG_OUT_Z_MSB, MMA8451_REG_OUT_Z_LSB) return x, y, z if __name__ == "__main__": BUSNUM = I2C.get_default_bus() print 'BUSNUM = ', BUSNUM print '1' fd = myDevice(MMA8451_DEFAULT_ADDRESS, BUSNUM) print '1a' fd.write8(MMA8451_REG_XYZ_DATA_CFG, 0b01) print '1b' r8 = fd.readS8(MMA8451_REG_XYZ_DATA_CFG) print 'r8 = ', r8 fd.write8(MMA8451_REG_CTRL_REG2, 0x40) print '1c' fd.getRange() # reset print '2' fd.write8(MMA8451_REG_CTRL_REG2, 0x40) time.sleep(.5)
def invoke(self, arg, from_tty): dbg = I2C.I2CDebugger(rv, arg) dbg.scan()
def get_i2c_device(self, address, busnum=None, **kwargs): if busnum is None: busnum = I2C.get_default_bus() return MXedDevice(self, address, busnum, **kwargs)
def __init__(self, accel_address = _ACCEL_ADDRESS, mag_address = _MAG_ADDRESS): self.accel = I2C.I2C(accel_address) self.mag = I2C.I2C(mag_address)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- '''-----------------------------导入模块--------------------------------''' from LKIF_function import * from I2C import * import time from tkinter import * import tkinter.messagebox as messagebox laser=LKIF() i2c=I2C() class La_Mes(object): def __init__(self): self.TVIB=0 self.TVIB_reg=0 self.DIRECT_reg=0x00 self.RING_reg=0x02 self.LSC_reg=0x80 self.SAC2_reg=0x00#需先写Ring self.SAC3_reg=0x40#需先写Ring self.SAC4_reg=0x80#需先写Ring self.SAC5_reg=0xc0#需先写Ring self.i2c_clk=400 self.I2C_Open_Ok=0 def soft_PD(self):
def main(): print("Welcome to the BPS Simulator") print( "Type 'start' to start BeVolt. Otherwise, you can specify the types of data to simulate." ) print(">>", end="") if input() == 'start': # Initial capacity is (2500*14)/(2950*14)=0.847 i.e. 84.7% charged init_capacity_mah = 2500 * config.num_batt_cells_parallel_per_module # Amperes current draw of the electrical system ampere_draw = 30 # Create state of the battery BeVolt = battery.Battery(ampere_draw, config.total_batt_pack_capacity_mah, init_capacity_mah) PLL.PLL_Init() SPI.init(battery=BeVolt) else: BeVolt = None configure() SPI.init(state=state, mode=mode) try: launch_bevolt() except Exception as e: print(repr(e)) logging.basicConfig(filename='debug.log', level=logging.DEBUG) global stdscr global CANbox stdscr = curses.initscr() curses.start_color() curses.noecho() curses.cbreak() #box is for CAN messages CANbox = curses.newwin(7, 21, 12, 80) CANbox.immedok(True) CANbox.box() CANbox.refresh() #Start background thread for timer timerThread = Timer.timer_Thread timerThread.start() spiThread = SPI.spi_thread spiThread.start() while True: try: # Generate all values generate(BeVolt) # Display all values display(BeVolt) time.sleep(1) # one second delay except KeyboardInterrupt: curses.endwin() if BeVolt is not None: print( "\n\rWould you like to change \n\r1. 'wires'\n\r2. 'quit'\n\r3. 'PLL'\n\r4. send a CAN message ('CAN')\n\r5. 'EEPROM'" ) else: print( "\n\rWould you like to change\n\r1. 'config'\n\r2. 'quit'\n\r3. 'PLL'\n\r4. send a CAN message ('CAN')\n\r5. 'EEPROM'" ) print(">>", end="") choice = input() if (choice == 'wires' or choice == '1') and BeVolt is not None: change_wires(BeVolt) stdscr = curses.initscr() curses.start_color() elif (choice == 'config' or choice == '1') and BeVolt is None: configure() stdscr = curses.initscr() elif choice == 'quit' or choice == '2': break elif choice == 'PLL' or choice == '3': print( "Enter the frequency you would like to change the clock to in Hz." ) frequency = int(input()) PLL.Change_Frequency(frequency) elif choice == 'CAN' or choice == '4': print( "Enter the CAN ID for the system you wish to simulate. Leave out '0x'." ) id = input() while (CAN.Invalid_CAN_ID(id) == True): print("Invalid CAN ID. Try again.") id = input() print( "Enter up to 8 bytes of the CAN message that you would like to send, and separate each byte by a ','. Leave out '0x'." ) message = input().split(',') CAN.Send_Message(id, message, len(message)) elif choice == 'EEPROM' or choice == '5': returnErrorCodes = 0 print( "Enter 'all' for all data or 'read' to enter specific address to read." ) print(">>", end="") choiceEEPROM1 = input() print( "Enter 'raw' to read the raw hex values or 'msg' for the translated error messages.", end="\n") print("If invalid response is given, default is raw data.") print(">>", end="") choiceEEPROM2 = input() if choiceEEPROM2 == 'raw': returnErrorCodes = 0 elif choiceEEPROM2 == 'msg': returnErrorCodes = 1 else: print("Invalid entry...", end="\n") print("Defaulted to raw data.") if choiceEEPROM1 == 'all': print(I2C.EEPROM_Dump(returnErrorCodes)) print("Enter to continue simulator:") print(">>", end="") choice = input() elif choiceEEPROM1 == 'read': print( "Enter address to start reading faults from (in hex format)." ) print(">>", end="") EEPROMstartAddress = input() print( "Enter address to stop reading faults from (in hex format)." ) print(">>", end="") EEPROMendAddress = input() EEPROMstartAddress = int(EEPROMstartAddress, 16) EEPROMendAddress = int(EEPROMendAddress, 16) if EEPROMstartAddress >= 0 and EEPROMstartAddress <= maxEEPROMAddress and EEPROMendAddress >= 0 and EEPROMendAddress <= maxEEPROMAddress: print( I2C.I2C_Read(EEPROMstartAddress, EEPROMendAddress, returnErrorCodes)) print("Enter to continue simulator:") choiceEEPROM = input() else: print("Invalid address...", end="\n") print("Enter to continue simulator:") choiceEEPROM = input() else: print("Invalid entry given for 1st choice (all/read)...", end="\n") print("Enter to continue simulator:") choiceEEPROM = input() else: print("That is not a valid option. Continuing simulation...") stdscr = curses.initscr() curses.start_color() except Exception as e: curses.echo() curses.nocbreak() curses.endwin() print("ERROR:", end=" ") print(repr(e), end="\r\n") exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno) print( "If addwstr() returned ERR, make your terminal window bigger.") print("\n\rContinue? (Y/n): ", end="") cont = input() if (cont.lower() == "n" or cont.lower() == "no"): break print("Continuing...") main() curses.echo() curses.nocbreak() curses.endwin() Timer.terminate(True)
def __init__(self, pi, bus, device): self.h = I2C.I2C(pi, bus, device) self.read_cal_data()
log.error("LM75 protocol error") time.sleep(0.1) def getTemperature(self, wait=True): if self.pauseBackground: while wait and self.temperature == None: time.sleep(0.1) else: self.temperature = self.measure() return self.temperature def close(self): #del (self.i2c) pass #--------------------------------------------------------------------------- if __name__ == '__main__': logging.basicConfig() log = logging.getLogger("I2C") log.setLevel(logging.DEBUG) log.info("----- I2C sensors test ---------") i2cBus = I2C.BusI2C('LPT1') sonde = LM75('Room 1', i2cBus) for i in range(10): log.debug("T = %02.03f C" % sonde.getTemperature()) time.sleep(1)
#!/usr/bin/python import time import I2C i2c = I2C.i2cMaster() i2c.init(100,17,27) #i2c speed = 100kbit/s SDA = GPIO17 SCL = GPIO27 def WriteByteData(addr,cmd): i2c.Start() i2c.WriteByte(addr) i2c.WriteByte(cmd) i2c.Stop() def ReadWord(addr): i2c.Start() i2c.WriteByte(addr) high = i2c.ReadAck() low = i2c.ReadNack() i2c.Stop() val = (high << 8)+ low return val def RawToLux(raw): return raw/1.2 def main(): WriteByteData(0x46,0x10) time.sleep(0.024) print RawToLux(ReadWord(0x47))
import I2C import I2C.sensors i2c = I2C.BusI2C('COM2') i2c.bus.setSpeed(2000) # you can set i2c speed adapted to your hardware sonde = I2C.sensors.LM75('Room 1', i2c) print("T = %02.03f C" % sonde.getTemperature())
self.Toggle[no] = self.Toggle[no] + 1 if self.Toggle[no] > max: self.Toggle[no] = 0 value = value2 else: value = value1 return value if __name__ == '__main__': if os.path.isfile("i2c_save.data"): mst_obj = pickle.load( open( "i2c_save.data", "rb" ) ) else: mst_obj = Main_class() # Sync High and low temps tmp102 = I2C.tmp102(0x48) ; tmp102.Low_temp = mst_obj.Low_temp ; tmp102.Hi_temp = mst_obj.Hi_temp mst_obj.temp_out = tmp102.read() parser = argparse.ArgumentParser(description="My list of command line args") group = parser.add_mutually_exclusive_group() group.add_argument("-q", "--quiet", action="store_false" , help="Stops all screen print outs" ) group.add_argument("-v", "--verbose", action="store_true" , help="Give a fuller print out" ) parser.add_argument("-t" , "--thingspeak", action="store_true", help="Sends data to the thinkspeak web site" ) parser.add_argument("--values" , action="store_true" , help="Display the local variables" ) parser.add_argument("--loop" , action="store_true" , help="Run in loop" ) parser.add_argument("--hot" , nargs=1 , type=float , help="Sets Hot " ) parser.add_argument("--cold" , nargs=1 , type=float , help="Sets Cold " ) parser.add_argument("--clear" , action="store_true" , help="Claer the Hi and Lo values" ) args = parser.parse_args()
def __init__(self, addr=ACLMTR_ADDR): self.aclmeter = I2C.get_i2c_device(addr) self.aclmeter.write8(0x2a, 0x09)
def __init__(self, gyro_address=_GYRO_ADDRESS): self.gyro = I2C.I2C(gyro_address)
for i2c import I2C bus = I2C() print bus