Пример #1
0
async def main():
    SENT_GPIO = 18
    RUN_TIME = 6000000000.0
    SAMPLE_TIME = 0.1

    pi = asyncpio.pi()
    await pi.connect()

    p = await SENTReader.create(pi, SENT_GPIO)

    start = time.time()

    while (time.time() - start) < RUN_TIME:

        await asyncio.sleep(SAMPLE_TIME)

        status, data1, data2, ticktime, crc, errors, syncPulse = p.SENTData()
        print(
            "Sent Status= %s - 12-bit DATA 1= %4.0f - DATA 2= %4.0f - tickTime(uS)= %4.2f - CRC= %s - Errors= %s - PERIOD = %s"
            % (status, data1, data2, ticktime, crc, errors, syncPulse))
        print(
            "Sent Stat2s= %s - 12-bit DATA 1= %4.0f - DATA 2= %4.0f - tickTime(uS)= %4.2f - CRC= %s - Errors= %s - PERIOD = %s"
            % (p.statusNibble(), p.dataField1(), p.dataField2(), p.tick(),
               p.crcNibble(), p.errorFrame(), p.syncPulse()))

    # stop the thread in SENTReader
    await p.stop()
    # clear the pi object instance
    await pi.stop()
Пример #2
0
async def main():
    pi = asyncpio.pi()
    await pi.connect()
    sensor = await DHT11.create(pi, 4)
    async for d in sensor:
        print("temperature: {}".format(d['temperature']))
        print("humidity: {}".format(d['humidity']))
        await asyncio.sleep(1)
    await sensor.close()
Пример #3
0
async def main():
    pi = asyncpio.pi()
    await pi.connect()

    s = await sniffer.create(pi, 1, 0, False)  # leave gpios 1/0 in I2C mode

    await asyncio.sleep(60000)

    await s.cancel()

    await pi.stop()
Пример #4
0
async def main():
    pi = asyncpio.pi()

    # Intervals of about 2 seconds or less will eventually hang the DHT22.
    INTERVAL = 3

    pi = asyncpio.pi()
    await pi.connect()

    s = await sensor.create(pi, 22, LED=16, power=8)

    try:
        r = 0

        next_reading = time.time()

        while True:

            r += 1

            await s.trigger()

            await asyncio.sleep(0.2)

            print("{} {} {} {:3.2f} {} {} {} {}".format(
                r, s.humidity(), s.temperature(), s.staleness(),
                s.bad_checksum(), s.short_message(), s.missing_message(),
                s.sensor_resets()))

            next_reading += INTERVAL

            await asyncio.sleep(next_reading - time.time()
                                )  # Overall INTERVAL second polling.

    except KeyboardInterrupt:
        await s.cancel()

    await pi.stop()
Пример #5
0
async def main():
    def callback(bits, value):
        print("bits={} value={}".format(bits, value))

    pi = asyncpio.pi()
    await pi.connect()

    w = await decoder.create(pi, 14, 15, callback)

    await asyncio.sleep(300)

    await w.cancel()

    await pi.stop()
Пример #6
0
async def main():
    pi = asyncpio.pi()
    await pi.connect()  # Connect to local Pi.

    handle = await pi.i2c_open(1, YL_40, 0)

    stdscr = curses.initscr()

    curses.noecho()
    curses.cbreak()

    aout = 0

    stdscr.addstr(10, 0, "Brightness")
    stdscr.addstr(12, 0, "Temperature")
    stdscr.addstr(14, 0, "AOUT->AIN2")
    stdscr.addstr(16, 0, "Resistor")

    stdscr.nodelay(1)

    try:
        while True:

            for a in range(0, 4):
                aout = aout + 1
                await pi.i2c_write_byte_data(handle, 0x40 | ((a + 1) & 0x03),
                                             aout & 0xFF)
                v = await pi.i2c_read_byte(handle)
                hashes = v / 4
                spaces = 64 - hashes
                stdscr.addstr(10 + a * 2, 12, str(v) + ' ')
                stdscr.addstr(10 + a * 2, 16, '#' * hashes + ' ' * spaces)

            stdscr.refresh()
            await asyncio.sleep(0.04)

            c = stdscr.getch()

            if c != curses.ERR:
                break

    except:
        pass

    curses.nocbreak()
    curses.echo()
    curses.endwin()

    await pi.i2c_close(handle)
    await pi.stop()
