Basic VS Code use and setup

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
andymouse
Posts: 12
Joined: Sat Apr 06, 2019 7:05 pm

Basic VS Code use and setup

Post by andymouse » Wed Apr 10, 2019 11:01 am

Hi,
In order to follow a tutorial I want to use Visual Studio Code, and when I open a Terminal, Windows 10, Power Shell is running and I will need to get used to its commands, but I would like to be able to tell it which serial port I am using just to get me moving with Micropython and have basic operation of my board all under one roof (so to speak!)
So my question is how do I tell it I'm on comm3 ? and get access to the Repl, also, what is the best place to find PS commands and explanations. Every journey and all that!
If you think Power Shell is a bad Idea for someone starting out please say so and put me straight. Please give as much detail as you can (you CAN teach an old dog new tricks, but slowly!)

Thanks.
Andy

User avatar
dhylands
Posts: 3117
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Basic VS Code use and setup

Post by dhylands » Wed Apr 10, 2019 1:45 pm

I wrote a python program I call find_port.py. You can find a copy of it here: https://github.com/dhylands/dotfiles/bl ... nd_port.py

It should work on Windows, Mac, or Linux. If you run

Code: Select all

find_port.py -l
then it should list all of the USB serial devices. For example, under Windows 10, I tested this in PowerShell with a SparkFun ESP32 Thing plugged in:

Code: Select all

PS C:\Users\dhyla\bin> python .\find_port.py -l
USB Serial Device 1027:24597 with vendor 'FTDI' serial 'DN02Z2XCA' found @COM5
You can also go into Device Manager, click on "Ports (COM & LPT)" and in my case it shows "USB Serial Port (COM5)"

andymouse
Posts: 12
Joined: Sat Apr 06, 2019 7:05 pm

Re: Basic VS Code use and setup

Post by andymouse » Wed Apr 10, 2019 2:19 pm

hi
Thanks, but I no which port I need its much simpler than that, I just dont no what to type in power shell to use the terminal and have the Repl command line, I realy am this new! I am in VScode and I have:-

PS C:\Users\andy>

I dont no where to go from here, and why I am doing it, I believe I have to point the terminal at a path to the com port maybe type "-p" or "com3"
something like that so I need a little jog to get me going! I will invest time in PowerShell, but for the moment I want to communicate with my board in the same manner as "Putty" but in the VisualCode environment using its terminal, I did use device manager to find my CH340 device, but I am not used to "command line" work, and any help you can give would be great as I'm itching to move on.

Andy

User avatar
dhylands
Posts: 3117
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Basic VS Code use and setup

Post by dhylands » Wed Apr 10, 2019 2:53 pm

Basically, you need to execute a command line terminal program and pass whatever arguments that particular command line terminal program wants. Most terminal programs (like putty) for Windows are GUI based and not command line based.

However, python includes one called miniterm which comes with pyserial.

From powershell, I was able to execute: python -m serial.tools.miniterm COM5 115200 and get a REPL.

Code: Select all

PS C:\Users\dhyla> python -m serial.tools.miniterm COM5 115200
--- Miniterm on COM5  115200,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---

>>>
--- exit ---
You'll probably need to press RETURN to get the >>> prompt or perhaps press Control-C if you have a main.py that runs something on the board. You could also use rshell. You would run rshell -p COM5 This would get you to an rshell prompt where you can enter rshell commands to copy files into and out of the micropython filesystem, or use the repl command to get into a micropyton repl.

Code: Select all

PS C:\Users\dhyla> rshell -p COM5
Using buffer-size of 32
Connecting to COM5 (buffer-size 32)...
Trying to connect to REPL  connected
Testing if ubinascii.unhexlify exists ... Y
Retrieving root directories ... /flash/
Setting time ... Apr 10, 2019 07:47:50
Evaluating board_name ... pyboard
Retrieving time epoch ... Jan 01, 1970
Welcome to rshell. Use the exit command to exit rshell.
C:\Users\dhyla> repl
Entering REPL. Use Control-X to exit.
>
MicroPython ESP32_LoBo_v3.2.12 - 2018-04-18 on ESP32 board with ESP32
Type "help()" for more information.
>>>
>>>
C:\Users\dhyla>
PS C:\Users\dhyla>
If you are going to use rshell to copy files in and out of the micropython board, then I recommend disabling USB mass storage.

andymouse
Posts: 12
Joined: Sat Apr 06, 2019 7:05 pm

Re: Basic VS Code use and setup

Post by andymouse » Wed Apr 10, 2019 6:36 pm

Hi
Your a rock star! that does indeed get me to the Repl and I have switched an LED off, so very close, however (you where waiting for that!) I have some problems.
the "back space" key doesn't work, I just get a strange graphic, for instance if I type "import" wrong, and press the backspace key I get:-

>>> impor␛[␛[␛[␛[K

also the "delete" key gives me a capital "S"

When I go back to Putty all is ok. And as long as I dont make any mistakes all appears well from VScode as well:-

>>> import os
>>> os.listdir()
['boot.py', 'main.py']
>>> import machine
>>> from machine import Pin
>>> led = Pin(2,Pin.OUT)
>>> led.on()
>>> led.off()
>>> led.value(True)
>>> led.value(False)
>>> led.value(1)
>>> led.value(0)
>>>

I realy thought I was there, please can you help me a bit further and give me your thoughts on the problems. I am from "Arduino land" and I guess I'm used to having this stuff done for me! buy the IDE, but I am a willing student.
Thanks
Andy

Post Reply