Ejemplo n.º 1
0
def main():
    options, args, proxy = (None, None, None, )
    
    ## Check the connection.
    try:
        options, args, proxy = default_main(args_validator=default_args_validator)
        proxy.validateConnection()
        logging.info("validateConnection() OK")
    except:
        print ""
        print "**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
        print "** "
        print "** The connection to Arduino isn't working as expected."
        print "** This version of 'Py-Arduino-Proxy UI' requires a working"
        print "**   connection to the Arduino. This will be fixed"
        print "**   in future version!"
        print "** "
        print "**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
        print ""
        raise
    
    app = QtGui.QApplication(args[1:])
    q_main_window = QtGui.QMainWindow()
    ArduinoProxyMainWindow(q_main_window, options, args, proxy) # pylint: disable=W0612
    q_main_window.show()
    sys.exit(app.exec_())
Ejemplo n.º 2
0
def main():
    _, _, proxy = default_main() # pylint: disable=W0612
    try:
        print "Clearing LCD", proxy.lcdClear()
        raw_input("Press any key to continue...")
        
        print "'Hello, world!' on row 0", proxy.lcdMessage("Hello, world!")
        raw_input("Press any key to continue...")

        print "'Hello, world!' on row 1", proxy.lcdMessage(["", "Hello, world!"])
        raw_input("Press any key to continue...")

        print "'Hello, world!' on row 0, 'bye bye world' on line 1", \
            proxy.lcdMessage(["Hello, world!", "bye bye world"])
        raw_input("Press any key to continue...")
        
        print "Filling screen with letters and numbers"
        for a_char in ['a', 'b', 'c', 'x', 'y', 'z']:
            proxy.lcdMessage([a_char * 16, a_char * 16])
            time.sleep(0.1)
        raw_input("Press any key to continue...")

        print "Moving an @"
        for i in range(0, 32):
            proxy.lcdWrite("@", i % 16, i / 16, clear_lcd=True) # msg, col, row
            time.sleep(0.2)
        #raw_input("Press any key to continue...")

    except KeyboardInterrupt:
        print ""
    finally:
        proxy.close()
Ejemplo n.º 3
0
def main():

    options, args, proxy = default_main()  # pylint: disable=W0612
    cfg = Config()
    cfg.InteractiveShellEmbed.prompt_in1 = "PyArduinoProxy [\\#]> "
    cfg.InteractiveShellEmbed.prompt_out = "PyArduinoProxy [\\#]: "

    shell = InteractiveShellEmbed(config=cfg, banner2=banner)
    shell.user_ns = {}
    shell()
Ejemplo n.º 4
0
def main():

    options, args, proxy = default_main() # pylint: disable=W0612
    cfg = Config()
    cfg.InteractiveShellEmbed.prompt_in1="PyArduinoProxy [\\#]> "
    cfg.InteractiveShellEmbed.prompt_out="PyArduinoProxy [\\#]: "

    shell = InteractiveShellEmbed(config=cfg, banner2=banner)
    shell.user_ns = {}
    shell()