Пример #7
0
async def main():
    pi = asyncpio.pi()
    await pi.connect() # connect to local Pi

    await pi.set_mode(HALL, asyncpio.INPUT)
    await pi.set_pull_up_down(HALL, asyncpio.PUD_UP)

    start = time.time()

    while (time.time() - start) < 60:
        print("Hall = {}".format(await pi.read(HALL)))
        await asyncio.sleep(0.2)

    await pi.stop()
Пример #8
0
async def main():
    pi = asyncpio.pi()
    await pi.connect()

    await pi.set_mode(GPIO, asyncpio.OUTPUT)

    await transmit_string(pi, GPIO, "Now is the winter of our discontent")

    while await pi.wave_tx_busy():
        pass

    await transmit_string(pi, GPIO, "made glorious summer by this sun of York")

    while await pi.wave_tx_busy():
        pass

    await pi.stop()
Пример #9
0
async def main():
    pi = asyncpio.pi()
    await pi.connect()

    sonar = await ranger.create(pi, 23, 18)

    end = time.time() + 600.0

    r = 1
    while time.time() < end:

        print("{} {}".format(r, await sonar.read()))
        r += 1
        await asyncio.sleep(0.03)

    await sonar.cancel()

    await pi.stop()
Пример #10
0
async def main():
    pi = asyncpio.pi()
    await pi.connect()

    t1 = gpioTest(pi, 4, asyncpio.EITHER_EDGE, 4000, 1)
    t2 = gpioTest(pi, 7, asyncpio.RISING_EDGE, 8000, 2)
    t3 = gpioTest(pi, 8, asyncpio.FALLING_EDGE, 8000, 3)
    t4 = gpioTest(pi, 9, asyncpio.EITHER_EDGE, 4000, 4)
    t5 = gpioTest(pi, 10, asyncpio.RISING_EDGE, 8000, 5)
    t6 = gpioTest(pi, 11, asyncpio.FALLING_EDGE, 8000, 6)
    t7 = gpioTest(pi, 14, asyncpio.EITHER_EDGE, 4000, 7)
    t8 = gpioTest(pi, 15, asyncpio.RISING_EDGE, 8000, 8)
    t9 = gpioTest(pi, 17, asyncpio.FALLING_EDGE, 8000, 9)
    t10 = gpioTest(pi, 18, asyncpio.EITHER_EDGE, 4000, 10)
    t11 = gpioTest(pi, 22, asyncpio.RISING_EDGE, 8000, 11)
    t12 = gpioTest(pi, 23, asyncpio.FALLING_EDGE, 8000, 12)
    t13 = gpioTest(pi, 24, asyncpio.EITHER_EDGE, 4000, 13)
    t14 = gpioTest(pi, 25, asyncpio.RISING_EDGE, 8000, 14)

    # R1: 0 1     4 7 8 9 10 11 14 15 17 18 21 22 23 24 25
    # R2:     2 3 4 7 8 9 10 11 14 15 17 18    22 23 24 25 27 28 29 30 31

    tests = [t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14]

    for i in tests:
        await i.start()

    await asyncio.sleep(delay)

    for i in tests:
        await i.stop()

    await pi.stop()

    tot = 0
    msg = ""

    for i in tests:
        tot += i.num()
        msg += str(i.num()) + " "

    print(msg)

    print("eps={} ({}/{})".format(tot / delay, tot, delay))
