This is an partial port of pyboard.py to javascript.
const Board = require('micropython.js')
// Instantiate board class
const board = new Board()
// List available boards
const ports = await board.listPorts()
console.log('available boards', ports)
// Connect to a serial path
await board.open('/dev/ttyUSB0')
// Enter raw repl, execute command, get output and leave raw repl
await board.enter_raw_repl()
const output = await board.exec_raw({ command: "print(123)" })
await board.exit_raw_repl()
// List files on the board
const rootFiles = await board.fs_ils()
console.log('files at /', rootFiles)
// Close serial
await board.close()
- Navigate to example folder
cd examples
- Execute files with
PORT
environment variable:PORT=/dev/tty.SLAB_USBtoUART node 05_list_files.js
- Run CLI
node cli.js [ARGUMENTS]...