Using udev to remove the need for sudo with the BBC Micro:bit
Last updated: Jan 24, 2023
A comment on this post hinted that there is a way to remove the need to use ‘sudo’ when interacting with the BBC Micro:bit on Linux. So I left a comment asking how to do this, which the author kindly answered:
The way to make sure there is no need for root permissions to access USB device (like a connected micro:bit) is by creating a file in the `/etc/udev/rules.d/` directory with proper config. For Microbit this could be like this:
SUBSYSTEM=="usb", ATTR{idVendor}=="0d28", ATTR{idProduct}=="0204", MODE="0666"
and then restarting udev system with:
sudo udevadm control --reload-rules
So I created the file
/etc/udev/rules.d/microbit.rules
with the above code and it works!
I fired up pyocd to enable command line programming of the BBC micro:bit without needing to use sudo. See this page for more details on programming the BBC micro:bit from the command line and using pyocd to help with this.