###### tags: `TA Stuff 2021` `Pycom` `ESP32`
# VSCode & Pymakr Step-By-Step Tutorial For Windows
## Before Starting:
Make sure to quickly read through all the steps described below so that you have a general understanding of what you are going to be doing before you start following along.
We will be going through these steps in the first workshop so don't worry if you don't get it to work. We will be helping you!
## 1. Installing VSCode
We will start by going to the [VSCode setup page for windows](https://code.visualstudio.com/docs/setup/windows). Follow the first three steps. You can read the rest of the page to get more information but it is not necessary.
1. Once you start the installer you will be asked to accept the license agreement:

2. Next you will be asked to pick where you want VSCode to be installed. We recommend leaving it as is. \[Yours might look different since you might have a different username\]

3. Now you can choose if you want to create a shortcut for VSCode in the start menu. We recommend doing that but if you do not want to, you can check the "Don't create a Start Menu folder" checkbox.

4. In this step you have a few decisions to make. We recommend the same settings as in the picture below but you might want to take the time to decide for yourself.

- The "Create a desktop icon" option is self-explanatory and is recommended but you can always create one yourself later if you do not want to clutter the desktop. However make sure to have at least a **Start Menu shortcut** (from step 3) or a **Desktop shortcut**.
- The second and third option creates a new context menu item to open a folder/directory or a file in vscode. (Recommended)

- The forth option will set VSCode as the default program for any file extension that vscode supports which might be unwanted since although VSCode is quite fast it might not be as fast as a simpler notepad program. So you might want to leave that one unchecked.
- The last option adds VSCode to the system path which means that running the "code" command in the command prompt will open VSCode in that directory. Since it could be useful we recommend checking that option.
If you change your mind later you can always re-run the setup and enable some of these options.
Now all you need to do is click the install button and the setup should finish successfully.


## 2. Setting Up The Environment
### Installing NodeJS:
1. Go to https://nodejs.org/en/
2. Click on the green button with LTS in the version name.

3. Once the download is done, run the installation and click the "Next" button.

4. Accept the license agreement and click "Next".

5. Here you can specify the installation path. We recommend leaving it as is.

6. Make sure all the packages are marked to be installed (looks something like the image below).

7. You can check the box to install additional software/scripts that are required by some packages but for our use case it won't be necessary.

8. Now you can start the installation.
9. Once the installation is done you need to restart your PC.
### Installing The Pymakr Extension:
Now you can go to https://docs.pycom.io/gettingstarted/software/vscode/ and follow the steps 3 to 6
You already followed the first 2 steps but in more details by following the previous steps in this tutorial.
After you followed the steps 3-6 you should have the Pymakr extension up and running.
If you get an error saying that no NodeJS installation is detected then make sure you have installed NodeJS correctly and that the add to path option is included in the installation. (Steps 3-9 in the Installing NodeJS section)
## 3. Connecting to the Lopy
Now we need to configure VSCode to connect to our Lopy device.
By default the Pymakr extension should automatically detect any connected Lopy devices, but if it does not, please follow the following steps:
1. Find the COM port (serial port) your Lopy is connected to. You do that by pressing `CTRL + SHIFT + P` on your keyboard. This will open the [Command Palette](https://code.visualstudio.com/docs/getstarted/tips-and-tricks#_command-palette) . When using VSCode this palette is super helpful since you can find all the commands and settings by searching through it. So start by typing the word "List" and you should find similar results to those in the picture:

2. As you can see, every command belongs to some kind of extension. The first 2 are from the Pymakr extension and the one we are looking for is the second one: "Pymakr > Extra > List serial ports". By executing this command we will get a list of all the detected serial devices.

3. Copy the port name (if not copied automatically) so that we can insert it into the settings.
4. We open the [Command Palette](https://code.visualstudio.com/docs/getstarted/tips-and-tricks#_command-palette) again by pressing the `CTRL + SHIFT + P` shortcut and type "Global settings". We should see a result from Pymakr.

1. This will open the global settings which apply for all the Pymakr project. There are also settings per project which can be found by searching for project settings instead. *Project settings are useful in case you want to change a specific setting for that specific project only.* Now we can modify the **address** filed in the settings file to the port name we got from step 2. Save the file `Ctrl+S`

Now you should be all set up and ready to communicate with the Lopy.
So let's test it out!
Open the Pymakr Console by clicking on the button in the bottom bar

Type `print("Hello World!")` (case sensitive) and you should get the following result:

If any errors come up please let us know and we will be happy to help 😸
Now we can move on to running actual python files:
1. Start by opening a folder by going to `File > Open Folder` or By clicking on the "Open folder" button in the welcome screen.

2. Click the "New Folder" button at the top and give your folder a name. For example "pytest".
3. Select that folder to be opened in VSCode.

4. Click the add file button in the side bar. If the Side bar is hidden press `CTRL + B` to toggle it.

5. Name the file `main.py` and paste the following code in it [Original code source](https://pycom.github.io/pydocs/gettingstarted/programming/first-project.html):
```python=
import pycom
import time
pycom.heartbeat(False)
while True:
pycom.rgbled(0xFF0000) # Red
time.sleep(1)
pycom.rgbled(0x00FF00) # Green
time.sleep(1)
pycom.rgbled(0x0000FF) # Blue
time.sleep(1)
```
6. Run the code by pressing the "Run" Button in the bottom bar.

7. Now you LED should be blinking in different colors. If not make sure you have copied the code correctly and that no lines are selected in the code. Otherwise Pycom will only run the lines you have highlighted.
8. To stop the code press `CTRL + C` in the console window. (It might need some spamming 😅 )
9. Once the code is stopped you might notice that the LED stays on. To turn it off we can run some python code directly in the console. Type `pycom.heartbeat(True)` and press `Enter`. This will reset the LED back to the default heartbeat behaviour. If you get an Error about a missing pycom package run: `import pycom` before running the heartbeat command.
Now you are all setup 😁
Make sure to give us feedback and leave comments if anything is not fully clear, and good luck with your future projects!