def init(self, busno, caseflag): self.busnum = busno self.bus = Bus(busno) self.case = caseflag time.sleep(.001) self.paj7620SelectBank(self.BANK0) self.paj7620SelectBank(self.BANK0) data0 = self.paj7620ReadReg(0, 1)[0] data1 = self.paj7620ReadReg(1, 1)[0] if self.debug: print("data0:", data0, "data1:", data1) if data0 != 0x20: #or data1 <> 0x76: if self.debug: print("Error with sensor") #return 0xff if data0 == 0x20: if self.debug: print("wake-up finish.") for i in range(len(self.initRegisterArray)): self.paj7620WriteReg(self.initRegisterArray[i][0], self.initRegisterArray[i][1]) self.paj7620SelectBank(self.BANK0) self.active = 1 print("Paj7620 initialize register finished.")
def init(self, busno=1, caseflag=1): self.busnum = busno print("set busnum to "+str(self.busnum)) sys.stderr.write("init"+str(busno)) self.bus = Bus(busno) self.case = caseflag self.paj7620SelectBank(self.BANK0) self.paj7620SelectBank(self.BANK0) data0 = self.paj7620ReadReg(0, 1)[0] data1 = self.paj7620ReadReg(1, 1)[0] if self.debug: print("data0:",data0,"data1:",data1) if data0 != 0x20 :#or data1 <> 0x76: if self.debug: sys.stderr.write("Error with sensor") #return 0xff if data0 == 0x20: if self.debug: sys.stderr.write("wake-up finish.") for i in range(len(self.initRegisterArray)): self.paj7620WriteReg(self.initRegisterArray[i][0],self.initRegisterArray[i][1]) self.paj7620SelectBank(self.BANK0) self.active=1 sys.stderr.write("Paj7620 initialize register finished.")
def __init__(self, address=0x03, evt_en=True): super(ButtonTypedI2c, self).__init__(0) self.bus = Bus() self._addr = address # Initialise the I2C button device self.dev_id = 0 self._probe_uid() self._version = 0 self.version() self._size = self.size() self._set_mode(True) self.__last_evt = None self.__last_evt = self.read() self.key_names = _grove_5way_tactile_keys if self._size == 6: self.key_names = _grove_6pos_dip_switch_keys self.__thrd_exit = False self.__thrd = None if not evt_en: return if self.__thrd is None or not self.__thrd.is_alive(): self.__thrd = threading.Thread( \ target = ButtonTypedI2c.__thrd_chk_evt, \ args = (self,)) self.__thrd.setDaemon(True) self.__thrd.start()
def get_data(): i2c_port_number = get_i2c_port_number() sgp30 = seeed_sgp30.grove_sgp30(Bus(i2c_port_number)) co2_eq_ppm = 400 tvoc_ppb = 0 sample_number = 0 sample_array = numpy.zeros((10, 2)) for lp in range(40): data = sgp30.read_measurements() co2_eq_ppm, tvoc_ppb = data.data # print("\r {}: tVOC = {} ppb CO2eq = {} ".format(lp, tvoc_ppb, co2_eq_ppm)) if co2_eq_ppm > 400 or tvoc_ppb > 0: sample_array[sample_number] = (tvoc_ppb, co2_eq_ppm) sample_number += 1 # print(sample_array) if sample_number == 10: # print(sample_array) result = numpy.mean(sample_array, axis=0) # print(result) return result[0], result[1] # VOC, CO2 # break time.sleep(1) return get_data()
def __init__(self, address=0x33): self.bus = Bus() self.addr = address self.refresh_rate = RefreshRate.REFRESH_0_5_HZ self._I2CReadWords(0x2400, eeData) # print(eeData) self._ExtractParameters()
def __init__(self, weather_sensor_address=Config.I2C_WEATHER_SENSOR_ADDRESS, bus=None): self.weather_sensor_address = weather_sensor_address self.bus = Bus(bus) if Config.ENABLE_POWERGAUGE: self.powergauge_module = LC709203F( board.I2C(), address=Config.I2C_POWERGAUGE_ADDRESS)
def __init__(self, bus=None, address=0x3C): self.bus = Bus(bus) self.address = address self.off() self.inverse = False self.mode = self.HORIZONTAL self.clear() self.on()
def __init__(self, bus_num=1, addr=ADC_DEFAULT_IIC_ADDR): ''' Init iic. Args: bus_num(int): the bus number; addr(int): iic address; ''' self.bus = Bus(bus_num) self.addr = addr
def __init__(self, bus=None, address=0x29): self.address = address self.bus = Bus(bus) self.awake = False if self.id not in (0x44, 0x4D): raise ValueError('Not find a Grove I2C Color Sensor V2') self.set_integration_time(24) self.set_gain(4)
def __init__(self, addr=ICM20600_I2C_ADDR1): self._dev = _akicm.rpi_icm20600_alloc() dev_path = "/dev/i2c-{}".format(Bus().bus) icm20600_cfg = ICM20600Cfg(ICM20600_RANGE_2K_DPS, ICM20600_GYRO_RATE_1K_BW_176, ICM20600_GYRO_AVERAGE_1, ICM20600_RANGE_16G, ICM20600_ACC_RATE_1K_BW_420, ICM20600_ACC_AVERAGE_4, ICM20600_ICM_6AXIS_LOW_POWER, 0) _akicm.rpi_icm20600_init(self._dev, dev_path, addr, byref(icm20600_cfg))
def __init__(self): self.bus = Bus() # SGB30 i2c default address is 0x58 self.address = 0x58 self.crc_status = [0, 0] self.CO2eq = 0 self.TVOC = 0 self.CO2eq_raw = 0 self.TVOC_raw = 0 self.CO2eq_baseline = 0 self.TVOC_baseline = 0
def __init__(self, address=0x53, i2c=None): self.address = address self.bus = Bus(i2c) print('ID: {}'.format(self.id)) self.reset() self._timing_control = 0 self._power_control = 0 self._measurement_control = 0 self._sample_rate = 400 self._bandwidth = 200 self._mode = STANDBY_MODE
def __init__(self, address=0x03): self.bus = Bus() self.addr = address self.dev_id = 0 self.val = 0 self.probeDevID() self.get_val() self.send_Byte(0x02) app1 = self.status_read() while 1: self.status_read() time.sleep(1.0) continue
def __init__(self, dht_type, pin=12, bus_num=1): if dht_type != self.DHT_TYPE['DHT11'] and dht_type != self.DHT_TYPE[ 'DHT22'] and dht_type != self.DHT_TYPE['DHT10']: print('ERROR: Please use 11|22|10 as dht type.') exit(1) self.dht_type = dht_type if dht_type == self.DHT_TYPE['DHT10']: self.bus = Bus(bus_num) self.addr = self.DEFAULT_ADDR self._dht10_init() else: self.pin = GPIO(pin, GPIO.OUT) self._last_temp = 0.0 self._last_humi = 0.0
def __init__(self, bus=None, address=0x3C): self.bus = Bus(bus) self.address = address self.off() self.inverse = False self.mode = self.HORIZONTAL self.width = 128 # test self.height = 64 # test self._pages = self.height//8 # test self._buffer = [0]*(self.width*self._pages) # test self.clear() self.on()
def main(): print(\ """ Make sure Grove-VOC-eCO2-Gas-Sensor(SGP30) inserted in one I2C slot of Grove-Base-Hat Baseline operations reference: http://wiki.seeedstudio.com/Grove-VOC_and_eCO2_Gas_Sensor-SGP30/ """) # configuration baseline_conf = "/tmp/SGP30_baseline" # Baseline file used to store baseline compensation parameters. sgp = GroveVOC_eCO2GasSgp30(Bus(), baseline_filename=baseline_conf) sgp.i2c_geral_call() sgp.read_features() serial = sgp.read_serial() print("SGP30 SERIAL: {}".format(serial.raw)) # sgp initialize sgp.init_sgp() # Load baseline if applicable t = file_get_modify_time(baseline_conf) if not t is None and time.time() - t < 7.0 * 24 * 3600: print("Try to set baseline: {}".format(sgp.try_set_baseline())) else: print("*** Baseline unexist or expired") print("First reading: ") print(" DATA = {}".format(sgp.read_measurements().data)) print("SGP30 need at least 15 seconds to warm up") for i in range(20): time.sleep(1) print(".", end="", file=sys.stderr) print() print("Has to run for 12 hours to get really stable data/baseline") start = time.time() while time.time() - start <= 12.0 * 3600: reading = sgp.read_measurements() sgp30_data_display(reading, time.time() - start) time.sleep(0.5) print("\nBaseline stored") sgp.store_baseline()
def __init__(self, bus=I2C_SMBUS, address=I2C_ADDRESS, debug=1, pause=0.8): # assert(bus is not None) # assert(address > 0b000111 and address < 0b1111000) self.address = address self.bus = Bus(bus) self.pause = pause self.debug = debug self.gain = 0 self._bus = bus self._addr = address ambient = None IR = None self._ambient = 0 self._IR = 0 self._LUX = None self._control(_POWER_UP) self._partno_revision()
def __init__(self, acc_addr = BMI088_ACCEL_I2C_ADDR, gyro_addr = BMI088_GYRO_I2C_ADDR): self._dev = _bmi.rpi_bmi088_alloc() dev_path = "/dev/i2c-{}".format(Bus().bus) accel_cfg = BMI08xCfg(BMI08X_ACCEL_PM_ACTIVE, BMI088_ACCEL_RANGE_6G, BMI08X_ACCEL_BW_NORMAL, BMI08X_ACCEL_ODR_100_HZ) gyro_cfg = BMI08xCfg(BMI08X_GYRO_PM_NORMAL, BMI08X_GYRO_RANGE_1000_DPS, BMI08X_GYRO_BW_23_ODR_200_HZ, BMI08X_GYRO_BW_23_ODR_200_HZ) _bmi.rpi_bmi088_init(self._dev, dev_path, acc_addr, gyro_addr, byref(accel_cfg), byref(gyro_cfg))
def __init__(self, acc_addr = BMI088_ACCEL_I2C_ADDR, gyro_addr = BMI088_GYRO_I2C_ADDR): _bmi.rpi_bmi088_alloc.restype = c_char_p self._dev = _bmi.rpi_bmi088_alloc() dev_path = b"/dev/i2c-%d" %(Bus().bus) accel_cfg = BMI08xCfg(BMI08X_ACCEL_PM_ACTIVE, BMI088_ACCEL_RANGE_6G, BMI08X_ACCEL_BW_NORMAL, BMI08X_ACCEL_ODR_100_HZ) gyro_cfg = BMI08xCfg(BMI08X_GYRO_PM_NORMAL, BMI08X_GYRO_RANGE_1000_DPS, BMI08X_GYRO_BW_23_ODR_200_HZ, BMI08X_GYRO_BW_23_ODR_200_HZ) _bmi.rpi_bmi088_init.argtypes = [c_char_p,c_char_p,c_int,c_int,POINTER(BMI08xCfg),POINTER(BMI08xCfg)] _bmi.rpi_bmi088_init(self._dev, dev_path, acc_addr, gyro_addr, byref(accel_cfg), byref(gyro_cfg))
def __init__(self, address=0x71, brightness=BRIGHT_DEFAULT, display_type=FOUR_TUBES): """ Constructor Args: address: I2C address, default is 0x71 brightness: Startup brightness, value between 0 and 15 display_type: Display type, can be one of 0: FOUR_TUBES and 1: TWO_TUBES """ self.address = address self.display_type = display_type self.font = display_font4 if display_type == FOUR_TUBES else display_font2 self.first_dot = False self.second_dot = False self.bus = Bus() self.data = [0] * 4 if self.display_type == FOUR_TUBES else 2 self.bus.write_i2c_block_data(self.address, REG_INIT, []) self.bus.write_i2c_block_data(self.address, DISP_ON, []) self.set_brightness(brightness)
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ''' import time from grove.i2c import Bus from rpi_vl53l0x.vl53l0x import VL53L0X _adapter = Bus() _GroveTofDistanceVL53L0X = VL53L0X(bus=_adapter.bus) _vl53 = GroveTofDistanceVL53L0X def init(): print("Make sure Time-of-Flight-Distance-Sensor-VL53L0X inserted") print(" in one I2C slot of Grove-Base-Hat") _vl53.begin() version = _vl53.get_devver() print("VL53L0X_GetDeviceInfo:") print(" Device Type : %s" % version["type"]) print(" Device Name : %s" % version["name"])
def __init__(self, address): self.bus = Bus() self.addr = address
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ''' import time,sys import RPi.GPIO as GPIO from grove.i2c import Bus # use the bus that matches your raspi version rev = GPIO.RPI_REVISION if rev == 2 or rev == 3: bus = Bus(1) else: bus = Bus(0) class gesture: #Registers and variables for the gesture sensor GES_REACTION_TIME =.500 # You can adjust the reaction time according to the actual circumstance. GES_ENTRY_TIME =.800 # When you want to recognize the Forward/Backward gestures, your gestures' reaction time must less than GES_ENTRY_TIME(0.8s). GES_QUIT_TIME =1.000 BANK0 = 0 BANK1 = 1 PAJ7620_ADDR_BASE =0x00 #REGISTER BANK SELECT
def __init__(self, address=0x0f): #I2C Port - Grove - I2C Motor Driver V1.3 self.I2CAddr = address self.bus = Bus() self.motor = [null, DCMotor(), DCMotor]
def __init__(self, bus_num=1, addr=TOUCH_SENSOR_CY8C_DEFAULT_IIC_ADDR): self.bus = Bus(bus_num) self.addr = addr
def __init__(self, address=0x0f): self.I2CAddr = address self.bus = Bus()
def __init__(self,bus_num=1,addr=ADC_DEFAULT_IIC_ADDR): self.bus=Bus(bus_num) self.addr=addr
import seeed_sgp30 from grove.i2c import Bus sgp30 = seeed_sgp30.grove_sgp30(Bus()) while True: data = sgp30.read_measurements() co2_eq_ppm, tvoc_ppb = data.data print("\r tVOC = {} ppb CO2eq = {} ".format(tvoc_ppb, co2_eq_ppm))
def __init__(self, address=0x45, bus=None): self.address = address # I2C bus self.bus = Bus(bus)
def __init__(self, address=SI114X_ADDR): self.bus = Bus() self.addr = address self._logger = logging.getLogger('grove_si114x') assert self.Begin( ), "Please check if the I2C device insert in I2C of Base Hat"