Setup Arduino Rust On Wsl
08 Sep 2024
This is a guide to use rust for arduino development on wsl (Windows subsystem for linux). Everything will be setup and available in the wsl terminal. Through this guide we will install the following components:
WSL
- Install wsl ubuntu.
wsl --install
this command this will install a default ubuntu distro. If you want to install a different distro refer to this page - We also need to change the font of the terminal to be able to use neo vim properly.
- Download any nerdfont as required by neovim.
- Select all the files
- Right click and choose install.
- Setup window terminal to use this new font.
- Open a windows terminal
Ctrl+,
to open settings- Clik on open json file at the bottom left corner. (This will open the json settings file in the default text editor)
- You can create a new or update the existing ubuntu profile
"profiles": { "list": [ { "guid": "{2c4de342-38b7-51cf-b940-2309a097f518}", "hidden": false, "name": "Ubuntu", "source": "Windows.Terminal.Wsl", "colorScheme": "Ubuntu-ColorScheme", "cursorShape": "filledBox", "font": { "face": "Cousine Nerd Font", <-- specify the installed nerd font here "size": 12 } }, ] }
- restart the terminal and notice the new font.
- Install usbipd-win.
- Connect the arduino to the pc.
- list the usb device with
usbipd list
- share arduino bus with wsl
usbipd bind --busid <busid>
You only need to share it once - Open wsl and run this command to attach it
usbipd attach --wsl --busid <busid>
- you should now see the arduino if you list the usb device in wsl with
lsusb
You can also create a shortcut to be able to launch a new windows terminal directly with the Ubuntu profile. To do that simply navigate to C:\Users\{username}\AppData\Roaming\Microsoft\Windows\Start Menu\Programs
, right click, new and shortcut. Use wt.exe
as target and add -p Ubuntu
to start the ubuntu wsl profile. So the resulting shortcut target should be wt.exe -p Ubuntu
. Note that you might need to use the full path to wt.exe
. To get the full path you can simply run where wt
in a windows terminal.
Zsh
Follow this page to install zsh in wsl.
Note: You don’t need to install the font since we already installed nerdfonts in the previous step.
Neovim
Let’s get Rusty youtube channel as a nice video on how to setup linux for rust development. Follow there step in the wsl terminal.
- Install nvim
- Install nvcahd. Make sure to install nerdfonts in the windows terminal to do that see WSl setup above.
- Install rust analyzer
- Install rustaceanvim
Arduino tools
Look at this page to setup rust for arduino. This will install all the necessary dependencies and init a new project with cargo generate
.
USB
To make sure what /dev/tty**
file to use for ravendude you can follow these steps.
First, make sure that you have installed usbipd-win and that the bus is shared and visible in wsl with lsusb
. To determine what /dev/tty***
unbeffured file to use you can do
❯ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 002: ID 2341:0043 Arduino SA Uno R3 (CDC ACM) <-- arduino device. this is a acm so looking for ttyACM* file
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
If this is the only usb device shared with wsl we can suppose that the file name will be /dev/ttyACM0
. But if you want to be sure you can use this command dmesg -H > test.txt
. This will output to the test.txt
file. Open this file and search for arduino.
[ +0.000002] usb 1-1: Manufacturer: Arduino (www.arduino.cc)
[ +0.000002] usb 1-1: SerialNumber: 75130303036351106150
[ +0.024063] cdc_acm 1-1:1.0: ttyACM0: USB ACM device <-- ttyACM0
You could also use this method:
- disconnect the arduino.
- list all the tty files to a file
ls \dev\tty* > test.txt
- connect the arduino
- attach the device to wsl (see command above in the wsl section.)
- list the tty files to a new tmp file
ls \dev\tty* > test2.txt
- compare both files:
❯ comm -1 -3 test.txt test2.txt /dev/ttyACM0