Skip to content

Edit and Execute program

Takeo Takahashi edited this page Jan 20, 2022 · 9 revisions

How to use

  • Launch Tera Term, select the recognized COM port, select the Setup – Serial port menu, select 115200 for Baud rate, and press Enter. You should see the MicroPython REPL prompt >>.

    • Supports RA4M1 and RA6M2 (RA4W1 and RA6M1 have not been tested). You can run MicroPython programs from this console.

First Sample - LED Blinking

  • As a first sample, let's turn on the LED on the target board.
  • Input following program.
  • Inputting Enter key several times, the program will runs.
  • Input Ctrl-C to exit the program.
import pyb
while True:
  pyb.LED(1).toggle()
  pyb.delay(50)

image

Copy and paste in REPL prompt

  • When copy and paste an indented program, it is convenient to press Ctrl-E and then Paste.

  • Run the program with Ctrl-D.

  • Stop the program with Ctrl-C.

  • Then press Ctrl-D to reboot the software.

Storage

  • In the implementation of the target board, the built-in Flash and SD card can be used as storage.
  • Built-in flash
    • RA4M1 Clicker 0x00037000 to 36KB, EK-RA6M2 0x000E0000 to 256KB
  • At startup, it becomes the default folder of "/flash", and after initialization, two files, boot.py and main.py, are placed.
    • You can run the program at startup by updating main.py.
  • To use the SD card, you need to connect the SD card separately. (Details will be explained separately). In that case, the "/sd" folder will be the default folder.
import os
os.listdir('/')

Program editing with Visual Studio Code + Pymakr

In addition to TeraTerm, Visual Studio Code and Pymakr extension can also be used to edit MicroPython programs.

Install Visual Studio Code + Pymakr

  • Install Visual Studio Code
  • Install Nodejs (16.9.5 or later)
    The latest version is probably fine
  • Install the Pymakr extension in Visual Studio Code
    • Click the extended menu icon at the left menu and enter Pymakr in the search field for EXTENSIONS: MARKET PLACE to install
  • Open Device Manager on Windows and confirm USB-to-Serial Comm port manufacturer name to connect the target board.
  • Register the manufacturer name in the Pymakr extension file
    • In the "Command Palette..." of View menu, select "Pymakr > Global settings" and insert the manufacturer name to the top of the list for "autoconnect_comport_manufacturers" in the pymakr.json file.
    • For example, if you want to connect the "Prolific" comport in the Device Manager, insert "Prolific" to the top of the list as follows:
  • Click "Pymakr Console" in Pymakr menu at left-bottom or restart Visual Studio Code, then COM port is automatically searched and connected:

  • If you want to connect manually, specify "COM9" for "address" and "false" for "auto_connect", then click "Pymakr Console" in Pymakr menu to connect/disconnect.

      ...
      "address": "COM9",
      ...
      ...
      "auto_connect": false,
      ...
    
    

Edit a program in Jupyter Notebook

  • Install Jupyter Notebook

    • Windows10
    • Python 3.8.8
      python -m pip install jupyter
      pip install --upgrade jupyter_client
      pip install jupyter_micropython_kernel
      jupyter kernelspec list
      jupyter notebook
      
  • The browser will start

  • Select “MicroPython – USB” from New at the top right of the page

  • Enter the following command in a cell of the new page

    %serialconnect to –port=COMx –baud=115200
    
  • MicroPython code can be executed in cells


Home

ホーム

Clone this wiki locally