Ejemplo n.º 1
0
def main():
    mcu = Arduino()
    mcu.pin(9).mode = OUTPUT
    mcu.pin(9).write_digital_out(1)
    pwm = mcu.pin(9).pwm
    pwm.set_high_freq_around(10000)
    print 'real frequency=', pwm.read_frequency()
Ejemplo n.º 2
0
def main(n=40, pin_nr=13, reset=False):
    """
    measuring analog input
    """
    mcu = Arduino(reset=reset)
    pin = mcu.pin(pin_nr)
    pin.write_mode(INPUT)
    x = []
    y = []
    start = time.time()
    for i in range(n):
        t = time.time() - start
        v = pin.read_analog()
        x.append(t)
        y.append(v)
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.plot(x, y, "b-o")

    ax.yaxis.set_major_formatter(FuncFormatter(lambda x, pos: ("%d") % (x)))
    ax.set_ylabel("analog value")

    ax.xaxis.set_major_formatter(FuncFormatter(lambda x, pos: "%.0f" % (1000 * x)))
    ax.set_xlabel("milliseconds")
    plt.show()
Ejemplo n.º 3
0
def test_counter():
    if (sys.version_info < (2, 6, 0)):
        from nose.plugins.skip import SkipTest
        raise SkipTest    
    mcu = Arduino()
    reg = mcu.registers.proxy
    mcu.pins.reset()
    p = mcu.pin(5)
    p.write_mode(OUTPUT)
    p.pwm.write_value(128)
    print 'frequencies_available:', p.pwm.frequencies_available
    for fset in p.pwm.frequencies_available:
        p.pwm.frequency = fset
        assert abs(p.pwm.frequency - fset) <= 1
        print '---------------------------'
        print 'fset=', fset
        print '---------------------------'
        for ms in [10, 20, 50, 100, 200, 500, 1000]:
            for _ in range(1):
                t = ms / 1000.0
                with mcu.counter:
                    mcu.counter.run(t)
                    f = mcu.counter.frequency
                    t = mcu.counter.gate_time
                    err = f - fset

                    print 't=%s  f=%s ' % (t, f)
                    ok_(abs(nominal_value(err)) <= 0.1+std_dev(err), 
                        (abs(nominal_value(err)),std_dev(err)))
Ejemplo n.º 4
0
def main():
    mcu = Arduino()
    p = mcu.pin(9)
    print p.read_mode()
    p.write_mode(1)
    print p.read_mode()
    mcu.pins.reset()
    print p.read_mode()
Ejemplo n.º 5
0
def main():
    mcu = Arduino()
    print 'mcu.bandgap_voltage =', mcu.bandgap_voltage
    print 'mcu.vcc.voltage =', mcu.vcc.voltage
    print 'mcu.vcc.u_voltage =', mcu.vcc.u_voltage
    print 'mcu.vcc.read_u_voltage() =', mcu.vcc.read_u_voltage()
    print 'mcu.vcc.read_voltage() =', mcu.vcc.read_voltage()
    print 'mcu.read_u_vcc() =', mcu.read_u_vcc()
    print 'mcu.read_vcc() =', mcu.read_vcc()
Ejemplo n.º 6
0
def main(
    t=0.1,
):
    mcu = Arduino()
    while 1:
        for x in mcu.pins.range_analog:
            pin = mcu.pin(x)
            print '%s:%s' % (pin.name, pin.read_analog()),
        print
        time.sleep(t)
Ejemplo n.º 7
0
def main(pin=''):
    '''


    :param pin: examples: 'D0','A2'

    '''
    mcu = Arduino(reset=False)
    if pin:
        pin = mcu.pin(pin)

    BoardWrapper(mcu=mcu).configure_traits()
Ejemplo n.º 8
0
def dig_out():
    dev = Arduino()
    dev.reset()
    pin = dev.pin(8)
    pin.mode = OUTPUT

    pin2 = dev.pin('A0')
    while 1:
        time.sleep(0.001)
        pin.dig_out = 0
        pin2.analog_in().value
        pin.dig_out = 1
        pin2.analog_in().value
Ejemplo n.º 9
0
def main(
    reconnect_time=5,
    func='usbPoll',
    disable_interrupts=0,
    sleep_between_calls=0,
    delay=0.001,
):
    mcu = Arduino()
    mcu.pins.reset()

    count = 0
    fail = 0
    t1 = time.time()
    while 1:
        count += 1
        t2 = time.time()
        if (t2 - t1) > 2:
            t1 = t2
            print dict(
                delay=delay,
                func=func,
                disable_interrupts=disable_interrupts,
                sleep_between_calls=sleep_between_calls,
                count=count,
                fail=fail,
            )
        try:
            mcu.delay_test(delay,
                           func,
                           disable_interrupts=disable_interrupts)
            time.sleep(sleep_between_calls)
            mcu.firmware_test()

        except (usb.USBError, ArduinoUsbDeviceError), e:
            print('USBError: %s reconnect_time: %s s' % (str(
                e), reconnect_time))

            # time for reconnect
            time.sleep(reconnect_time)

#            mcu.connect()
            fail += 1
Ejemplo n.º 10
0
def usbdump():
    mcu = Arduino()

    print
    print '================================'
    print 'Arduino() attributes:'
    print '================================'
    dump(mcu)

    print
    print '================================'
    print 'Arduino().usb attributes:'
    print '================================'
    dump(mcu.usb)

    print
    print '================================'
    print 'Arduino().pins attributes:'
    print '================================'
    dump(mcu.pins)

    print
    print '================================'
    print 'Arduino().pin(nr) attributes:'
    print '================================'
    for nr in mcu.pins.range_all:
        print '---------- nr=%s ---------------' % nr
        dump(mcu.pin(nr))
        if mcu.pin(nr).pwm.available:
            print '--- pwm ---'
            dump(mcu.pin(nr).pwm)

    print
    print '================================'
    print 'Arduino().vcc attributes:'
    print '================================'
    dump(mcu.vcc)

    print
    print '================================'
    print 'Arduino().defines attributes:'
    print '================================'

    dump(mcu.defines)

    print
    print '================================'
    print 'Arduino().registers attributes:'
    print '================================'
    dump(mcu.registers)

    print

    print
    print '================================'
    print 'defines:'
    print '================================'
    for k, v in SortedDict(mcu.defines.as_dict()).items():
        print '%-20s = %18s' % (k, v)

    print
    print '================================'
    print 'registers:'
    print '================================'
    # , key=lambda x:mcu.registers.address(x[0]) # sort by address
    for k, v in SortedDict(mcu.registers.as_dict()).items():
        print '%-20s = 0x%02X @0x%2X (%s)' % (k, v, mcu.registers.address(k), mcu.registers.size(k))
Ejemplo n.º 11
0
def main():
    mcu = Arduino()
    print 'F_CPU=', mcu.define('F_CPU')
    print 'DDRC=', mcu.register('DDRC').read_value()