-
Notifications
You must be signed in to change notification settings - Fork 3
MicroPython Library
-
There are two types of modules (function and class libraries) built into MicroPython.
- An implementation of a subset of standard Python functionality
- Standard Python (called CPython) module names and module names with ‘u’ at the beginning (eg os and uos)
- What the user can and cannot extend with Python code.
- Modules specific to a particular MicroPython port
- The module name and usage (API) are different for each MCU. --In RA MCU, the pyb module and the rab module are the same
- Modules specific to the target board (eg pyb, rab, esp32…) and modules common to the target board (eg machine)
- An implementation of a subset of standard Python functionality
-
You can check the modules available on the board with help (“module”).
-
The modules that can be used differ between the RA4M1 Clicker board and the EK-RA6M2 board.
- Due to the Flash capacity limit, the modules installed on the RA4M1 Clicker board are limited.
-
For more information on the modules built into MicroPython, see the url below
Pyb module | Rab module | description |
---|---|---|
Accel | Not implemented | Accelerometer |
ADC | ADC | AD converter |
CAN | Not implemented | CAN (controller area network communication bus) |
DAC | Not implemented | DA converter |
ExtInt | ExtInt | External interrupt by I / O pin |
I2C | I2C | I2C (a two-wire serial protocol) |
LCD | Not implemented | LCD control |
LED | LED | LED object |
Pin | Pin | I/O pin |
PinAF | Not implemented | Pin peripheral function |
RTC | RTC | Real Time Controller |
Servo | Not implemented | Servo (PWM) |
SPI | SPI | SPI (a master-driven serial protocol) |
Switch | Switch | Switch |
Timer | Timer | Timer |
TimerChannel | No functionality | Channel settings for timers |
UART | UART | Serial Communication |
USB_HID | Not implemented | USB Human Interface Device (HID) |
USB_VCP | Not implemented | USB Virtual COM port |
- Software Timer: Definition is a function that decides whether to execute the registered task every 1ms based on the 1ms Systick.
- Hardware Timer: A function to execute the task registered by the periodic timer on 2 channels of AGT of RA MCU.
- Software I2C / SPI: The definition is the I2C / SPI function implemented by the bitbang function of the GPIO pin.Hardware I2C / SPI: I2C / SPI function implemented by the peripheral module function of the MCU
- Software I2C / SPI / Timer: Called from “machine” module
- Hardware I2C / SPI / Timer: Generally called from an MCU-specific module (eg “pyb” / “rab”)
- Only Software Timer and Software I2C can be used on RA4M1 clicker board. SPI can use software and hardware.
- Both software I2C / SPI / Timer and hardware I2C / SPI / Timer are available on the EK-RA6M2.
When using a Python module in a separate file, it is necessary to copy the Python module file to the target board in advance. In that case, use the “ampy” command or Pymakr of Visial Studio Code.
-
To install the ampy command on host PC
pip install adafruit-ampy
-
How to use the ampy command to run PC-local-file from Command Prompt of the host PC
echo print("test.py is running.") > test.py ampy -p COM6 run test.py test.py is running.
-
How to use the ampy command to download PC-local-file from Command Prompt of the host PC
ampy -p COM6 put test.py ampy -p COM6 ls /flash /flash/boot.py /flash/main.py /flash/project.pymakr /flash/test.py
-
How to use the ampy command to get file contents from the host PC
ampy -p COM6 get main.py # main.py -- put your code here!
The contents will be displayed to the standard output. If you want to save the contents to a file, you need to redirect to the file like below.
ampy -p COM6 get main.py > main.py
To use Pymakr of Visual Studio Code, some software installations and setups are needed for Nodejs, Visual Studio Code and Pymakr extension. Please refer to Program editing with Visual Studio Code + Pymakr section in "Edit and Execute program" page before try followings.
-
You have to an open folder for "Download"/"Upload" in advance. Click "EXPLORER" at left-top in Visual Studio Code. Click "Open Folder" and create a new folder, for example "C:\pymakr-sample":
-
If the following dialog appears, click "Yes" button:
-
Then PYMAKR-SAMPLE folder is opened in the EXPLORER view:
-
To download files from the target board to host PC, click "Download" in Pymakr menu. If "Do you want to download these files into your project..." is displayed, select "Yes" in the confirmation box at the top of the screen.
-
Then boot.py and main.py are downloaded into "C:\pymakr-sample" folder:
-
To run a python program, create a new python file "test.py" and click "Run" in Pymakr menu:
-
To upload files from hostPC to the target board, click "Upload" in Pymakr menu:
import os
os.listdir()
os.listdir('/flash')