|
2 | 2 |
|
3 | 3 | This is an partial port of [pyboard.py](https://docs.micropython.org/en/latest/reference/pyboard.py.html) to javascript.
|
4 | 4 |
|
| 5 | +## Basic usage |
| 6 | + |
| 7 | +``` |
| 8 | +const Board = require('micropython.js') |
| 9 | +// Instantiate board class |
| 10 | +const board = new Board() |
| 11 | +
|
| 12 | +// List available boards |
| 13 | +const ports = await board.listPorts() |
| 14 | +console.log('available boards', ports) |
| 15 | +
|
| 16 | +// Connect to a serial path |
| 17 | +await board.open('/dev/ttyUSB0') |
| 18 | +
|
| 19 | +// Enter raw repl, execute command, get output and leave raw repl |
| 20 | +await board.enter_raw_repl() |
| 21 | +const output = await board.exec_raw({ command: "print(123)" }) |
| 22 | +await board.exit_raw_repl() |
| 23 | +
|
| 24 | +// List files on the board |
| 25 | +const rootFiles = await board.fs_ils() |
| 26 | +console.log('files at /', rootFiles) |
| 27 | +
|
| 28 | +// Close serial |
| 29 | +board.close() |
| 30 | +``` |
| 31 | + |
5 | 32 | ## Examples
|
6 | 33 |
|
7 |
| -1. Install dependencies `npm install` |
8 |
| -2. Navigate to example folder `cd examples` |
9 |
| -3. Execute files with `PORT` environment variable: `PORT=/dev/tty.SLAB_USBtoUART node 05_list_files.js` |
| 34 | +1. Navigate to example folder `cd examples` |
| 35 | +2. Execute files with `PORT` environment variable: `PORT=/dev/tty.SLAB_USBtoUART node 05_list_files.js` |
10 | 36 |
|
11 | 37 | ## Command Line Interface (CLI)
|
12 | 38 |
|
13 |
| -1. Install dependencies `npm install` |
14 | 39 | 1. Run CLI `node cli.js [ARGUMENTS]...`
|
15 | 40 |
|
16 | 41 | [Read more](CLI.md)
|
17 |
| - |
|
0 commit comments