ワンクリックで
circuitpython-runner
// Run CircuitPython code on a connected CircuitPython device and read the output. Use when testing CircuitPython code, debugging hardware interactions, or working with microcontrollers.
// Run CircuitPython code on a connected CircuitPython device and read the output. Use when testing CircuitPython code, debugging hardware interactions, or working with microcontrollers.
| name | circuitpython-runner |
| description | Run CircuitPython code on a connected CircuitPython device and read the output. Use when testing CircuitPython code, debugging hardware interactions, or working with microcontrollers. |
| license | MIT |
| metadata | {"version":"1.0","requires":["python3","circuitpython device"]} |
This skill enables you to run CircuitPython code on a connected CircuitPython device and capture the output.
Use this skill when you need to:
circuitpython_run_and_read_output.py script available in the skills scripts/ directoryThe CircuitPython device appears as a USB drive. Run the helper script to copy a code file to the device, execute it on the CircuitPython device and capture serial output.
Save your CircuitPython code to a local file in the working directory.
Example:
# Simple blink example
import time
import board
import digitalio
led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT
for i in range(5):
led.value = True
print(f"LED ON - iteration {i+1}")
time.sleep(0.5)
led.value = False
print(f"LED OFF - iteration {i+1}")
time.sleep(0.5)
print("Done!")
After saving the code, run the circuitpython_run_and_read_output.py script to copy the code, execute it and capture the device's output:
python3 circuitpython_run_and_read_output.py the_code_file.py
The script will:
# 1. Save your code to a local file
cat > example_code.py << 'EOF'
import time
print("Hello from CircuitPython!")
for i in range(3):
print(f"Count: {i}")
time.sleep(1)
print("Goodbye!")
EOF
# 2. Run the output reader
python3 circuitpython_run_and_read_output.py example_code.py
Put at the end of CircuitPython test scripts so that the runner script will be able to return without waiting the full duration when possible.
print("~~END~~")
import board
import adafruit_dht
dht = adafruit_dht.DHT22(board.D4)
try:
temperature = dht.temperature
humidity = dht.humidity
print(f"Temp: {temperature}°C, Humidity: {humidity}%")
except RuntimeError as e:
print(f"Error reading sensor: {e}")
import board
import busio
i2c = busio.I2C(board.SCL, board.SDA)
while not i2c.try_lock():
pass
print("I2C devices found:", [hex(addr) for addr in i2c.scan()])
i2c.unlock()
import board
import neopixel
pixels = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.3)
pixels[0] = (255, 0, 0) # Red
print("NeoPixel set to red")
time.sleep() appropriatelyprint("~~END~~") at end of scripts - Print this string to help the runner script finish faster when possible.CIRCUITPY/ is not accessible, as the user to check that the device is properly connected and recognized by the systemNo output received:
Script timeouts:
Help command:
--help argument to print information about the script and its parameters.