I'm connecting to a raspberry pi PICO. I've used Thonny for weeks successfully untill today. I have been unable lately to save py files to the device. I am running micropython fresh install today. rp2-pico-w-20221220-unstable-v1.19.1-782-g699477d12.uf2.
I'm running MACOS 12.5.1 - Monterey
I get the following error:
Could not write next block after having written 0 bytes to /sensor_loop_with_web.py
PROBLEM IN THONNY'S BACK-END: Exception while handling 'write_file' (OSError: [Errno Could not complete file writing] __W(b'from machine import Pin, WDT\nimport utime, time\nimport network, urequests\n\nwatch_dog = WDT(timeout = 8000)\nmin_dist = 5.0\ntarget_dist = 6.0\nmax_dist = 7.0\nlast_distance = 0\n\nbeeper = Pin(0, Pin.OUT) # GP0\ntrigger = Pin(22, Pin.OUT) # GP22\necho = Pin(7, Pin.IN) # GP 7\nled_target = Pin(3, Pin.OUT) # GP3\nled_too_far = Pin(4, Pin.OUT)# GP4\nled_too_close = Pin(5, Pin.OUT) # GP5\ntarget_set_button = Pin(6, Pin.IN, Pin.PULL_UP) # GP6\nonboard_led = Pin("LED", Pin.OUT) # onboard LED\nfileName = "dim_settings.txt"\non_target_beeps = 0\n\n\ndef measure_distance():\n global last_distance\n onboard_led.value(1)\n \n trigger.low()\n utime.sleep_us(2)\n trigger.high()\n utime.sleep_us(5)\n trigger.low()\n \n while echo.value() == 0:\n signaloff = utime.ticks_us()\n while echo.value() == 1:\n signalon = utime.ticks_us()\n timepassed = signalon - signaloff\n distance = (timepassed * 0.0343) / 2\n print("The distance from object is ",distance,"cm")\n \n distanceInInches = round(distance / 2'): '').
See Thonny's backend.log for more info.
You may need to press "Stop/Restart" or hard-reset your MicroPython device and try again.
Process ended with exit code 1.
The BACKEND.log shows the following:
12:35:57.779 INFO thonny: Thonny version: 4.0.1
12:35:57.779 INFO thonny: cwd: /
12:35:57.779 INFO thonny: original argv: ['/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.10/Resources/Python.app/Contents/MacOS/Python', '-u', '-B', '/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/thonny/plugins/rp2040/rp2040_back.py', "{'clean': True, 'port': '/dev/cu.usbmodem14343401', 'dtr': None, 'rts': None, 'submit_mode': 'raw_paste', 'interrupt_on_connect': True, 'write_block_size': 64, 'write_block_delay': None, 'proxy_class': 'RaspberryPiPicoBackendProxy', 'sync_time': True, 'validate_time': False, 'local_rtc': True}"]
12:35:57.779 INFO thonny: sys.executable: /Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.10/bin/python3.10
12:35:57.779 INFO thonny: sys.argv: ['/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/thonny/plugins/rp2040/rp2040_back.py', "{'clean': True, 'port': '/dev/cu.usbmodem14343401', 'dtr': None, 'rts': None, 'submit_mode': 'raw_paste', 'interrupt_on_connect': True, 'write_block_size': 64, 'write_block_delay': None, 'proxy_class': 'RaspberryPiPicoBackendProxy', 'sync_time': True, 'validate_time': False, 'local_rtc': True}"]
12:35:57.779 INFO thonny: sys.path: ['/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/thonny/plugins/rp2040', '/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.10/lib/python310.zip', '/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.10/lib/python3.10', '/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.10/lib/python3.10/lib-dynload', '/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages']
12:35:57.779 INFO thonny: sys.flags: sys.flags(debug=0, inspect=0, interactive=0, optimize=0, dont_write_bytecode=1, no_user_site=0, no_site=0, ignore_environment=0, verbose=0, bytes_warning=0, quiet=0, hash_randomization=1, isolated=0, dev_mode=False, utf8_mode=0, warn_default_encoding=0)
12:35:57.779 INFO thonny.plugins.micropython.bare_metal_backend: Starting backend, args: {'clean': True, 'port': '/dev/cu.usbmodem14343401', 'dtr': None, 'rts': None, 'submit_mode': 'raw_paste', 'interrupt_on_connect': True, 'write_block_size': 64, 'write_block_delay': None, 'proxy_class': 'RaspberryPiPicoBackendProxy', 'sync_time': True, 'validate_time': False, 'local_rtc': True}
12:35:57.784 INFO thonny.plugins.micropython.bare_metal_backend: Initial submit_mode: raw_paste, write_block_size: 64, write_block_delay: 0, read_block_size: 0
12:35:57.784 INFO thonny.plugins.micropython.mp_back: Initializing MicroPythonBackend of type RP2040Backend
12:35:57.784 INFO thonny: TIME/MODS 0.077 before prepare (+73 modules)
12:35:57.784 INFO thonny: NEW MODS ['future', '_bz2', '_compression', '_datetime', '_heapq', '_lzma', '_posixsubprocess', '_queue', '_struct', '_tkinter', 'array', 'binascii', 'bz2', 'datetime', 'encodings.ascii', 'errno', 'faulthandler', 'fcntl', 'fnmatch', 'gettext', 'heapq', 'lzma', 'math', 'ntpath', 'pathlib', 'platform', 'queue', 'select', 'selectors', 'serial', 'serial.serialposix', 'serial.serialutil', 'shlex', 'shutil', 'signal', 'struct', 'subprocess', 'termios', 'textwrap', 'thonny.backend', 'thonny.base_file_browser', 'thonny.codeview', 'thonny.config_ui', 'thonny.editors', 'thonny.languages', 'thonny.misc_utils', 'thonny.plugins', 'thonny.plugins.backend_config_page', 'thonny.plugins.micropython', 'thonny.plugins.micropython.bare_metal_backend', 'thonny.plugins.micropython.connection', 'thonny.plugins.micropython.mp_back', 'thonny.plugins.micropython.mp_common', 'thonny.plugins.micropython.mp_front', 'thonny.plugins.micropython.serial_connection', 'thonny.plugins.micropython.webrepl_connection', 'thonny.roughparse', 'thonny.running', 'thonny.tktextext', 'thonny.ui_utils', 'thonny.workdlg', 'tkinter', 'tkinter.commondialog', 'tkinter.constants', 'tkinter.dialog', 'tkinter.filedialog', 'tkinter.font', 'tkinter.messagebox', 'tkinter.simpledialog', 'tkinter.ttk', 'urllib', 'urllib.parse', 'zlib']
12:35:57.785 INFO thonny.plugins.micropython.mp_back: Sending interrupt
12:35:57.785 INFO thonny.plugins.micropython.mp_back: Done sending interrupt
12:35:57.836 INFO thonny.plugins.micropython.bare_metal_backend: Poking
12:35:57.875 INFO thonny.plugins.micropython.bare_metal_backend: Discarding stdout: 'OK\r\n'
12:35:57.875 INFO thonny.plugins.micropython.bare_metal_backend: Discarding stdout: 'MPY: soft reboot\r\n'
12:35:57.890 INFO thonny.plugins.micropython.bare_metal_backend: Discarding stdout: ''
12:35:57.903 INFO thonny: TIME/MODS 0.119 got welcome
12:35:57.903 INFO thonny: TIME/MODS 0.000 bef preparing helpers
12:35:57.903 INFO thonny.plugins.micropython.mp_back: Preparing helpers
12:35:57.904 INFO thonny: TIME/MODS 0.001 befsubcode
12:35:57.905 INFO thonny.plugins.micropython.bare_metal_backend: Discarding stdout: '\r\n'
12:35:57.916 INFO thonny.plugins.micropython.bare_metal_backend: Discarding stdout: ''
12:35:57.954 INFO thonny: TIME/MODS 0.050 affsubcode
12:35:58.034 INFO thonny: TIME/MODS 0.080 affforw
12:35:58.034 INFO thonny: TIME/MODS 0.000 prepared helpers
12:35:58.034 INFO thonny: TIME/MODS 0.000 befsubcode
12:35:58.036 INFO thonny: TIME/MODS 0.002 affsubcode
12:35:58.051 INFO thonny: TIME/MODS 0.015 affforw
12:35:58.051 INFO thonny: TIME/MODS 0.000 got cwd
12:35:58.051 INFO thonny: TIME/MODS 0.000 befsubcode
12:35:58.054 INFO thonny: TIME/MODS 0.002 affsubcode
12:35:58.067 INFO thonny: TIME/MODS 0.013 affforw
12:35:58.067 INFO thonny: TIME/MODS 0.000 prepared
12:35:58.067 INFO thonny.plugins.micropython.mp_back: Prepared
12:35:58.067 INFO thonny: TIME/MODS 0.000 befsubcode
12:35:58.069 INFO thonny: TIME/MODS 0.002 affsubcode
12:35:58.092 INFO thonny: TIME/MODS 0.022 affforw
12:35:58.092 INFO thonny: TIME/MODS 0.000 befsubcode
12:35:58.099 INFO thonny: TIME/MODS 0.007 affsubcode
12:35:58.135 INFO thonny: TIME/MODS 0.036 affforw
12:35:58.135 INFO thonny: TIME/MODS 0.000 befsubcode
12:35:58.146 INFO thonny: TIME/MODS 0.011 affsubcode
12:35:58.181 INFO thonny: TIME/MODS 0.035 affforw
12:35:58.181 INFO thonny.backend: Loading Jedi
12:35:58.181 INFO thonny: TIME/MODS 0.000 Before loading Jedi
12:35:58.181 INFO thonny.common: Using THONNY_FRONTEND_SYS_PATH ['/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.10/lib/python310.zip', '/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.10/lib/python3.10', '/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.10/lib/python3.10/lib-dynload', '/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages', '/Users/jonclayton/Library/Thonny/plugins/lib/python/site-packages']
12:35:58.264 INFO thonny: TIME/MODS 0.083 After loading Jedi (+125 modules)
12:35:58.264 INFO thonny: NEW MODS ['_blake2', '_compat_pickle', '_json', '_md5', '_osx_support', '_pickle', '_sha1', '_sha256', '_sha3', '_sha512', '_sysconfigdata__darwin_darwin', 'difflib', 'filecmp', 'gc', 'hashlib', 'importlib._abc', 'importlib.util', 'jedi', 'jedi._compatibility', 'jedi.api', 'jedi.api.classes', 'jedi.api.completion', 'jedi.api.completion_cache', 'jedi.api.environment', 'jedi.api.errors', 'jedi.api.exceptions', 'jedi.api.file_name', 'jedi.api.helpers', 'jedi.api.interpreter', 'jedi.api.keywords', 'jedi.api.project', 'jedi.api.refactoring', 'jedi.api.refactoring.extract', 'jedi.api.strings', 'jedi.cache', 'jedi.common', 'jedi.debug', 'jedi.file_io', 'jedi.inference', 'jedi.inference.analysis', 'jedi.inference.arguments', 'jedi.inference.base_value', 'jedi.inference.cache', 'jedi.inference.compiled', 'jedi.inference.compiled.access', 'jedi.inference.compiled.getattr_static', 'jedi.inference.compiled.mixed', 'jedi.inference.compiled.subprocess', 'jedi.inference.compiled.subprocess.functions', 'jedi.inference.compiled.value', 'jedi.inference.context', 'jedi.inference.docstring_utils', 'jedi.inference.docstrings', 'jedi.inference.filters', 'jedi.inference.flow_analysis', 'jedi.inference.gradual', 'jedi.inference.gradual.annotation', 'jedi.inference.gradual.base', 'jedi.inference.gradual.conversion', 'jedi.inference.gradual.generics', 'jedi.inference.gradual.stub_value', 'jedi.inference.gradual.type_var', 'jedi.inference.gradual.typeshed', 'jedi.inference.gradual.typing', 'jedi.inference.gradual.utils', 'jedi.inference.helpers', 'jedi.inference.imports', 'jedi.inference.lazy_value', 'jedi.inference.names', 'jedi.inference.param', 'jedi.inference.parser_cache', 'jedi.inference.recursion', 'jedi.inference.references', 'jedi.inference.signature', 'jedi.inference.syntax_tree', 'jedi.inference.sys_path', 'jedi.inference.utils', 'jedi.inference.value', 'jedi.inference.value.decorator', 'jedi.inference.value.dynamic_arrays', 'jedi.inference.value.function', 'jedi.inference.value.instance', 'jedi.inference.value.iterable', 'jedi.inference.value.klass', 'jedi.inference.value.module', 'jedi.parser_utils', 'jedi.plugins', 'jedi.plugins.django', 'jedi.plugins.flask', 'jedi.plugins.pytest', 'jedi.plugins.registry', 'jedi.plugins.stdlib', 'jedi.settings', 'json', 'json.decoder', 'json.encoder', 'json.scanner', 'parso', 'parso._compatibility', 'parso.cache', 'parso.file_io', 'parso.grammar', 'parso.normalizer', 'parso.parser', 'parso.pgen2', 'parso.pgen2.generator', 'parso.pgen2.grammar_parser', 'parso.python', 'parso.python.diff', 'parso.python.errors', 'parso.python.parser', 'parso.python.pep8', 'parso.python.prefix', 'parso.python.token', 'parso.python.tokenize', 'parso.python.tree', 'parso.tree', 'parso.utils', 'pickle', 'pkgutil', 'pydoc', 'pydoc_data', 'pydoc_data.topics', 'sysconfig', 'zipfile']
12:35:58.264 INFO thonny: TIME/MODS 0.000 sent ready
12:35:58.264 INFO thonny: TIME/MODS 0.000 Beginning of mainloop
12:35:58.264 INFO thonny: TIME/MODS 0.000 before get_dirs_children_info
12:35:58.265 INFO thonny: TIME/MODS 0.000 befsubcode
12:35:58.278 INFO thonny: TIME/MODS 0.013 affsubcode
12:35:58.343 INFO thonny: TIME/MODS 0.065 affforw
12:35:58.344 INFO thonny: TIME/MODS 0.001 after get_dirs_children_info
12:35:58.355 INFO thonny: TIME/MODS 0.011 before get_globals
12:35:58.355 INFO thonny: TIME/MODS 0.000 befsubcode
12:35:58.365 INFO thonny: TIME/MODS 0.010 affsubcode
12:35:58.378 INFO thonny: TIME/MODS 0.013 affforw
12:35:58.378 INFO thonny: TIME/MODS 0.000 after get_globals
12:36:00.728 INFO thonny: TIME/MODS 2.350 before read_file
12:36:00.728 INFO thonny: TIME/MODS 0.000 befsubcode
12:36:00.731 INFO thonny: TIME/MODS 0.003 affsubcode
12:36:00.749 INFO thonny: TIME/MODS 0.018 affforw
12:36:00.750 INFO thonny: TIME/MODS 0.000 befsubcode
12:36:00.763 INFO thonny: TIME/MODS 0.014 affsubcode
12:36:00.774 INFO thonny: TIME/MODS 0.011 affforw
12:36:00.774 INFO thonny: TIME/MODS 0.000 befsubcode
12:36:00.777 INFO thonny: TIME/MODS 0.002 affsubcode
12:36:00.794 INFO thonny: TIME/MODS 0.018 affforw
12:36:00.795 INFO thonny: TIME/MODS 0.000 befsubcode
12:36:00.797 INFO thonny: TIME/MODS 0.002 affsubcode
12:36:00.811 INFO thonny: TIME/MODS 0.014 affforw
12:36:00.811 INFO thonny: TIME/MODS 0.000 befsubcode
12:36:00.814 INFO thonny: TIME/MODS 0.003 affsubcode
12:36:00.827 INFO thonny: TIME/MODS 0.012 affforw
12:36:00.827 INFO thonny.plugins.micropython.bare_metal_backend: Read /sensor_loop_with_web.py in 0.1 seconds
12:36:00.827 INFO thonny: TIME/MODS 0.000 after read_file
12:36:01.226 INFO thonny: TIME/MODS 0.399 before highlight_occurrences
12:36:01.391 INFO thonny: TIME/MODS 0.165 after highlight_occurrences (+1 modules)
12:36:01.391 INFO thonny: NEW MODS ['thonny.jedi_utils']
12:36:16.159 INFO thonny: TIME/MODS 14.769 before get_dirs_children_info
12:36:16.160 INFO thonny: TIME/MODS 0.000 befsubcode
12:36:16.172 INFO thonny: TIME/MODS 0.013 affsubcode
12:36:16.236 INFO thonny: TIME/MODS 0.064 affforw
12:36:16.236 INFO thonny: TIME/MODS 0.000 after get_dirs_children_info
12:36:21.117 INFO thonny: TIME/MODS 4.881 before write_file
12:36:21.118 INFO thonny: TIME/MODS 0.000 befsubcode
12:36:21.129 INFO thonny: TIME/MODS 0.011 affsubcode
12:36:21.164 INFO thonny: TIME/MODS 0.036 affforw
12:36:21.165 INFO thonny: TIME/MODS 0.000 befsubcode
12:36:21.169 INFO thonny: TIME/MODS 0.005 affsubcode
12:36:21.187 INFO thonny: TIME/MODS 0.017 affforw
12:36:21.187 INFO thonny: TIME/MODS 0.000 befsubcode
12:36:21.195 INFO thonny: TIME/MODS 0.008 affsubcode
12:36:21.207 INFO thonny: TIME/MODS 0.012 affforw
12:36:21.207 INFO thonny: TIME/MODS 0.000 befsubcode
12:36:21.218 INFO thonny: TIME/MODS 0.010 affsubcode
12:36:21.250 INFO thonny: TIME/MODS 0.033 affforw
12:36:21.251 ERROR thonny.backend: Exception while handling 'write_file'
Traceback (most recent call last):
File "/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/thonny/backend.py", line 282, in _handle_normal_command
response = handler(cmd)
File "/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/thonny/plugins/micropython/bare_metal_backend.py", line 1094, in _cmd_write_file
return super(BareMetalMicroPythonBackend, self)._cmd_write_file(cmd)
File "/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/thonny/backend.py", line 568, in _cmd_write_file
self._write_file(
File "/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/thonny/plugins/micropython/bare_metal_backend.py", line 1267, in _write_file
self._write_file_via_serial(source_fp, target_path, file_size, callback)
File "/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/thonny/plugins/micropython/bare_metal_backend.py", line 1396, in _write_file_via_serial
raise OSError("Could not complete file writing", script, out, err)
OSError: [Errno Could not complete file writing] __W(b'from machine import Pin, WDT\nimport utime, time\nimport network, urequests\n\nwatch_dog = WDT(timeout = 8000)\nmin_dist = 5.0\ntarget_dist = 6.0\nmax_dist = 7.0\nlast_distance = 0\n\nbeeper = Pin(0, Pin.OUT) # GP0\ntrigger = Pin(22, Pin.OUT) # GP22\necho = Pin(7, Pin.IN) # GP 7\nled_target = Pin(3, Pin.OUT) # GP3\nled_too_far = Pin(4, Pin.OUT)# GP4\nled_too_close = Pin(5, Pin.OUT) # GP5\ntarget_set_button = Pin(6, Pin.IN, Pin.PULL_UP) # GP6\nonboard_led = Pin("LED", Pin.OUT) # onboard LED\nfileName = "dim_settings.txt"\non_target_beeps = 0\n\n\ndef measure_distance():\n global last_distance\n onboard_led.value(1)\n \n trigger.low()\n utime.sleep_us(2)\n trigger.high()\n utime.sleep_us(5)\n trigger.low()\n \n while echo.value() == 0:\n signaloff = utime.ticks_us()\n while echo.value() == 1:\n signalon = utime.ticks_us()\n timepassed = signalon - signaloff\n distance = (timepassed * 0.0343) / 2\n print("The distance from object is ",distance,"cm")\n \n distanceInInches = round(distance / 2'): ''