示例#1
0
def IMU_Task():
    ''' Accelerometer is initialized on and i2c bus and data is collected with a share'''
    IMU = MPU6050(i2c)
    while True:
        shareIMU.put(IMU.gyro.z)
        #print(shareIMU.get())
        yield None
 def __init__(self, sda_pin, scl_pin):
     from imu import MPU6050
     # See instruction: https://github.com/micropython-IMU/micropython-mpu9x50/blob/master/README_MPU9150.md
     # already modified for esp32(sda=21, scl=22)/wemos D1 mini(sda=4, scl=5)
     self.imu = MPU6050(sda=sda_pin, scl=scl_pin)
     self.measured_angles = None
     utime.sleep_ms(500)  # allow stablization of the module
def window():  
    i2c = machine.I2C(scl=Pin(5), sda=Pin(4), freq=100000)
    mpu6050 = MPU6050(i2c)
    gyro = mpu6050.gyro
    gyro1 = gyro.xyz
    gyro_list = list(gyro1)
    #ersten beiden Werte, Beschleunigung x,y
    #z wird nicht beschleunigt im vorligenden Fall
    gyro_x = round(gyro_list[0], 1)
    gyro_y = round(gyro_list[1],1)
    gyro_values = [gyro_x, gyro_y]
    return(gyro_values)
示例#4
0
        connections.add(conn_handle)
        ble.gap_advertise(None)
        print('[bluetooth] device connected')
    elif event == _IRQ_CENTRAL_DISCONNECT:
        # A central has disconnected from this peripheral.
        conn_handle, addr_type, addr = data
        connections.remove(conn_handle)
        ble.gap_advertise(500000)
        print('[bluetooth] device disconnected')
    else:
        print('[bluetooth] received event {}'.format(event))


# entrypoint
i2c = I2C(0)
imu = MPU6050(i2c)
ble = bluetooth.BLE()
ble.active(True)
ble.irq(bt_irq)
ble.config(gap_name='Bosu')

# configure the services that will be advertised
ACCEL_UUID = bluetooth.UUID('7ED5A5BC-8013-4753-B199-0A364D52E5DE')
ACCEL_CHAR = (
    bluetooth.UUID('F477FD95-41F0-4C73-9093-5DA7DC624DF0'),
    bluetooth.FLAG_READ | bluetooth.FLAG_NOTIFY,
)
ACCEL_SERVICE = (
    ACCEL_UUID,
    (ACCEL_CHAR, ),
)
    a = time.localtime(now+3600)
    return(a)

def do_connect():
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    if not wlan.isconnected():
        print('connecting to ' + ssid)
        wlan.connect(ssid, pwd)
        while not wlan.isconnected():
            pass
    print('network config:', wlan.ifconfig())
    
#Für IMU Sensor    
i2c = machine.I2C(scl=Pin(0), sda=Pin(4), freq=100000)
mpu6050 = MPU6050(i2c)

def start_sampling(d):
    client = MQTTClient(device_name, mqtt_server, mqtt_port)
    mqttConnected=client.connect()
      
    #IMU SENSOR
    accel = mpu6050.accel
    gyro = mpu6050.gyro
    accel1 = accel.xyz
    gyro1 = gyro.xyz
    accel2 = list(accel1)
    gyro2 = list(gyro1)
        
    #DHT22 SENSOR
    d.measure()
示例#6
0
# Copyright (c) 2017-2020 Peter Hinch

# Requires:
# uasyncio V3 (Included in daily builds and release builds later than V1.12).
# From https://github.com/micropython-IMU/micropython-mpu9x50:
# imu.py, mpu6050.py, vector3d.py
# From this repo: deltat.py fusion_async.py
# MPU9150 on X position

from machine import Pin
import uasyncio as asyncio
import gc
from imu import MPU6050
from fusion_async import Fusion  # Using async version

imu = MPU6050('X')  # Attached to 'X' bus, 1 device, disable interrupts


# User coro returns data and determines update rate.
# For 6DOF sensors two 3-tuples (x, y, z) for accel and gyro
async def read_coro():
    await asyncio.sleep_ms(20)  # Plenty of time for mag to be ready
    return imu.accel.xyz, imu.gyro.xyz


fuse = Fusion(read_coro)


async def mem_manage():  # Necessary for long term stability
    while True:
        await asyncio.sleep_ms(100)