Пример #11
0
async def main():
    RX = 11
    TX = 25

    BPS = 2000

    pi = asyncpio.pi()  # Connect to local Pi.
    await pi.connect()

    rx = await rx.create(pi, RX, BPS)  # Specify Pi, rx gpio, and baud.
    tx = await tx.create(pi, TX, BPS)  # Specify Pi, tx gpio, and baud.

    msg = 0

    start = time.time()

    while (time.time() - start) < 300:

        msg += 1

        while not await tx.ready():
            await asyncio.sleep(0.1)

        await asyncio.sleep(0.2)

        await tx.put([48, 49, 65, ((msg >> 6) & 0x3F) + 32, (msg & 0x3F) + 32])

        while not await tx.ready():
            await asyncio.sleep(0.1)

        await asyncio.sleep(0.2)

        await tx.put("Hello World #{}!".format(msg))

        while rx.ready():
            print("".join(chr(c) for c in rx.get()))

    await rx.cancel()
    await tx.cancel()

    await pi.stop()
Пример #12
0
async def main():
   pos = 0

   def callback(way):

      nonlocal pos

      pos += way

      print("pos={}".format(pos))

   pi = asyncpio.pi()
   await pi.connect()

   decoder = decoder(pi, 7, 8, callback)
   await decoder.start()

   await asyncio.sleep(300)

   await decoder.cancel()

   await pi.stop()
Пример #13
0
async def main():
    hashes = {
        142650387: '2',
        244341844: 'menu',
        262513468: 'vol-',
        272048826: '5',
        345069212: '6',
        363685443: 'prev.ch',
        434191356: '1',
        492745084: 'OK',
        549497027: 'mute',
        603729091: 'text',
        646476378: 'chan-',
        832916949: 'home',
        923778138: 'power',
        938165610: 'power',
        953243510: 'forward',
        1009731980: '1',
        1018231875: 'TV',
        1142888517: 'c-up',
        1151589683: 'chan+',
        1344018636: 'OK',
        1348032067: 'chan+',
        1367109971: 'prev.ch',
        1370712102: 'c-left',
        1438405361: 'rewind',
        1452589043: 'pause',
        1518578730: 'chan-',
        1554432645: '8',
        1583569525: '0',
        1629745313: 'rewind',
        1666513749: 'record',
        1677653754: 'c-down',
        1825951717: 'c-right',
        1852412236: '6',
        1894279468: '9',
        1904895749: 'vol+',
        1941947509: 'ff',
        2076573637: '0',
        2104823531: 'back',
        2141641957: 'home',
        2160787557: 'record',
        2398525299: '7',
        2468117013: '8',
        2476712746: 'play',
        2574308838: 'forward',
        2577952149: '4',
        2706654902: 'stop',
        2829002741: 'c-up',
        2956097083: 'back',
        3112717386: '5',
        3263244773: 'ff',
        3286088195: 'pause',
        3363767978: 'c-down',
        3468076364: 'vol-',
        3491068358: 'stop',
        3593710134: 'c-left',
        3708232515: '3',
        3734134565: 'back',
        3766109107: 'TV',
        3798010010: 'play',
        3869937700: 'menu',
        3872715523: '7',
        3885097091: '2',
        3895301587: 'text',
        3931058739: 'mute',
        3983900853: 'c-right',
        4032250885: '4',
        4041913909: 'vol+',
        4207017660: '9',
        4227138677: 'back',
        4294027955: '3'
    }

    def callback(hash):
        if hash in hashes:
            print("key={} hash={}".format(hashes[hash], hash))

    pi = asyncpio.pi()
    await pi.connect()

    ir = await hasher.create(pi, 7, callback, 5)

    print("ctrl c to exit")

    await asyncio.sleep(300)

    await pi.stop()
Пример #14
0
    while True:

        for g in range(GPIOS):
            tally = cb[g].tally()
            mode = await pi.get_mode(g)

            col = (g // 11) * 25
            row = (g % 11) + 2

            stdscr.addstr(row, col, "{:2}".format(g), curses.A_BOLD)

            stdscr.addstr("={} {:>6}: {:<10}".format(pi.read(g), MODES[mode],
                                                     tally))

        stdscr.refresh()

        await asyncio.sleep(0.1)

        c = stdscr.getch()

        if c != curses.ERR:
            break


pi = asyncpio.pi()
loop = asyncio.get_event_loop()
try:
    loop.run_until_complete(main(pi))
finally:
    loop.run_until_complete(cleanup(pi))