2

I recently started playing with an ESP8266 and wanted to try uploading to it using WSL. I found the Arduino-CLI command and followed some tutorials but couldn't figure out how to upload to the board. The command I tried running is arduino-cli upload -p /dev/ttyS5 --fqbn esp8266:esp8266:arduino-esp8266 Testing because I know that the board is an ESP8266 and the is connected to COM5 on the Windows Arduino app. The code compiles and attempts to connect to the board, but cannot get past that part.

This is the code I was trying to upload.

void setup() {
        pinMode(0, OUTPUT);
}

void loop() {
        digitalWrite(0, HIGH);
        delay(1000);
        digitalWrite(0, LOW);
        delay(1000);
}

When I execute arduino-cli board list, it shows this.

Port Protocol Type    Board Name FQBN Core
     serial   Unknown

I'm using Windows Terminal for Ubuntu 20.04 and just installed Arduino-CLI. I also am not sure how to ask stuff cuz it's my first time using StackOverflow, so pls tell me if I'm doing something wrong :)

Edit: So it turns out that I was uploading using the wrong core. I ended up trying every single core listed by arduino-cli board listall esp8266 and it eventually worked with esp8266:esp8266:nodemcuv2 instead of esp8266:esp8266:arduino-esp8266.

Apple716_
  • 33
  • 7

2 Answers2

2

Just educated guesses here from my understanding of WSL rather than Arduino.

I'm assuming that you are using WSL2, which doesn't have access to most Windows hardware, including the serial ports.

If that's the case, two options that you might try:

  • WSL1 does have some better direct hardware access, at the expense of some kernel compatibility (since it attempts to translate syscalls rather than virtualize them). You can try converting the distribution to WSL1 via:

    wsl -l -v
    # Confirm distribution name
    wsl --set-version <distro_name> 1
    

    You might want to back it up first with wsl --export <distro_name> backup.tar.

  • As mentioned in the comments, you should be able to use the Windows toolchain. You can even run this under WSL2, since Windows commands can be executed there through interop (and would have hardware access). Remember to use the full executable, like /mnt/c/arduino-cli/arduino-cli.exe. And also you'll need to convert any Linux/WSL paths to their Windows equivalent with wslpath.

NotTheDr01ds
  • 15,620
  • 5
  • 44
  • 70
0

I found this article in Microsoft website that I hope it will be the answer to your problem.

Connect USB devices
Article03/20/2023

This guide will walk through the steps necessary to connect a USB device to a Linux distribution running on WSL 2 using the USB/IP open-source project, usbipd-win.
Setting up the USB/IP project on your Windows machine will enable common developer USB scenarios like flashing an Arduino or accessing a smartcard reader.

Prerequisites:

  • Running Windows 11 (Build 22000 or later). (Windows 10 support is possible, see note below).
  • A machine with an x64/x86 processor is required. (Arm64 is currently not supported with usbipd-win).
  • Linux distribution installed and set to WSL 2.
  • Running Linux kernel 5.10.60.1 or later.

But you will need later version of Windows 11, Windows 10 support is possible in the provided note

Note:

To check your Windows version and build number, select Windows logo key + R, type winver, select OK. You can update to the latest Windows version by selecting Start > Settings > Windows Update > Check for updates. To check your Linux kernel version, open your Linux distribution and enter the command: uname -a. To manually update to the latest kernel, open PowerShell and enter the command: 'wsl --update`.

I hope you find it useful.

yacine-app
  • 19
  • 7