Ejemplo n.º 5
0
def main(): # pylint: disable=R0915
    _, _, proxy = default_main() # pylint: disable=W0612
    analog_reads = (400, 1000, )
    try:
        #
        # streamingAnalogRead()
        #
        print "Initiating %d reads using analogRead()" % analog_reads[0]
        start_analogRead = datetime.now()
        for i in xrange(0, analog_reads[0]): #@UnusedVariable
            proxy.analogRead(0)
        end_analogRead = datetime.now()
        
        print "Initiating %d reads using streamingAnalogRead()" % analog_reads[1]
        start_streamingAnalogRead = datetime.now()
        for i in proxy.streamingAnalogRead(0, analog_reads[1]): #@UnusedVariable
            pass
        end_streamingAnalogRead = datetime.now()
        
        non_streaming = float(analog_reads[0]) / (end_analogRead - start_analogRead).total_seconds()
        streaming = float(1000.0) / (end_streamingAnalogRead - start_streamingAnalogRead).total_seconds()
        print "analogRead() -> %f reads per second" % non_streaming
        print "streamingAnalogRead() ->  %f reads per second" % streaming
        print "speedup: X%0.2f" % (streaming / non_streaming)
        
        #
        # streamingDigitalRead()
        #
        print "Initiating %d reads using digitalRead()" % analog_reads[0]
        start_digitalRead = datetime.now()
        for i in xrange(0, analog_reads[0]): #@UnusedVariable
            proxy.digitalRead(0)
        end_digitalRead = datetime.now()
        
        print "Initiating %d reads using streamingDigitalRead()" % analog_reads[1]
        start_streamingDigitalRead = datetime.now()
        for i in proxy.streamingDigitalRead(0, analog_reads[1]): #@UnusedVariable
            pass
        end_streamingDigitalRead = datetime.now()
        
        non_streaming = float(analog_reads[0]) / (end_digitalRead - start_digitalRead).total_seconds()
        streaming = float(1000.0) / (end_streamingDigitalRead - start_streamingDigitalRead).total_seconds()
        print "digitalRead() -> %f reads per second" % non_streaming
        print "streamingDigitalRead() ->  %f reads per second" % streaming
        print "speedup: X%0.2f" % (streaming / non_streaming)
        
    except KeyboardInterrupt:
        print ""
    except Exception:
        raise
    finally:
        proxy.close()
Ejemplo n.º 6
0
def main():
    options, _, proxy = default_main(add_options_callback=add_options_callback,
        args_validator=optional_device_arg_validator, connect_only_if_device_specified=True)

    try:
        http_port = int(options.http_port)
    except ValueError:
        raise(Exception("Http port is not valid: {0}".format(options.http_port)))

    if options.exit_on_validate_connection_error:
        start_webserver(http_port, proxy=proxy, validate_connection_error_handler=exit_on_error)
    else:
        start_webserver(http_port, proxy=proxy)
Ejemplo n.º 7
0
def main():
    options, _, proxy = default_main() # pylint: disable=W0612
    try:
        if options.debug:
            proxy.enableDebug()
        
        #    LOW to trigger the interrupt whenever the pin is low,
        #    CHANGE to trigger the interrupt whenever the pin changes value
        #    RISING to trigger when the pin goes from low to high,
        #    FALLING for when the pin goes from high to low.
        #
        #    ATTACH_INTERRUPT_MODE_LOW = 'L'
        #    ATTACH_INTERRUPT_MODE_CHANGE = 'C'
        #    ATTACH_INTERRUPT_MODE_RISING = 'R'
        #    ATTACH_INTERRUPT_MODE_FALLING = 'F'
        
        print "proxy.pinMode()"
        proxy.pinMode(2, ArduinoProxy.INPUT) # INT_0
        proxy.delay(200)
        
        print "proxy.digitalWrite(2,HIGH) -> pullup resistor"
        proxy.digitalWrite(2, ArduinoProxy.HIGH) # INT_0 -> pullup resistor
        proxy.delay(200)
        
        print "proxy.watchInterrupt(0) -> interrupt occurs when pin 2 become LOW."
        print " +", proxy.watchInterrupt(0, ArduinoProxy.ATTACH_INTERRUPT_MODE_LOW)
        
        while True:
            try:
                if proxy.getInterruptMark(0):
                    print " + INTERRUPT 0 has ocurred"
            except InvalidCommand:
                print " + Ignoring InvalidCommand! This is normal when working with interrupts."
            except ArduinoProxyException:
                traceback.print_exc()
                print "##"
                print "## ERROR DETECTED!"
                print "##"
                print "validateConnection() -> %s" % str(proxy.validateConnection())
                print "enableDebug() -> %s" % str(proxy.enableDebug())
                print "ping() -> %s" % str(proxy.ping())
                print ""
                print "Continuing..."
                print ""
                
    except KeyboardInterrupt:
        print ""
    finally:
        proxy.close()
