From 60103d1ce89c173cb9803a2554923c0426e3e8d9 Mon Sep 17 00:00:00 2001 From: Quentin Bolsee <quentinbolsee@hotmail.com> Date: Mon, 2 Oct 2023 19:40:09 -0400 Subject: [PATCH] support for prints --- .gitignore | 4 ++++ examples/micropython/main.py | 5 ++++- examples/test_blink.py | 6 ++++-- examples/test_time.py | 6 +++--- examples/test_upload.py | 6 +++--- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index fcd3efb..08fc627 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ *.psd +examples/mpy_bridge.py +__pycache__ +examples/__pycache__ +.idea \ No newline at end of file diff --git a/examples/micropython/main.py b/examples/micropython/main.py index 19f8503..9084706 100644 --- a/examples/micropython/main.py +++ b/examples/micropython/main.py @@ -7,15 +7,18 @@ def get_pin_value(pin): def echo_function(*args, **kwargs): - return f"You sent args: {args}, kwargs: {kwargs}" + return "You sent args {}, kwargs {}".format(args, kwargs) def led_on(): + print("LED ON") p_led.off() def led_off(): + print("LED OFF") p_led.on() p_led = machine.Pin(16, machine.Pin.OUT) +led_off() diff --git a/examples/test_blink.py b/examples/test_blink.py index a47bfd1..aa81277 100644 --- a/examples/test_blink.py +++ b/examples/test_blink.py @@ -4,17 +4,19 @@ import time def main(): # open device, read functions - d = mpy_bridge.Device("COM5") + d = mpy_bridge.Device("COM39") # print out functions print(d) - # blink LED once + # # blink LED once d.led_on() time.sleep(0.2) d.led_off() time.sleep(0.2) + print(d.echo_function(4, 5, a=10)) + if __name__ == "__main__": main() diff --git a/examples/test_time.py b/examples/test_time.py index 09384a8..5329ad9 100644 --- a/examples/test_time.py +++ b/examples/test_time.py @@ -5,7 +5,7 @@ import matplotlib.pyplot as plt def main(): - d = mpy_bridge.Device("COM34") + d = mpy_bridge.Device("COM39") n_exp = 1024 results = [] @@ -15,8 +15,8 @@ def main(): t2 = datetime.datetime.now() results.append((t2 - t1).total_seconds()) - print(np.mean(results)) - print(np.std(results)) + print(f"Mean RTT: {np.mean(results)}") + print(f"STD RTT: {np.std(results)}") results_ms = [1000*x for x in results] diff --git a/examples/test_upload.py b/examples/test_upload.py index dd90f5a..8c3e3a2 100644 --- a/examples/test_upload.py +++ b/examples/test_upload.py @@ -2,10 +2,10 @@ import mpy_bridge def main(): - d = mpy_bridge.Device("COM34") + # Open device, skip reading its functions (the main file might be absent) + d = mpy_bridge.Device("COM39", init=False) + # Upload main file d.upload("micropython/main.py", "main.py") - print(d) - d.close() if __name__ == "__main__": -- GitLab