Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

CircuitPython in VSCode - odd behaviour with Pico
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

CircuitPython in VSCode - odd behaviour with Pico

by wadewatts4030 on Wed Mar 17, 2021 8:56 am

Hi there :)

So i've set up my Pico in VSCode (MacOS Mojave) to work with CircuitPython and tried a code to test it.

Code: Select all | TOGGLE FULL SIZE
import microcontroller
import board

board_pins = []
for pin in dir(microcontroller.pin):
    if isinstance(getattr(microcontroller.pin, pin), microcontroller.Pin):
        pins = []
        for alias in dir(board):
            if getattr(board, alias) is getattr(microcontroller.pin, pin):
                pins.append("board.{}".format(alias))
        if len(pins) > 0:
            board_pins.append(" ".join(pins))
for pins in sorted(board_pins):
    print(pins)


i can't import board (Import "board" could not be resolved) but the odd thing is that the code works and pulls data from the board module... I'm a bit confused.

Here's a screenshot of the code with the terminal output:

Screenshot 2021-03-17 at 13.25.12.png
Screenshot 2021-03-17 at 13.25.12.png (361.1 KiB) Viewed 47 times


Could someone explain me what is going on there?

wadewatts4030
 
Posts: 2
Joined: Wed Mar 17, 2021 8:43 am

Re: CircuitPython in VSCode - odd behaviour with Pico

by blnkjns on Wed Mar 17, 2021 10:19 am

There is code-editing and code-running. VS Code does not run the code, but just tries to show it in a nice way and help you with correct writing habits.
The Pico is the thing RUNNING the code, so the Pico parser will decide whether or not it will import "board". So what happens is MakeCode does not recognize board, while the parser just likes it.
If you want the editor to give more feedback look at compiled code like c++.
Also give Thonny a try, I have the idea that program has the best tie with the Circuit Python on the Pi Pico on a Mac right now.

blnkjns
 
Posts: 455
Joined: Fri Oct 02, 2020 3:33 am

Re: CircuitPython in VSCode - odd behaviour with Pico

by wadewatts4030 on Wed Mar 17, 2021 6:07 pm

Ah! Thanks blnkjns :)
I wanted to have it in the same app as the rest of my dev projects in C++ but I'll give Thonny another chance.
Quite inexperienced with Python, actually so thanks for clarifying a few things here!
The main reason why i want to use Circuit/MicroPython on the Pico is to learn it and the nature of my project potentially lead to using CircuitPython.

Btw, would you not recommend Mu Editor over Thonny?

wadewatts4030
 
Posts: 2
Joined: Wed Mar 17, 2021 8:43 am

Re: CircuitPython in VSCode - odd behaviour with Pico

by blnkjns on Thu Mar 18, 2021 8:59 am

MU does not work on my Mac, it crashes on boot. It might work for you though.

blnkjns
 
Posts: 455
Joined: Fri Oct 02, 2020 3:33 am

Please be positive and constructive with your questions and comments.