Ejemplo n.º 8
0
def main():  # pylint: disable=R0915
    _, _, proxy = default_main()  # pylint: disable=W0612
    try:
        print "getFreeMemory() -> %s" % str(proxy.getFreeMemory())
        print "enableDebug() -> %s" % str(proxy.enableDebug())
        print "disableDebug() -> %s" % str(proxy.disableDebug())
        print "validateConnection() -> %s" % str(proxy.validateConnection())
        print "ping() -> %s" % str(proxy.ping())
        print "pinMode() -> %s" % str(proxy.pinMode(13, ArduinoProxy.OUTPUT))
        print "analogRead() -> %s" % str(proxy.analogRead(0))
        print "analogWrite() -> %s" % str(proxy.analogWrite(0, 128))
        print "digitalRead() -> %s" % str(proxy.digitalRead(0))
        print "digitalWrite() -> %s" % str(
            proxy.digitalWrite(0, ArduinoProxy.HIGH))
        print "digitalRead() -> %s" % str(proxy.digitalRead(0))
        print "delay() -> %s" % str(proxy.delay(1))
        print "delayMicroseconds() -> %s" % str(proxy.delayMicroseconds(1))
        print "millis() -> %s " % str(proxy.millis())
        print "micros() -> %s" % str(proxy.micros())
        print "shiftOut() -> %s" % str(
            proxy.shiftOut(
                10, 11, ArduinoProxy.LSBFIRST, 255, set_pin_mode=True))

        #define RETURN_OK 0
        #define READ_ONE_PARAM_NEW_LINE_FOUND 7
        #define READ_ONE_PARAM_EMPTY_RESPONSE 1
        #define READ_ONE_PARAM_ERROR_PARAMETER_TOO_LARGE 2
        #define READ_PARAMETERS_ERROR_TOO_MANY_PARAMETERS 3
        #define UNEXPECTED_RESPONSE_FROM_READ_ONE_PARAM 4
        #define UNEXPECTED_RESPONSE_FROM_READ_PARAMETERS 5
        #define FUNCTION_NOT_FOUND 6

        try:
            print "Check for READ_ONE_PARAM_ERROR_PARAMETER_TOO_LARGE"
            proxy.send_cmd("laaaarge_meeeethod_" * 10)
            assert False, "The previous line should raise an exception!"
        except InvalidCommand, exception:
            # READ_ONE_PARAM_ERROR_PARAMETER_TOO_LARGE == 2
            print " +", exception
            assert exception.error_code == "2"

        try:
            print "Check for FUNCTION_NOT_FOUND"
            proxy.send_cmd("_nonexisting\tp1\tp2\tp3\tp4\tp5\tp6\tp7\tp8\tp9")
            assert False, "The previous line should raise an exception!"
        except InvalidCommand, exception:
            # FUNCTION_NOT_FOUND == 6
            print " +", exception
            assert exception.error_code == "6"
