Theme: duskfox
micropython_nvim is a plugin that aims to make it easier and more enjoyable to work on micropython projects in Neovim. See the quickstart section to get started.
N.B. If you open an existing project that has an .ampy
configuration file in the root directory, the plugin will automatically configure the port and baud rate for you.
IMPORTANT This plugin assumes you are opening Neovim at the root of the project. Some commands will not behave in the expected way if you choose not to do this.
run
function-- Lua
vim.keymap.set("n", "<leader>mr", require("micropython_nvim").run)
Next steps
{
"jim-at-jibba/micropython.nvim",
dependencies = { "akinsho/toggleterm.nvim", "stevearc/dressing.nvim" },
}
use {
"jim-at-jibba/micropython.nvim",
requires = { "akinsho/toggleterm.nvim", "stevearc/dressing.nvim" },
}
:MPRun
runs current buffer on the micro-controller:MPSetPort
sets the port, in both the .ampy
configuration file and Neovim global variable:MPSetBaud
sets the baudrate in the .ampy
configuration file and Neovim global variable:MPSetStubs
sets the stubs for the board in requirments.txt
ready for installation:MPRepl
opens the REPL:MPInit
initalizes the project with basic settings and files. See project setup:MPUpload
uploads the current buffer to the micro-controller:MPEraseOne
deletes single file or folder from device.:MPUploadAll
uploads all files in the project. This command also accepts file or folder names to ignore i.e :MPUploadAll test.py unused
and auto ignores the following files. Currently, you can not ignore files that are not in the root directory. local ignore_list = {
['.git'] = true,
['requirements.txt'] = true,
['.ampy'] = true,
['.vscode'] = true,
['.gitignore'] = true,
['project.pymakr'] = true,
['env'] = true,
['venv'] = true,
['__pycache__'] = true,
['.python-version'] = true,
['.micropy/'] = true,
['micropy.json'] = true,
}
Steps to initialize a project
:MPInit
in the project directory, this will create the necessary files and directories. This includes:main.py
from machine import Pin
from time import sleep
led = Pin("LED", Pin.OUT)
while True:
led.value(not led.value())
print("LED is ON" if led.value() else "LED is OFF")
sleep(0.5)
.ampy
configuration fileAMPY_BAUD=115200
# AMPY_PORT=
# Fix for macOS users' "Could not enter raw repl"; try 2.0 and lower from there:
# AMPY_DELAY=0.5
requirments.txt
fileadafruit-ampy
rshell
micropython-rp2-stubs
ruff
pyrightconfig.json
file{
"reportMissingModuleSource": false
}
:MPSetPort
to set the port:MPSetStubs
to set the stubs for the board:MPSetBaud
to set the baudrate if not the same as the default 115200
pip install -r requirments.txt
to install the required packagesNow you be able to run the project using :MPRun
.
A statusline component can be easily added to show whether a buffer is tagged.
require("lualine").setup({
sections = {
lualine_b = {
{
require("micropython_nvim").statusline,
cond = package.loaded["micropython_nvim"] and require("micropython_nvim").exists,
},
}
}
})