From 2e3e0e316bc9bd396e02f60c403ce918606be459 Mon Sep 17 00:00:00 2001 From: Marcus Nordstrom Date: Sat, 3 May 2025 13:38:03 +0200 Subject: [PATCH] initial commit --- .Trash-1000 | 0 .Trashes | 0 .fseventsd/no_log | 0 .metadata_never_index | 0 .vscode/settings.json | 15 +++++++++++++++ boot.py | 3 +++ boot_out.txt | 4 ++++ code.py | 31 +++++++++++++++++++++++++++++++ sd/placeholder.txt | 1 + settings.toml | 0 10 files changed, 54 insertions(+) create mode 100644 .Trash-1000 create mode 100644 .Trashes create mode 100644 .fseventsd/no_log create mode 100644 .metadata_never_index create mode 100644 .vscode/settings.json create mode 100644 boot.py create mode 100644 boot_out.txt create mode 100644 code.py create mode 100644 sd/placeholder.txt create mode 100644 settings.toml diff --git a/.Trash-1000 b/.Trash-1000 new file mode 100644 index 0000000..e69de29 diff --git a/.Trashes b/.Trashes new file mode 100644 index 0000000..e69de29 diff --git a/.fseventsd/no_log b/.fseventsd/no_log new file mode 100644 index 0000000..e69de29 diff --git a/.metadata_never_index b/.metadata_never_index new file mode 100644 index 0000000..e69de29 diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e9a8c58 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,15 @@ +{ + "python.languageServer": "Pylance", + "python.analysis.diagnosticSeverityOverrides": { + "reportMissingModuleSource": "none", + "reportShadowedImports": "none" + }, + "circuitpython.board.version": "9.2.7", + "circuitpython.board.vid": "0x239A", + "circuitpython.board.pid": "0x80F4", + "python.analysis.extraPaths": [ + "/home/mackan/.vscode/extensions/wmerkens.vscode-circuitpython-v2-0.3.3/boards/0x239A/0x80F4", + "/home/mackan/.vscode/extensions/wmerkens.vscode-circuitpython-v2-0.3.3/stubs", + "/home/mackan/.config/Code/User/globalStorage/wmerkens.vscode-circuitpython-v2/bundle/20250222/adafruit-circuitpython-bundle-py-20250222/lib" + ] +} \ No newline at end of file diff --git a/boot.py b/boot.py new file mode 100644 index 0000000..81198c5 --- /dev/null +++ b/boot.py @@ -0,0 +1,3 @@ +import usb_cdc + +usb_cdc.enable(console=True, data=True) \ No newline at end of file diff --git a/boot_out.txt b/boot_out.txt new file mode 100644 index 0000000..ae006f9 --- /dev/null +++ b/boot_out.txt @@ -0,0 +1,4 @@ +Adafruit CircuitPython 9.2.7 on 2025-04-01; Raspberry Pi Pico with rp2040 +Board ID:raspberry_pi_pico +UID:504450612057BD1C +boot.py output: diff --git a/code.py b/code.py new file mode 100644 index 0000000..fc0920f --- /dev/null +++ b/code.py @@ -0,0 +1,31 @@ +import time +import board +import usb_cdc +import pwmio +import digitalio + +pwm_X = pwmio.PWMOut(board.GP17, frequency=1000, duty_cycle=0) +pwm_Y = pwmio.PWMOut(board.GP18, frequency=1000, duty_cycle=0) +pen = digitalio.DigitalInOut(board.GP16) +pen.direction = digitalio.Direction.OUTPUT +pen.value = False # Set pen to up position + +def message_handler(msg): + parts = msg.split(',') + if len(parts) != 3: + print("Invalid message format") + return + print(f"X: {parts[0]}, Y: {parts[1]}, Pen: {parts[2]}") + pwm_X.duty_cycle = int(parts[0]) + pwm_Y.duty_cycle = int(parts[1]) + pen.value = True if int(parts[2]) == 1 else False + +print("Booted") +while True: + if usb_cdc.data.in_waiting: + data = usb_cdc.data.read(usb_cdc.data.in_waiting) + message = data.decode('utf-8').strip() + message_handler(message) + time.sleep(0.5) + usb_cdc.data.write(b"OK\n") + time.sleep(0.1) \ No newline at end of file diff --git a/sd/placeholder.txt b/sd/placeholder.txt new file mode 100644 index 0000000..6e9754c --- /dev/null +++ b/sd/placeholder.txt @@ -0,0 +1 @@ +SD cards mounted at /sd will hide this file from Python. SD cards are not visible via USB CIRCUITPY. diff --git a/settings.toml b/settings.toml new file mode 100644 index 0000000..e69de29