def test(duration=0):
    if duration:
        print("Test LCD display for {:3d} seconds".format(duration))
    objSched = Sched()
    lcd0 = LCD(PINLIST, objSched, cols=16)
    objSched.add_thread(lcd_thread(lcd0))
    if duration:
        objSched.add_thread(stop(duration, objSched))
    objSched.run()
Beispiel #2
0
def test():
    objSched = Sched()
    lcd0 = LCD(PINLIST, objSched, cols=24)
    objSched.add_thread(master(lcd=lcd0))
    objSched.run()
Beispiel #3
0
imu = MPU9150('X')                # Attached to 'X' bus, 1 device, disable interruots

fuse = Fusion()

def waitfunc():
    yield from wait(0.1)

def lcd_thread(mylcd, imu, sw):
    if sw.value() == 1:
        mylcd[0] = "Calibrate. Push switch"
        mylcd[1] = "when done"
        yield from wait(0.1)
        fuse.calibrate(imu.mag.xyz, lambda : not sw.value(), waitfunc)
        print(fuse.magbias)
    mylcd[0] = "{:5s}{:5s} {:5s}".format("Yaw","Pitch","Roll")
    count = 0
    while True:
        yield from wait(0.02) # imu updates at 50Hz
        count += 1
        if count % 25 == 0:
            mylcd[1] = "{:4.0f} {:4.0f}  {:4.0f}".format(fuse.heading, fuse.pitch, fuse.roll)
        fuse.update(imu.accel.xyz, imu.gyro.xyz, imu.mag.xyz)
# For 6DOF sensors
#        fuse.update_nomag(imu.get_accel(), imu.get_gyro())

objSched = Sched()
lcd0 = LCD(PINLIST, objSched, cols = 24) # Should work with 16 column LCD
objSched.add_thread(lcd_thread(lcd0, imu, switch))
objSched.run()
Beispiel #4
0
from usched import Sched, wait, Poller
from lcdthread import LCD, PINLIST  # Library supporting Hitachi LCD module
from mpu9150 import MPU9150


def pollfunc(mpu):
    return 1 if mpu.mag_ready else None


def lcd_thread(mylcd, mpu9150):
    k = mpu9150.mag_correction
    mylcd[1] = "x {:5.3f} y {:5.3f} z {:5.3f}".format(k[0], k[1], k[2])
    while True:
        reason = (yield Poller(pollfunc,
                               (mpu9150, )))  # Scheduler returns when pollfunc
        if reason[
                1] == 1:  # returns something other than None. 1 indicates ready.
            xyz = mpu9150.mag.xyz
            mylcd[0] = "x {:5.1f} y {:5.1f} z {:5.1f}".format(
                xyz[0], xyz[1], xyz[2])
        elif reason[1] == 2:
            mylcd[0] = "Mag read failure"
        yield from wait(0.5)


objSched = Sched()
lcd0 = LCD(PINLIST, objSched, cols=24)
mpu9150 = MPU9150('X')
objSched.add_thread(lcd_thread(lcd0, mpu9150))
objSched.run()