Ejemplo n.º 9
0
def main(): # pylint: disable=R0915
    _, _, proxy = default_main() # pylint: disable=W0612
    try:
        print "getFreeMemory() -> %s" % str(proxy.getFreeMemory())
        print "enableDebug() -> %s" % str(proxy.enableDebug())
        print "disableDebug() -> %s" % str(proxy.disableDebug())
        print "validateConnection() -> %s" % str(proxy.validateConnection())
        print "ping() -> %s" % str(proxy.ping())
        print "pinMode() -> %s" % str(proxy.pinMode(13, ArduinoProxy.OUTPUT))
        print "analogRead() -> %s" % str(proxy.analogRead(0))
        print "analogWrite() -> %s" % str(proxy.analogWrite(0, 128))
        print "digitalRead() -> %s" % str(proxy.digitalRead(0))
        print "digitalWrite() -> %s" % str(proxy.digitalWrite(0, ArduinoProxy.HIGH))
        print "digitalRead() -> %s" % str(proxy.digitalRead(0))
        print "delay() -> %s" % str(proxy.delay(1))
        print "delayMicroseconds() -> %s" % str(proxy.delayMicroseconds(1))
        print "millis() -> %s " % str(proxy.millis())
        print "micros() -> %s" % str(proxy.micros())
        print "shiftOut() -> %s" % str(proxy.shiftOut(10, 11, ArduinoProxy.LSBFIRST, 255,
            set_pin_mode=True))

        #define RETURN_OK 0
        #define READ_ONE_PARAM_NEW_LINE_FOUND 7
        #define READ_ONE_PARAM_EMPTY_RESPONSE 1
        #define READ_ONE_PARAM_ERROR_PARAMETER_TOO_LARGE 2
        #define READ_PARAMETERS_ERROR_TOO_MANY_PARAMETERS 3
        #define UNEXPECTED_RESPONSE_FROM_READ_ONE_PARAM 4
        #define UNEXPECTED_RESPONSE_FROM_READ_PARAMETERS 5
        #define FUNCTION_NOT_FOUND 6

        try:
            print "Check for READ_ONE_PARAM_ERROR_PARAMETER_TOO_LARGE"
            proxy.send_cmd("laaaarge_meeeethod_" * 10)
            assert False, "The previous line should raise an exception!"
        except InvalidCommand, exception:
            # READ_ONE_PARAM_ERROR_PARAMETER_TOO_LARGE == 2
            print " +", exception
            assert exception.error_code == "2"

        try:
            print "Check for FUNCTION_NOT_FOUND"
            proxy.send_cmd("_nonexisting\tp1\tp2\tp3\tp4\tp5\tp6\tp7\tp8\tp9")
            assert False, "The previous line should raise an exception!"
        except InvalidCommand, exception:
            # FUNCTION_NOT_FOUND == 6
            print " +", exception
            assert exception.error_code == "6"
Ejemplo n.º 10
0
def main():
    options, args, proxy = default_main(optparse_usage=\
        "usage: %prog [options] serial_device pwm_digital_port value",
        args_validator=args_validator)

    pwm_digital_port = int(args[1])
    value = int(args[2])

    try:
        proxy.pinMode(pwm_digital_port, ArduinoProxy.OUTPUT)
        proxy.analogWrite(pwm_digital_port, value)
    except KeyboardInterrupt:
        print ""
    except Exception:
        raise
    finally:
        proxy.close()
Ejemplo n.º 11
0
def main():
    options, args, proxy = default_main(optparse_usage=\
        "usage: %prog [options] serial_device pwm_digital_port value",
        args_validator=args_validator)
    
    pwm_digital_port = int(args[1])
    value = int(args[2])
    
    try:
        proxy.pinMode(pwm_digital_port, ArduinoProxy.OUTPUT)
        proxy.analogWrite(pwm_digital_port, value)
    except KeyboardInterrupt:
        print ""
    except Exception:
        raise
    finally:
        proxy.close()
Ejemplo n.º 12
0
def main():
    options, _, proxy = default_main(
        add_options_callback=add_options_callback,
        args_validator=optional_device_arg_validator,
        connect_only_if_device_specified=True)

    try:
        http_port = int(options.http_port)
    except ValueError:
        raise (Exception("Http port is not valid: {0}".format(
            options.http_port)))

    if options.exit_on_validate_connection_error:
        start_webserver(http_port,
                        proxy=proxy,
                        validate_connection_error_handler=exit_on_error)
    else:
        start_webserver(http_port, proxy=proxy)
