-
|
I'm fairly new to using VSC so I'm assuming I have made an error in the extension setup. When attempting to import built-in libraries, such as board or microcontroller, I recieve a matching 'ModuleNotFoundError', when using the 'Run Python File' button. I can open the serial console and import the same module with no errors. I can also reset the board from the serial console and see the output from main.py. When attempting to 'Run' a file from the IDE it seems as though the libraries are not accessible. I'm on Windows 11, microcontroller is a Pico2, and circuitpython is the newest stable release. I'm unsure if this is a bug, user error, or the expected result. I came across the guide for this on the Adafruit learn site and was hoping to move up from Thonny. I have also reinstalled VSC and tried both the 'user' install and the 'system' install, same result on both. Any information is greatly appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
|
The workflow is thus. Connect the MCU, such as your Pico-2, and from VSC, open the CIRCUITPY folder. The first time this is done, a .vscode folder is set up with Then edit the code.py and do whatever coding you want. As soon as it's saved, it runs. You do not need to manually run the code, such as using the run option under the RUN menu. You can open the REPL via a serial connection and see any messages from the code. If there are problems, error messages will display, telling you which line has an error. Also, pressing CTRL-C will stop the run, and pressing CTRL-D will start it again. |
Beta Was this translation helpful? Give feedback.
-
|
This is not the extension doing this, but the way Adafruit designed the run system in the CP. Specific files, such as code.py or main.py, which is a carryover from micropython from which CP is derived, are watched and re-run if changes are detected. Yes, making parts into something .py and doing an import is good practice, but it does not lead to the module files running standalone under the autorun system of CP. The best way to do this is to ask how to handle this in Discord on the Adafruit channel. http://adafru.it/discord |
Beta Was this translation helpful? Give feedback.
-
|
Just be aware that Thonny, or Mu, one of the two, is being Deprecated and will stop being supported this year. This is why Adafruit is focusing heavily on this extension; they are considering having people use VSC and this extension as the base IDE for doing CP. You don't need to apologize; this is a problem I understand from first wanting to break code apart. I come from a C background, and this is standard practice. |
Beta Was this translation helpful? Give feedback.
The workflow is thus.
Connect the MCU, such as your Pico-2, and from VSC, open the CIRCUITPY folder. The first time this is done, a .vscode folder is set up with
a settings.json file holding some settings, then pick the MCU from the bottom right of VSC; this sets some more stuff up in the now created .vscode/settings.json.
Then edit the code.py and do whatever coding you want. As soon as it's saved, it runs.
You do not need to manually run the code, such as using the run option under the RUN menu.
You can open the REPL via a serial connection and see any messages from the code. If there are problems, error messages will display, telling you which line has an error. Also, pressing CTRL-C w…