def __init__(self, port): self.i2c = i2c_bus.get(i2c_bus.M_BUS) self._available() self._available() self.port = port self._position = 0 self.updateTime = 0
def __init__(self, i2c=None): if i2c is None: self.i2c = i2c_bus.get(i2c_bus.M_BUS) else: self.i2c = i2c self.imu = MPU6050(self.i2c) if self.i2c.is_ready(M5GO_WHEEL_ADDR) or self.i2c.is_ready( M5GO_WHEEL_ADDR): pass else: raise ImportError("Bala Motor not connect") self.id = self.imu.whoami # self.set_motor(0, 0) self.imu.setGyroOffsets(-2.71, -0.01, -0.04) self.loop_interval = time.ticks_us() self.dt = time.ticks_us() self.angleX = 0 self.angleX_offset = 0 self.last_angle = 0.0 self.last_wheel = 0.0 self.in_speed0 = 0 self.in_speed1 = 0 self.left = 0 self.right = 0 self.K1 = 40 self.K2 = 40 self.K3 = 6.5 self.K4 = 5.5 self.K5 = 0 self.enc_filter = 0.90
def __init__(self, addr=0x08): self.i2c = i2c_bus.get(i2c_bus.M_BUS) self.addr = addr self._available() self.press_status = 0x00 self.release_status = 0x00 self._timer = timEx.addTimer(100, timEx.PERIODIC, self._monitor) self.status_hold = 0xff
def __init__(self, addr = 0x5e): self._addr = addr self.i2c = i2c_bus.get(i2c_bus.M_BUS) self._available() self.encode_value = 0 self.press = 0 self.time = 0 self.dir = 0
def __init__(self, i2c=None, i2cAddress=_I2C_ADDRESS_MAG3110): if i2c: self.i2c = i2c else: i2c = i2c_bus.get(i2c_bus.M_BUS) self.i2cAddress = i2cAddress self.__initialSetup()
def __init__(self, port): from dht12 import DHT12 from bmp280 import BMP280 self.i2c = i2c_bus.get(port) self._available() self.dht12 = DHT12(self.i2c) self.bmp280 = BMP280(self.i2c) self.time = 0 self.data = None
def __init__(self, addr=0x70, i2c=None): if i2c == None: self.i2c = i2c_bus.get(i2c_bus.PORTA) else: self.i2c = i2c self.addr = addr self._available() self.mode = 'absolute' # absolute self.last_speed = 300
def __init__(self, port, address=0x29): self.i2c = i2c_bus.get(port) self.addr = address self._active = False self.integration_time = 0 self.time = 0 self._raw = (0, 0, 0, 0) self._available() self.setIntegrationTime(_INT_154MS) self.setGains(0x02) self.enable()
def __init__(self, port=PORTA): global class_map from dht12 import DHT12 from bmp280 import BMP280 self.i2c = i2c_bus.get(i2c_bus.M_BUS) if class_map['dht12'] == None: class_map['dht12'] = DHT12(self.i2c) if class_map['bmp280'] == None: class_map['bmp280'] = BMP280(self.i2c) self.dht12 = class_map['dht12'] self.bmp280 = class_map['bmp280'] self.time = 0 self.data = None
def __init__(self, port): self.i2c = i2c_bus.get(port) self._available() self.offset = 0.25 self.mode = MODE_CONTIN self.rate = RATE_15 self.gain = GAIN_ONE self.mini_code = {RATE_15: 16, RATE_30: 15, RATE_60: 14, RATE_240: 12} self.gain_code = { GAIN_ONE: 1, GAIN_TWO: 2, GAIN_FOUR: 4, GAIN_EIGHT: 8 }
def __init__(self, i2c=None, address=0x68, accel_fs=ACCEL_FS_SEL_2G, gyro_fs=GYRO_FS_SEL_500DPS, accel_sf=SF_G, gyro_sf=SF_DEG_S): if i2c: self.i2c = i2c else: import i2c_bus self.i2c = i2c_bus.get(i2c_bus.M_BUS) # from machine import I2C # self.i2c = I2C(sda=21, scl=22, speed=400000) self.address = address # if 0x71 != self.whoami: # raise RuntimeError("MPU6500 not found in I2C bus.") # Init self._register_char(_SMPLRT_DIV, 0x00) self._register_char(_CONFIG, 0x00) self._accel_so = self._accel_fs(accel_fs) self._gyro_so = self._gyro_fs(gyro_fs) self._accel_sf = accel_sf self._gyro_sf = gyro_sf self._register_char(_PWR_MGMT_1, 0x01) # Enable I2C bypass to access for MPU9250 magnetometer access. # char = self._register_char(_INT_PIN_CFG) # char &= ~_I2C_BYPASS_MASK # clear I2C bits # char |= _I2C_BYPASS_EN # self._register_char(_INT_PIN_CFG, char) self.preInterval = time.ticks_us() self.accCoef = 0.02 self.gyroCoef = 0.98 self.angleGyroX = 0 self.angleGyroY = 0 self.angleGyroZ = 0 self.angleX = 0 self.angleZ = 0 self.angleY = 0 self.gyroXoffset = 0 self.gyroYoffset = 0 self.gyroZoffset = 0
def __init__( self, i2c=None, address=0x68, accel_fs=ACCEL_FS_SEL_2G, gyro_fs=GYRO_FS_SEL_500DPS, accel_sf=SF_G, gyro_sf=SF_DEG_S ): if i2c: self.i2c = i2c else: import i2c_bus self.i2c = i2c_bus.get(i2c_bus.M_BUS) self.address = address if self.i2c.is_ready(address) or self.i2c.is_ready(address): pass else: raise RuntimeError("imu not found") # Init self._register_char(_SMPLRT_DIV, 0x00) self._register_char(_CONFIG, 0x00) self._accel_so = self._accel_fs(accel_fs) self._gyro_so = self._gyro_fs(gyro_fs) self._accel_sf = accel_sf self._gyro_sf = gyro_sf self._register_char(_PWR_MGMT_1, 0x01) # Enable I2C bypass to access for MPU9250 magnetometer access. # char = self._register_char(_INT_PIN_CFG) # char &= ~_I2C_BYPASS_MASK # clear I2C bits # char |= _I2C_BYPASS_EN # self._register_char(_INT_PIN_CFG, char) self.preInterval = time.ticks_us() self.accCoef = 0.02 self.gyroCoef = 0.98 self.angleGyroX = 0 self.angleGyroY = 0 self.angleGyroZ = 0 self.angleX = 0 self.angleZ = 0 self.angleY = 0 self.gyroXoffset = 0 self.gyroYoffset = 0 self.gyroZoffset = 0
def __init__(self, port): self.i2c = i2c_bus.get(i2c_bus.M_BUS) self._available() self.port = port - 1 self.prev_enc_val = 0 self.interval = 0 self.sample_interval = 10 self.enc_zero = 0 self.input_value = 0 self.speed_pid = PID(p=50, i=0, d=60) self.speed_point = None self.angle_pid = PID(p=8, i=0, d=30) self.angle_point = None self.angle_max_pwm = 255 self.encode_zero = 0 self.encode_clear()
def __init__(self, port=i2c_bus.PORTA): self._addr = 0x5a self._i2c = i2c_bus.get(port)
def __init__(self, addr=0x28): self.addr = addr self.i2c = i2c_bus.get(i2c_bus.M_BUS) self._available() self.init()
def __init__(self, port): self.i2c = i2c_bus.get(port) self._available() self.config = Ext_io.ALL_INPUT self.setPortMode(self.config)
def __init__(self, addr=0x70): # self.i2c = # self.i2c = I2C(id=0, sda=a[0], scl=a[1]) self.i2c = i2c_bus.get(i2c_bus.M_BUS) self.addr = addr self.speed = 500
def __init__(self, port, addr=0x60): self.i2c = i2c_bus.get(port) self.addr = addr self._available()
def __init__(self, min_us=500, max_us=2500): self.i2c = i2c_bus.get(i2c_bus.PORTA) self._available() self.min_us = min_us self.max_us = max_us
label1.setText('Hi, SmartDevice MQTT start') lcd.font(lcd.FONT_Comic) m5mqtt.publish(str('test_ESP32_smartdevice'), str('smart device is now online')) #----------get time #rtc = machine.RTC() #rtc.ntp_sync(server="1.europe.pool.ntp.org", tz="CET-1CEST") #rtc.ntp_sync(server="hr.pool.ntp.org", tz="CET-1CEST") #rtc.synced() #env0 = unit.get(unit.ENV, unit.PORTA) try: env0 = unit.get(unit.ENV, unit.PORTA) label3.setText("Sensor: OK") except: i2c = i2c_bus.get(i2c_bus.M_BUS) label3.setText("Sensor: N.A.") ENV_insert = 1 while ENV_insert: if i2c.is_ready(IIC_Address_ENV): ENV_insert = 0 env0 = unit.get(unit.ENV, unit.PORTA) label3.setText("Sensor: OK!") wait_ms(200) pass # mpu9250 imu0 = imu.IMU() if get_bmm150_status(): wait_ms(200)
def __init__(self, port): self.i2c = i2c_bus.get(port) self._available()
def __init__(self): self.addr = 0x34 self.i2c = i2c_bus.get(i2c_bus.M_BUS)
from lib import mpu6050 import i2c_bus SH200Q_ADDR = 0x6c MPU6050_ADDR = 0x68 imu_i2c = i2c_bus.get(i2c_bus.M_BUS) IMU = mpu6050.MPU6050 if imu_i2c.is_ready(MPU6050_ADDR) or imu_i2c.is_ready(MPU6050_ADDR): IMU = mpu6050.MPU6050
from m5stack import * from m5ui import * from mpu6050 import MPU6050 from mag3110 import MAG3110 import i2c_bus clear_bg(0x111111) itwoc = i2c_bus.get(i2c_bus.M_BUS) mag = MAG3110(itwoc) imu = MPU6050(itwoc) btnA = M5Button(name='ButtonA', text='ButtonA', visibility=False) btnB = M5Button(name='ButtonB', text='ButtonB', visibility=False) btnC = M5Button(name='ButtonC', text='ButtonC', visibility=False) labelx = M5TextBox(40, 30, "Text", lcd.FONT_Default, 0xFFFFFF) labely = M5TextBox(40, 50, "Text", lcd.FONT_Default, 0xFFFFFF) labelz = M5TextBox(40, 70, "Text", lcd.FONT_Default, 0xFFFFFF) labelax = M5TextBox(40, 90, "Text", lcd.FONT_Default, 0xFFFFFF) labelay = M5TextBox(40, 110, "Text", lcd.FONT_Default, 0xFFFFFF) labelaz = M5TextBox(40, 130, "Text", lcd.FONT_Default, 0xFFFFFF) labelgx = M5TextBox(40, 150, "Text", lcd.FONT_Default, 0xFFFFFF) labelgy = M5TextBox(40, 170, "Text", lcd.FONT_Default, 0xFFFFFF) labelgz = M5TextBox(40, 190, "Text", lcd.FONT_Default, 0xFFFFFF) labelmg = M5TextBox(40, 210, "Text", lcd.FONT_Default, 0xFFFFFF) lpitch = M5TextBox(5, 30, "pitch", lcd.FONT_Default, 0xFFFFFF) lroll = M5TextBox(5, 50, "roll", lcd.FONT_Default, 0xFFFFFF) lyaw = M5TextBox(5, 70, "yaw", lcd.FONT_Default, 0xFFFFFF) lax = M5TextBox(5, 90, "ax", lcd.FONT_Default, 0xFFFFFF) lay = M5TextBox(5, 110, "ay", lcd.FONT_Default, 0xFFFFFF)
import math import machine import neopixel import urequests import _thread import ntptime import time import wifiCfg # 変数の定義 Library_ServoDefaultValue = [1000, 630, 300, 600, 240, 600, 1000, 720] Library_MotionNumberCache = [] Library_TransitionTimeArrayCache = [] Library_SearvoArrayCache = [] Library_ServoBeforeValue = [0] * 8 Library_i2c = i2c_bus.get(i2c_bus.M_BUS) Library_np = neopixel.NeoPixel(machine.Pin(26), 2) # グローバル変数の定義 Library_ServoCurrentValue = [0] * 8 Library_CurrentLEDValue = [(0, 0, 0), (0, 0, 0)] Library_MotionNumberBefore = -1 Library_MotionNumberFlag = -1 Library_ThreadFlag = False Library_ThreadPlayFlag = False Library_PlayFlag = False Library_ServoErrorFlag = False Library_MotionSpeed = 100 for i in range(8): Library_ServoCurrentValue[i] = Library_ServoDefaultValue[i]
def __init__(self, port=PORTA): from dht12 import DHT12 from bmp280 import BMP280 self.i2c = i2c_bus.get(i2c_bus.M_BUS) self.dht12 = DHT12(self.i2c) self.bmp280 = BMP280(self.i2c)
def __init__(self, addr=0x5e): self.i2c = i2c_bus.get(i2c_bus.M_BUS) self._addr = addr self._available() self.time = 0 self.value = None
def __init__(self, port): self.i2c = i2c_bus.get(i2c_bus.M_BUS) self.port = port self._position = 0
lcd.setBrightness(25) Sleep_EN = 0 Lum_value_tmp = 0 Lum_value_max = 0 Lum_value_min = 0 LCD_EN = 10 setScreenColor(0x111111) lcd.image(lcd.CENTER, lcd.CENTER, 'res/ghost_in_the_shell.jpg') time.sleep(0.6) setScreenColor(0x111111) title = M5Title(title=" ESP32 IIC debug, BH1750 Lux", x=3, fgcolor=0xEFEFDF, bgcolor=0x1F1F1F) #IIC init a = i2c_bus.get(i2c_bus.PORTA) label1 = M5TextBox(10, 40, "Text", lcd.FONT_DejaVu24, 0xFFFFAA, rotate=0) label_iic = M5TextBox(10, 140, "Lum:", lcd.FONT_Comic, 0xEFEFDF, rotate=0) lcd.image(lcd.CENTER + 60, lcd.CENTER + 40, 'res/light.jpg') label_max = M5TextBox(190, 140, "Lum.Max:", lcd.FONT_Default, 0xFFCF1F, rotate=0) label_min = M5TextBox(190, 160, "Lum.Min:", lcd.FONT_Default, 0xAFEFDF, rotate=0)
def __init__(self, addr=0x08): self.i2c = i2c_bus.get(i2c_bus.M_BUS) self.addr = addr self._available() self._str = '' self.key = b''