Ejemplo n.º 13
0
def main():
    options, args, proxy = default_main(optparse_usage=\
        "usage: %prog [options] serial_device digital_port", args_validator=args_validator)

    digital_port = int(args[1])

    try:
        proxy.pinMode(digital_port, ArduinoProxy.OUTPUT)
        while True:
            proxy.digitalWrite(digital_port, ArduinoProxy.HIGH)
            time.sleep(0.5)
            proxy.digitalWrite(digital_port, ArduinoProxy.LOW)
            time.sleep(0.5)
    except KeyboardInterrupt:
        print ""
    except Exception:
        raise
    finally:
        proxy.close()
Ejemplo n.º 14
0
def main():
    options, args, proxy = default_main(optparse_usage=\
        "usage: %prog [options] serial_device digital_port", args_validator=args_validator)
    
    digital_port = int(args[1])
    
    try:
        proxy.pinMode(digital_port, ArduinoProxy.OUTPUT)
        while True:
            proxy.digitalWrite(digital_port, ArduinoProxy.HIGH)
            time.sleep(0.5)
            proxy.digitalWrite(digital_port, ArduinoProxy.LOW)
            time.sleep(0.5)
    except KeyboardInterrupt:
        print ""
    except Exception:
        raise
    finally:
        proxy.close()
Ejemplo n.º 15
0
def main(callback):
    options, args, proxy = default_main(optparse_usage=\
        "usage: %prog [options] serial_device analog_port", args_validator=args_validator,
        add_options_callback=add_options_callback)
    
    analog_port = int(args[1])
    
    try:
        while True:
            value = proxy.analogRead(analog_port)
            callback(value)
            if not options.loop:
                break
    except KeyboardInterrupt:
        print ""
    except Exception:
        raise
    finally:
        proxy.close()
Ejemplo n.º 16
0
def main():
    options, args, proxy = default_main(optparse_usage=\
        "usage: %prog [options] serial_device analog_port", args_validator=args_validator)
    
    analog_port = int(args[1])
    
    try:
        while True:
            value = proxy.analogRead(analog_port)
            temp_in_c = ((5.0 * int(value) * 100.0)/1024.0)
            temp_in_f = ((temp_in_c * 9.0) / 5.0) + 32
            proxy.lcdMessage(["Temperature/%d" % analog_port, "%.2fC %.2fF" % (temp_in_c, temp_in_f)])
            time.sleep(2)
    except KeyboardInterrupt:
        print ""
    except Exception:
        raise
    finally:
        proxy.close()
Ejemplo n.º 17
0
def main():
    
    options, args, proxy = default_main() # pylint: disable=W0612
    ipshell = IPShellEmbed()
    ipshell.set_banner("""

Launching IPython shell...

Available variables:
 - proxy: the ArduinoProxy instance.
 - options, args: parsed argument options.

To import ArduinoProxy class:
>>> from arduino_proxy import ArduinoProxy

Enter 'quit()' to exit.
 
    """)
    ipshell()
Ejemplo n.º 18
0
def main(callback):
    options, args, proxy = default_main(optparse_usage=\
        "usage: %prog [options] serial_device analog_port", args_validator=args_validator,
        add_options_callback=add_options_callback)

    analog_port = int(args[1])

    try:
        while True:
            value = proxy.analogRead(analog_port)
            callback(value)
            if not options.loop:
                break
    except KeyboardInterrupt:
        print ""
    except Exception:
        raise
    finally:
        proxy.close()
Ejemplo n.º 19
0
def main(callback):
    options, args, proxy = default_main(optparse_usage=\
        "usage: %prog [options] serial_device digital_port", args_validator=args_validator,
        add_options_callback=add_options_callback)

    digital_port = int(args[1])

    try:
        proxy.pinMode(digital_port, ArduinoProxy.INPUT)
        while True:
            value = proxy.digitalRead(digital_port)
            callback(value, options)
            if not options.loop:
                break
    except KeyboardInterrupt:
        print ""
    except Exception:
        raise
    finally:
        proxy.close()
