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.
- Allows you to run and upload your python files directly to your chosen micro-controller straight from Neovim
- Allows general file management
- Allows easy management of port, baudrate, and other settings
- Allows easy set up of project environment
- Create a new project, with project specific settings
- Easy access to the REPL
- Run local python files on your micro-controller
- Upload local python files to your micro-controller
- REPL access
- File management
- Project initialisation
- Install micropython_nvim using your preferred package manager
- Add a keybind to
runfunction
-- Lua
vim.keymap.set("n", "<leader>mr", require("micropython_nvim").run)- Follow the project setup steps on automatically create the necessary files and directories for a new project.
Next steps
- Add a statusline component
lazy.nvim
{
"jim-at-jibba/micropython.nvim",
dependencies = { "akinsho/toggleterm.nvim", "stevearc/dressing.nvim" },
}packer
use {
"jim-at-jibba/micropython.nvim",
requires = { "akinsho/toggleterm.nvim", "stevearc/dressing.nvim" },
}:MPRunruns current buffer on the micro-controller:MPSetPortsets the port, in both the.ampyconfiguration file and Neovim global variable:MPSetBaudsets the baudrate in the.ampyconfiguration file and Neovim global variable:MPSetStubssets the stubs for the board inrequirments.txtready for installation:MPReplopens the REPL:MPInitinitalizes the project with basic settings and files. See project setup:MPUploaduploads the current buffer to the micro-controller:MPEraseOnedeletes single file or folder from device.:MPUploadAlluploads all files in the project. This command also accepts file or folder names to ignore i.e:MPUploadAll test.py unusedand 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
- Create a new directory for your project
- Optional but highly recommended create a virtual environment
- Run
:MPInitin 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).ampyconfiguration file
AMPY_BAUD=115200
# AMPY_PORT=
# Fix for macOS users' "Could not enter raw repl"; try 2.0 and lower from there:
# AMPY_DELAY=0.5requirments.txtfile
adafruit-ampy
rshell
micropython-rp2-stubs
ruffpyrightconfig.jsonfile
{
"reportMissingModuleSource": false
}:MPSetPortto set the port:MPSetStubsto set the stubs for the board:MPSetBaudto set the baudrate if not the same as the default115200pip install -r requirments.txtto install the required packages
Now 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,
},
}
}
})- upload all files in a directory
- delete individual files
- delete all files
- get files from the device file system



