Skip to content

Edit and Execute program

TakeoTakahashi2020 edited this page Sep 23, 2021 · 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

Note: about REPL

  • 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 128K
  • 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 Plus extension PyMakr can also be used to edit MicroPython programs.

Install Visual Studio Code + PyMakr

  • Install Visual Studio Code
  • Install Nodejs (6.9.5 or later) Maybe the latest version is fine
  • Install the PyMaker plugin in Visual Studio Code
    • Click the extended menu icon at the bottom left and enter PyMakr in the search field for EXTENSIONS: MARKET PLACE to install
  • Register the COM port of the target board in the PyMaker plug-in
    • In the View – Command Palette menu, select PyMakr – Global settings and set the COM port to xxxx for “address”: “xxxx” in the pimakr.json file.
  • PyMaker extension often doesn't work with certain versions of Visual Studio, so you need to check, such as google. For example, pymakr-1.1.6 and Visual Studio 1.52 work, but 1.53 doesn't.

PyMakr – Global settings

PyMakr Tips

  • The PyMakr files are located in the following folders.

    • C:\Users\xxxxxxx.vscode\extensions\pycom.pymakr-1.1.6
  • The PyMakr configuration file is located in the following folder.

    • C:\Users\xxxxxx.AppData\Roaming\Code\User
  • If the COM port connection is interrupted in a Windows environment, Comment out 4 lines from the line 139 of C: \ Users \ username \ .vscode \ extensions \ pycom.pymakr-1.1.6 \ lib (and \ src) \ connections \ pyserial.js.

  • If Upload fails, set upload_chunk_size from 512 to 256 in config.js.

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