Ejemplo n.º 20
0
def main():

    _, _, proxy = default_main() # pylint: disable=W0612
    try:
        while True:
            sys.stdout.write("Ping sent...")
            sys.stdout.flush()
            start = time.time()
            try:
                proxy.ping()
                end = time.time()
                sys.stdout.write(" OK - Time=%.3f ms\n" % ((end - start) * 1000))
                sys.stdout.flush()
                time.sleep(1)
            except CommandTimeout:
                sys.stdout.write(" timeout\n")
                sys.stdout.flush()
    except KeyboardInterrupt:
        print ""
        proxy.close()
Ejemplo n.º 21
0
def main():
    
    options, args, proxy = default_main() # pylint: disable=W0612
    try:
        while True:
            sys.stdout.write("Ping sent...")
            sys.stdout.flush()
            start = time.time()
            try:
                proxy.ping()
                end = time.time()
                sys.stdout.write(" OK - Time=%.3f ms\n" % ((end-start)*1000))
                sys.stdout.flush()
                time.sleep(1)
            except CommandTimeout:
                sys.stdout.write(" timeout\n")
                sys.stdout.flush()
    except KeyboardInterrupt:
        print ""
        proxy.close()
Ejemplo n.º 22
0
def main():
    options, args, proxy = default_main(optparse_usage=\
        "usage: %prog [options] serial_device pwm_digital_port",
        args_validator=args_validator)
    
    pwm_digital_port = int(args[1])
    
    try:
        proxy.pinMode(pwm_digital_port, ArduinoProxy.OUTPUT)
        while True:
            for value in range(0, 256):
                proxy.analogWrite(pwm_digital_port, value)
            for value in range(255, -1, -1):
                proxy.analogWrite(pwm_digital_port, value)
    except KeyboardInterrupt:
        print ""
    except Exception:
        raise
    finally:
        proxy.close()
Ejemplo n.º 23
0
def main(callback):
    options, args, proxy = default_main(optparse_usage=\
        "usage: %prog [options] serial_device digital_port", args_validator=args_validator,
        add_options_callback=add_options_callback)
    
    digital_port = int(args[1])
    
    try:
        proxy.pinMode(digital_port, ArduinoProxy.INPUT)
        while True:
            value = proxy.digitalRead(digital_port)
            callback(value, options)
            if not options.loop:
                break
    except KeyboardInterrupt:
        print ""
    except Exception:
        raise
    finally:
        proxy.close()
def main():
    options, args, proxy = default_main(optparse_usage=\
        "usage: %prog [options] serial_device pwm_digital_port",
        args_validator=args_validator)
    
    pwm_digital_port = int(args[1])
    
    try:
        proxy.pinMode(pwm_digital_port, ArduinoProxy.OUTPUT)
        while True:
            for value in range(0, 256):
                proxy.analogWrite(pwm_digital_port, value)
            for value in range(255, -1, -1):
                proxy.analogWrite(pwm_digital_port, value)
    except KeyboardInterrupt:
        print ""
    except Exception:
        raise
    finally:
        proxy.close()
Ejemplo n.º 25
0
def main():
    options, args, proxy = default_main(optparse_usage=\
        "usage: %prog [options] serial_device digital_port", args_validator=args_validator,
        add_options_callback=add_options_callback)
    
    digital_port = int(args[1])
    
    try:
        while True:
            temp, hum = proxy.dht11_read(digital_port)
            print "Temp: {0}C - Hum: {1}%".format(
                temp, hum)
            if options.loop:
                proxy.delay(500)
            else:
                break
    except KeyboardInterrupt:
        print ""
    except Exception:
        raise
    finally:
        proxy.close()
Ejemplo n.º 26
0
def main():
    options, args, proxy = default_main()
    print "CPU: %s" % proxy.getAvrCpuType()
    pprint.pprint(proxy.getArduinoTypeStruct())
    proxy.close()
Ejemplo n.º 27
0
def main():
    options, args, proxy = default_main()
    print "CPU: %s" % proxy.getAvrCpuType()
    pprint.pprint(proxy.getArduinoTypeStruct())
    proxy.close()